diff --git a/CMakeLists.txt b/CMakeLists.txt index fda244e..c603ec2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,4 +15,5 @@ endif() project(alogrithm_2024) -add_executable(P1031 ${CMAKE_CURRENT_LIST_DIR}/P1031/main.cpp) \ No newline at end of file +add_executable(P1031 ${CMAKE_CURRENT_LIST_DIR}/P1031/main.cpp) +add_executable(P1031_pro ${CMAKE_CURRENT_LIST_DIR}/P1031/pro.cpp) \ No newline at end of file diff --git a/P1031/pro.cpp b/P1031/pro.cpp new file mode 100644 index 0000000..9bff8cd --- /dev/null +++ b/P1031/pro.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +const int MAX_N = (int)1e2+5; +int n; +int a[MAX_N]; +int sum; +int avg; +int ans; +struct Gift{ + int next,num; +}; +std::vector to[MAX_N]; +int inDegree[MAX_N]; +std::queue q; + +int main(){ + std::ios::sync_with_stdio(false),std::cin.tie(nullptr),std::cout.tie(nullptr); + + std::cin>>n; + + + for(int i=1;i<=n;i++){ + std::cin>>a[i]; + sum+=a[i]; + } + + avg = sum/n; + + ans = 0; + for(int i=1;iavg){ + int num = a[i]-avg; + to[i].push_back({.next=i+1,.num=num}); + inDegree[i+1]++; + a[i+1]+=num; + }else if(a[i]