Codeforces Round #552 (Div. 3)

休闲VP发现打的真的太休闲了,完全没有比赛的氛围

A,B

不管

C

暴力跑第一轮和最后一轮

中间的轮数直接做除法

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
inline int read(){int v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
LL aaa,bbb,ccc;
LL ans;
int aa[5],bb[5],cc[5];
inline LL work(LL x,LL a,LL b,LL c){for(int j = x;j <= 7;++j){if(j == 1 || j == 4 || j == 7) a--;if(j == 2 || j == 6) b--;if(j == 3 || j == 5) c--;if(a < 0 || b < 0 || c < 0) return j - x;   }LL week,day;LL resta = a / 3;LL restb = b / 2;LL restc = c / 2;week = min(resta,min(restb,restc));LL ans = week * 7 + 7 - x + 1;a = a - week * 3,b -= week * 2,c -= week * 2;for(int j = 1;j <= 7;++j){if(j == 1 || j == 4 || j == 7) a--;if(j == 2 || j == 6) b--;if(j == 3 || j == 5) c--;ans++;if(a < 0 || b < 0 || c < 0) return ans - 1;}for(int j = 1;j <= 7;++j){if(j == 1 || j == 4 || j == 7) a--;if(j == 2 || j == 6) b--;if(j == 3 || j == 5) c--;ans++;if(a < 0 || b < 0 || c < 0) return ans - 1;}
}
int main(){cin >> aaa >> bbb >> ccc;aa[1] = 4,aa[2] = 7,aa[3] = 8; bb[1] = 6,bb[2] = 9;cc[1] = 5,cc[2] = 10;for(int i = 1;i <= 7;++i){ans = max(ans,work(i,aaa,bbb,ccc));//  printf("%d %d\n",i,ans);}cout << ans;return 0;
}

D

之前贪心发现贪错了

发现操作分位3种

\(x-1\),\(y - 1\),\(x-1,y+1\)

可以证明当\(s[i] = 1\)时,使用\(x - 1,y+1\)一定不会更劣

所以就尽可能的在\(s[i] = 1\)时使用\(x\)就好了

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
int s[N];
int n,a,b,num;//b:太阳能
inline int read(){int v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
int main(){n = read(),a = read(),b = read(),num = 0;int rest = b;for(int i = 1;i <= n;++i) s[i] = read();for(int i = 1;i <= n;++i){if(a == 0 && rest == 0) {printf("%d\n",i - 1);return 0;}if(s[i] == 0 && rest != 0) rest--;else if(s[i] == 0 && rest == 0) a--;else if(s[i] == 1 && rest != b){if(a == 0) rest--;else {a--;if(rest != 0) num++;rest++; }   }else if(s[i] == 1 && rest == b){rest--;}
//      printf("%d %d\n",a,rest);}printf("%d\n",n);return 0;
}
/*
19 7 4
0 0 1 1 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1
*/

E

直接用双向链表模拟就好了

时间复杂度可以证明

暴力删除

懒得写链表,就用set维护

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<set>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
int a[N];
int L[N];
int R[N];
bool book[N];
int n,k;
int ans[N];
set<pii> s;
set<int> ss;
int sta[N];
int tot;
set<pii>::iterator it;
set<int>::iterator iit;
inline int read(){int v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
int main(){int now = 1;n = read(),k = read();for(int i = 1;i <= n;++i) a[i] = read(),s.insert(mk(a[i],i)),ss.insert(i);while(!s.empty()){it = s.end();it--;pii x = *it;tot = 0;iit = ss.lower_bound(x.se);for(int num = 0;num <= k;--iit,++num){//  printf("%d ",*iit);ans[*iit] = now;s.erase(mk(a[*iit],*iit));sta[++tot] = *iit;if(iit == ss.begin()) break;}iit = ss.lower_bound(x.se);for(int num = 0;num <= k && iit != ss.end();++iit,++num){//  printf("%d ",*iit);ans[*iit] = now;s.erase(mk(a[*iit],*iit));sta[++tot] = *iit;  }//  puts("");for(int i = 1;i <= tot;++i) ss.erase(sta[i]);if(now == 1) now = 2;else now = 1;}for(int i = 1;i <= n;++i) printf("%d",ans[i]);return 0;
}

F

发现\(k\)这么小,肯定有东西

发现购买的物品一定是前\(k\)

前\(k\)小一定是从大往小买

直接排序

所以我们设\(f_i\)表示前\(i\)个物品的最小花费

每次枚举用了哪一个优惠

或者不用优惠就好了

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
inline int read(){int v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
int n,k,m;
int bar[N];
int f[N];
int a[N];
int sum[N];
int main(){n = read(),m = read(),k = read();for(int i = 1;i <= n;++i) a[i] = read();for(int i = 1;i <= m;++i){int x = read(),y = read();bar[x] = max(bar[x],y); }sort(a + 1,a + n + 1);reverse(a + 1,a + k + 1);for(int i = 1;i <= k;++i) sum[i] = sum[i - 1] + a[i];memset(f,0x3f,sizeof(f));f[0] = 0;
//  for(int i = 1;i <= k;++i) printf("%d\n",a[i]);for(int i = 1;i <= k;++i){for(int j = 1;j <= i;++j)f[i] = min(f[i],f[i - j] + sum[i] - sum[i - j] - (sum[i] - sum[i - bar[j]]));       f[i] = min(f[i],f[i - 1] + a[i]);}cout << f[k] << endl;return 0;
}

G

\[ lcm(i,j) = \frac{i\times j}{gcd(i,j)} \]

我们就枚举\(gcd(i,j)\)

显然\(i,j\)都要是他的倍数

在枚举的时候顺带更新答案就好了

CF上开\(4\)s,\(10^7\)一个\(log\)还是可以过得

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 1e7 + 3;
const int M = 1e7;
int n;
int a[N];
LL ans = 9999999999999999;
pii id;
int vis[N];
inline int read(){int v = 0,c = 1;char ch = getchar();while(!isdigit(ch)){if(ch == '-') c = -1;ch = getchar();}while(isdigit(ch)){v = v * 10 + ch - 48;ch = getchar();}return v * c;
}
int main(){n = read();for(int i = 1;i <= n;++i){a[i] = read();if(vis[a[i]]){if(a[i] < ans) ans = a[i],id = mk(vis[a[i]],i); }vis[a[i]] = i;}for(int d = 1;d <= M;++d){int maxx1 = 0,maxx2 = 0;for(int x = d;x <= M;x += d){if(vis[x]){if(!maxx1) maxx1 = vis[x];else if(!maxx2) maxx2 = vis[x];else maxx2 = maxx1,maxx1 = vis[x];if(maxx1 != 0 && maxx2 != 0)if(1ll * a[maxx1] * a[maxx2] / d < ans) ans = 1ll * a[maxx1] * a[maxx2] / d,id = mk(maxx1,maxx2);//  printf("%d %d %d %lld\n",d,maxx1,maxx2,ans);}}}if(id.fi > id.se) swap(id.fi,id.se);printf("%d %d\n",id.fi,id.se);return 0;
}

转载于:https://www.cnblogs.com/wyxdrqc/p/11412991.html

Codeforces Round #552 (Div. 3)相关推荐

  1. Codeforces Round #552 (Div. 3) Editorial 1154C - Gourmet Cat

    链接:https://codeforces.com/contest/1154/problem/C 题意:一只旅行的小猫在特定的星期里吃特定的食物,一四七a,二六b,三五c,现在给三种食物的数量,问小猫 ...

  2. Codeforces Round #552 (Div. 3) E stl模拟 F dp G gcd

    contest链接 https://codeforces.com/contest/1154 E 题解思路 直接哈希模拟删除T了,可以用setsetset和lowerlowerlower_boundbo ...

  3. Codeforces Round #552 (Div. 3) A B C D E F G (暴力,dp,模拟)

    题目链接:https://codeforces.com/contest/1154 A:Restoring Three Numbers B:Make Them Equal C:Gourmet Cat D ...

  4. Codeforces Round #552 (Div. 3) C题

    题目链接 http://codeforces.com/contest/1154/problem/C 题目 C. Gourmet Cat time limit per test 1 second mem ...

  5. Codeforces Round #552 (Div. 3)D、E题解

    D. Walking Robot 题意 机器人在一维坐标轴上从0走到x,中途可以在有光的地方可以选择给太阳能电池充电,每次移动都要消耗一单位电,蓄电池容量为a,太阳能电池容量为b,一开始都是满电,问机 ...

  6. Codeforces Round #552 (Div. 3) —— B. Make Them Equal

    B. Make Them Equal time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...

  7. Codeforces Round #552 (Div. 3) —— A. Restoring Three Numbers

    A. Restoring Three Numbers A.恢复三个数字 time limit per test1 second 每次测试的时间限制1秒 memory limit per test256 ...

  8. Codeforces Round #552 Div. 3

    题目链接:戳我 前两题是littlesun_wl小可爱写的qwqwq A #include<iostream> #include<cstdio> #include<cst ...

  9. Codeforces Round #552 (Div. 3) E. Two Teams 暴力+双向链表

    传送 题意:将n个人分成2个队,每次选取队伍中未被选取的最大值,然后顺便选取左边相邻的k个数(有多少拿多少) 问你最后队伍的分配情况. #include<bits/stdc++.h>usi ...

  10. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

最新文章

  1. wince 6中硬键盘 输入法解决
  2. 怎么定义html的整体的宽度,html怎么设置最大宽度
  3. 怎样将employee 加到Territory里
  4. Linux-Android启动之Init进程前传
  5. exchange2003 SMTP连接器的应用案例
  6. 微波网络归一化转移矩阵[a]导出散射矩阵[S]
  7. 在ORACLE中找出并批量编译失效的对象
  8. java8—Stream
  9. 初中英语多词性单词怎么办_初中英语单词按词性分类表.pdf
  10. VSCode中使用CodeRunner运行Python乱码
  11. (转载)各类指数基金标的指数比较
  12. Wordpress中wp-admim管理后台(404)无法进入,无限循环跳出解决方法
  13. webdriver中的等待——主要讲解WebDriverWait()
  14. 《微信公众平台开发:从零基础到ThinkPHP5高性能框架实践》——1.2 微信公众账号注册...
  15. 照片秒变艺术肖像画,Github标星5.2K!
  16. 跨平台第三方平台登录和单点登录
  17. IAR+openSDA+s32k144 环境搭建
  18. Ubuntu 16.04安装Zimbra邮件服务器
  19. 使用throttlestop超频,解除锁频和温控
  20. 想要学习编程,有什么推荐的书籍?

热门文章

  1. No package ‘gtksourceview-4‘ found
  2. WORD中如何转换符号的全角半角
  3. SVN回滚代码时,提示冲突怎么办
  4. 终于把Android Studio用起来了,及体验
  5. 软件基本功:没有人比我更重视测试
  6. 安卓GLSurfaceView使用简单范例
  7. 挑选32 2K显示器
  8. 最土家乡话,莫过于栖霞
  9. 路面压电发电,应该有前途
  10. 什么样的文档能够帮助理解代码