标签:inpu output 依次 string desc while else cstring pac
http://acm.hdu.edu.cn/contests/contest_showproblem.php?cid=831&pid=1003
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
求最小值最大。。明显的二分题。
合并m次,可以看成把n个数分成n-m个区间
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<queue> 5 #include<string> 6 #include<cstdio> 7 #include<cmath> 8 #include<map> 9 #define MAXN 1000005 10 #define INF 0x3f3f3f3f3f3f3f3f 11 using namespace std; 12 13 long long a[100005]; 14 long long Max; 15 int n; 16 int Check(long long s){ 17 int cnt=0; 18 long long sum=0; 19 for(int i=1;i<=n;i++){ 20 sum+=a[i]; 21 if(sum>=s){ 22 cnt++; 23 if(Max>sum) Max=sum; 24 sum=0; 25 } 26 } 27 return cnt; 28 } 29 30 int main(){ 31 std::ios::sync_with_stdio(false); 32 int T; 33 cin>>T; 34 while(T--){ 35 int m; 36 cin>>n>>m; 37 long long L=0,R=10000000005LL; 38 for(int i=1;i<=n;i++){ 39 cin>>a[i]; 40 } 41 long long mid; 42 long long ans; 43 while(L<=R){ 44 Max=INF; 45 mid=(L+R)/2; 46 if(Check(mid)<(n-m)){ 47 R=mid-1; 48 } 49 else{ 50 ans=Max; 51 L=mid+1; 52 } 53 } 54 cout<<ans<<endl; 55 } 56 57 }
标签:inpu output 依次 string desc while else cstring pac
原文地址:https://www.cnblogs.com/Fighting-sh/p/9901465.html