Strange Partition CodeForces - 1471A
生活随笔
收集整理的這篇文章主要介紹了
Strange Partition CodeForces - 1471A
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Strange Partition CodeForces - 1471A
題意:
對于數組b可以兩兩合并其中的相連元素,beauty值就是對于數組b中的b[i]除以k向上取整的和,求出beauty值的范圍。
題解:
題目給的是向上取整,也就是越合并值有可能越低,因為原本兩個數分別向上取整(相當于多加2),合成一個數后最多加1
這樣就可以知道不做操作就是取到最大值,全部合并就是取到最小值。
代碼:
#include<bits/stdc++.h> typedef long long ll; using namespace std; inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w; } const int maxn=1e5+9; int a[maxn]; int main() {int t;cin>>t;while(t--){int n,x;ll maxx=0,minn=0;ll sum=0;cin>>n>>x;for(int i=1;i<=n;i++){cin>>a[i];sum+=a[i];}double w;if(sum%x==0)minn=sum/x;else minn=sum/x+1;//minn=sum%x?sum/x+1:sum/x;for(int i=1;i<=n;i++){if(a[i]%x==0)a[i]=a[i]/x;else a[i]=a[i]/x+1;maxx+=a[i];}cout<<minn<<" "<<maxx<<endl;}return 0; }總結
以上是生活随笔為你收集整理的Strange Partition CodeForces - 1471A的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Strange Housing Code
- 下一篇: Strange List CodeFor