POJ3273
按每个月的权值进行分段
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include<set> 8 #include 9 #define pii pair 10 #define fi first 11 #define se second 12 #define mp make_pair 13 #define pb push_back 14 #define rep(i, a, b) for(int i=(a); i<(b); i++) 15 #define sz(a) (int)a.size() 16 #define de(a) cout << #a << " = " << a << endl 17 #define dd(a) cout << #a << " = " << a << " " 18 #define all(a) a.begin(), a.end() 19 #define endl "\n" 20 #define INF 0x3f3f3f3f 21 #include 22 using namespace std; 23 #define M 200000+ 24 const int maxn=1e5+7; 25 #define eps 1e-5 26 typedef long long ll; 27 ll n,m,sum; 28 double a[maxn]; 29 bool check(ll mid) 30 { 31 int ret=0,cnt=1; 32 rep(i,0,n){ 33 ret+=a[i]; 34 if(ret>mid){ 35 cnt++; 36 ret=a[i]; 37 } 38 } 39 return cnt<=m; 40 } 41 int main() 42 { 43 cin>>n>>m; 44 ll max=0; 45 rep(i,0,n){ 46 cin>>a[i],sum+=a[i];if(a[i]>max)max=a[i]; 47 } 48 ll l=max,r=sum,ans=0,mid; 49 while(r>=l) 50 { 51 mid=(r+l)/2; 52 if(check(mid))r=mid-1; 53 else l=mid+1; 54 } 55 cout< endl; 56 return 0; 57 }
最长递增子段
1 #include2 #include 3 #include 4 #include 5 #include 6 #include