Meaning of the questions: There are n cup of coffee, you need to write m-page job; he can drink Any cup of coffee a day (1 or multi-cup); each cup of coffee you can let him write ai-page job; in the same day, he drank coffee can let him write w pages;
w = (first + second cup cup -1 + -2 third cup ......); seeking to drink at least a few days to finish the job (which seems to describe the meaning of the questions are not many, improvise ~ bad language)
Solution: Sorting + binary answer, the lower limit of one day, the upper limit of n days, then directly see Check code;
O (nlogn)
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e5+10; int a[MAXN]; int n,m; bool check(int mid){ int ans=0; int i=1; int cnt=0; int k=mid; while(i<=n){ for(;i<=min(k,n);i++){ ans+=max(a[i]-cnt,0); } if(ans>=m)return true; k=k+=mid; cnt++; } return false; } bool cmp(int x,int y){ return x>y; } int main(){ ios::sync_with_stdio(false); cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+1+n,cmp); int ans=-1; int l=1,r=n,mid; while(l<=r){ mid=(l+r)>>1; if(check(mid)){ r=mid-1; ans=mid; } else l=mid+1; } cout<<ans<<endl; return 0; }
Meaning of the questions: acm team, there is a code hands, b the number on the king, c idler;
Seeking up to set the number of teams, each team must have at least one hand and the code number theory a king;
Solution: Analog? ; Easy
#include <bits/stdc++.h> using namespace std; const int MAXN=1e5+10; typedef long long ll; int main(){ ios::sync_with_stdio(false); int T; cin>>T; while(T--){ ll a,b,c,minn; cin>>a>>b>>c; minn=min(a,min(b,c)); if(minn!=c){ cout<<minn<<endl; } else{ a-=c;b-=c; cout<<minn+min(a,min(b,(a+b)/3))<<endl; } } return 0; }
Question is intended: to a n, the output of a graph (containing only W, B), such that each W or B or B to attack the maximum number of W;
Each character can only attack on the daily diagonal; W attack B, B to attack W;
Solution: BW CROSS output on the line;
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=2e5+10; int main(){ ios::sync_with_stdio(false); int n; cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i%2==j%2)cout<<'B'; else cout<<'W'; } cout<<endl; } return 0; }
The meaning of problems: the number n, seeking to remove a number, such that the remaining entries in the array equal to the odd number and even-numbered;
Solution: obtaining first and odd-numbered and even-numbered and not removed;
Then through the array; i representative of the i-th then removed
Odd-numbered (even-numbered after and before i + i and odd-numbered) and =
Even term (before and after the odd-numbered even-numbered and i + i and) and =
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=2e5+10; int a[MAXN]; int main(){ ios::sync_with_stdio(false); int n; cin>>n; int sum1=0; int sum2=0; for(int i=1;i<=n;i++){ cin>>a[i]; if(i%2)sum1+=a[i]; else sum2+=a[i]; } //cout<<"sum1="<<sum1<<' '<<"sum2="<<sum2<<endl; int ans=0; int newsum1=0; int newsum2=0; for(int i=1;i<=n;i++){ if(i%2){ sum1-=a[i]; if(sum1+newsum2==sum2+newsum1)ans++; newsum1+=a[i]; } else { sum2-=a[i]; if(sum1+newsum2==sum2+newsum1)ans++; newsum2+=a[i]; } } cout<<ans<<endl; return 0; }
Meaning of the questions: n give you the number, the same number of each of the two can be combined to double this number, asked whether the synthesis of 2048;
2048 Games ~;
Solution: bucket sort; less than or equal to the number of sort barrel 2048 is, greater than 2048 can not synthesized;
Then traversing from 1 to 2048 (1024 to), [i] num> = 2 num [i * 2] + = num [i] / 2: continue;?
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=1e3+10; int a[MAXN]; int num[3000]; int main(){ ios::sync_with_stdio(false); int T,n; cin>>T; while(T--){ cin>>n; memset(num,0,sizeof(num)); for(int i=1;i<=n;i++){ cin>>a[i]; if(a[i]<=2048){ num[a[i]]++; } } for(int i=1;i<=2048;i++){ if(num[i]>=2){ num[i*2]+=num[i]/2; } } if(num[2048])cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
Meaning of the questions: two kinds of water bottles, 1L a dollar, 2L b yuan, need to ask a minimum of n L of water, how much;
Solution: 1L and 2L direct comparison price, buy then follow;
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,a,b; int main(){ ios::sync_with_stdio(false); int T; cin>>T; while(T--){ cin>>n>>a>>b; if(a*2<=b){ cout<<n*a<<endl; } else{ ll ans=0; ans+=n/2*b; if(n%2){ ans+=a; } cout<<ans<<endl; } } return 0; }