Codeforces Round #552 (Div. 3)

骑猪看日落 2022-04-24 07:04 297阅读 0赞

C. Gourmet Cat

题目:http://codeforces.com/contest/1154/problem/C

摘除 3:2:2之后 暴力

  1. #include<iostream>
  2. #define N 100
  3. using namespace std;
  4. int a[4],d[4];
  5. int s[7]={1,1,2,3,1,3,2};
  6. int main(){
  7. cin>>a[1]>>a[2]>>a[3];
  8. int ans=0;
  9. for(int j=1;j<=7;j++){
  10. int b=min((a[1])/3,min((a[2])/2,(a[3])/2));
  11. int d[4]={0,a[1]-3*b,a[2]-2*b,a[3]-2*b};
  12. int c=b*7;
  13. for(int i=1;i<=7;i++){
  14. if(d[s[i]]) {
  15. d[s[i]]--;
  16. c++;
  17. }
  18. else break;
  19. }
  20. a[s[j]]++;
  21. ans=max(ans,c-j+1);
  22. }
  23. cout<<ans<<endl;
  24. return 0;
  25. }
  26. /*
  27. 30 20 10
  28. 输出:39
  29. */

D. Walking Robot

题目:http://codeforces.com/contest/1154/problem/D

输入是 n b a;

当无光即==0时 先使用a;

当有光即==1时 先使用b同时保证a不满;

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. int n,b,a;
  5. cin>>n>>b>>a;
  6. int aa=a;
  7. for(int i=1;i<=n;i++){
  8. int x;
  9. cin>>x;
  10. if(x==0){
  11. if(a) a--;
  12. else b--;
  13. }
  14. else{
  15. if(b&&a<aa){
  16. b--;
  17. a++;
  18. }
  19. else a--;
  20. }
  21. if(a==0&&b==0) {
  22. cout<<i<<endl;return 0;
  23. }
  24. }
  25. cout<<n<<endl;
  26. return 0;
  27. }

E. Two Teams

题目:http://codeforces.com/contest/1154/problem/E

暴力第37个点超时emmmmm

So 数组模拟链表

  1. #include<iostream>
  2. #include<queue>
  3. #define N 200010
  4. #define P pair<int,int>
  5. using namespace std;
  6. int n,K,opt,a[N],vis[N],pre[N],net[N];
  7. priority_queue<P> q,p;//大顶堆
  8. int main(){
  9. cin>>n>>K;
  10. for(int i=1;i<=n;i++){
  11. cin>>a[i];
  12. pre[i]=i-1;net[i]=i+1;
  13. q.push(P(a[i],i));
  14. }
  15. while(!q.empty()){
  16. //将已标记过的数据从原数组中删除
  17. while(p.size()&&p.top()==q.top()) p.pop(),q.pop();
  18. int i=0,j=0,k=0;
  19. if(q.empty()) break;
  20. //后继
  21. for(i=1,j=net[q.top().second];i<=K&&j;i++,j=net[j]){
  22. vis[j]=opt+1;p.push(P(a[j],j));
  23. }
  24. //前驱
  25. for(i=1,k=pre[q.top().second];i<=K&&k;i++,k=pre[k]){
  26. vis[k]=opt+1;p.push(P(a[k],k));
  27. }
  28. vis[q.top().second]=opt+1;q.pop();
  29. //更改对应的前驱与后继
  30. pre[j]=k;net[k]=j;opt^=1;
  31. }
  32. for(int i=1;i<=n;i++) cout<<vis[i];
  33. return 0;
  34. }
  35. /*
  36. 5 1
  37. 2 4 5 3 1
  38. 输出:
  39. 21112
  40. */

F. Shovels Shop

题目:http://codeforces.com/contest/1154/problem/F

前缀和 大神就是大神 膜拜ing

为什么我没有想到?菜是原罪!!!

  1. #include<iostream>
  2. #include<algorithm>
  3. #define N 100010
  4. using namespace std;
  5. int n,m,k;
  6. int a[N],g[N],f[N];
  7. int main(){
  8. cin>>n>>m>>k;
  9. for(int i=1;i<=n;i++) cin>>a[i];
  10. sort(a+1,a+n+1);
  11. for(int i=1;i<=n;i++) a[i]+=a[i-1]; //前缀和
  12. for(int i=1;i<=m;i++){
  13. int x,y;
  14. cin>>x>>y;
  15. g[x]=max(g[x],y);//买x个最多免费g[x]个
  16. }
  17. for(int i=1;i<=k;i++){//dp;
  18. f[i]=0x3f3f3f3f;
  19. for(int j=0;j<i;j++){
  20. f[i]=min(f[i],f[j]+a[i]-a[j+g[i-j]]);
  21. }
  22. }
  23. cout<<f[k]<<endl;
  24. return 0;
  25. }

G. Minimum Possible LCM

题目:http://codeforces.com/contest/1154/problem/G

倍增找最小的lcm

  1. #include<iostream>
  2. #define ll long long
  3. using namespace std;
  4. const int N=1e7+50;
  5. int n,x,vis[N],t1,t2,s1,s2;
  6. ll ans=1e14;
  7. int main(){
  8. cin>>n;
  9. //如果存在两个数相同 ans记录最小的那个
  10. //t1记录ans在数组中的第一个位置,t2记录ans在数组中的第二个位置
  11. //如果不存在t1=t2=0;
  12. for(int i=1;i<=n;i++){
  13. cin>>x;
  14. if(vis[x]){
  15. if(ans>x) {
  16. ans=x;
  17. t1=vis[x];
  18. t2=i;
  19. }
  20. }
  21. if(!vis[x]) vis[x]=i;
  22. }
  23. //从最小数开始倍增 同时判断该数组中有没有这个数
  24. for(int i=1;i<N;i++){
  25. if(i>=ans) break;
  26. s1=s2=0;
  27. for(int j=i;j<N;j+=i){//倍增
  28. if(!vis[j]) continue;
  29. if(!s1) {
  30. s1=j;s2=vis[j];
  31. }
  32. else{
  33. if(ans>1ll*s1*j/i){
  34. ans=1ll*s1*j/i;
  35. t1=s2;t2=vis[j];
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. if(t1>t2) t1^=t2^=t1^=t2; //异或交换t1,t2的值
  42. cout<<t1<<" "<<t2<<endl;
  43. return 0;
  44. }

发表评论

表情:
评论列表 (有 0 条评论,297人围观)

还没有评论,来说两句吧...

相关阅读