Educational Codeforces Round 58 (Rated for Div. 2) A,B,C,E
2019-01-12 00:55
239 查看
Educational Codeforces Round 58 (Rated for Div. 2) A,B,C,E
前言
我会说现在比赛还没有结束吗,当然不会(别打我,就皮这一下)。
咳咳,总的来说这场EDU还是有点难受的,看目前的榜应该会把我卡在蓝色的大门之外(不FST的话)。
出题节奏的把握可以说是很差了,几次错过能出的题去看别的题。
开场
2min出的A,还行,应该还能更快一点,打了一天王者抄了一天马克思手有一点点不太灵活。后来开B,看了一会儿没看懂(雾),立马去写C,失误WA了一发,想了半天觉得没有问题,以为自己题目理解错了,看榜觉得B也不是很难的样子,回头莽了一发,
30min过了B,然后又去开C,又交了一发还是WA,这个时候就很难受了,D看了一下,感觉不是我的能力范围,看了一眼Dashboard,感觉E还有点搞头,调bug浪费了一点时间,
49min过了E,后来就佛了,坐着乱想,还真把C的反例想出来了,原来是边界判断没有取max,也是醉了orz。时间是
69min。
应该不会蓝名了吧,有点遗憾,但是下次我会加油的。
A. Minimum Integer
题意
给定一段区间和一个数,求这个区间之外的最小的给定数的倍数。
做法
如果左端比给定数大,输出给定数,反之输出比右端大的给定数的倍数。
代码
#include <cstdio> using namespace std; int main() { int n; scanf("%d",&n); while(n--) { int l,r,d; scanf("%d%d%d",&l,&r,&d); if(l>d) printf("%d\n",d); else { printf("%d\n",(r+d)/d*d); } } }
B. Accordion
题意
给定一串字符串,找到满足[:(|…|):]的子串的最大长度,‘|’的数量没有要求
做法
从两端分别遍历即可。
代码
#include <cstdio> #include <cstring> using namespace std; char s[500005]; int main() { scanf("%s",s); int l=0; int r=strlen(s)-1; int len = r; int lm=-1,rm=-1,cnt=4; for(;l<len;l++) { if(s[l]=='[') { break; } } for(;l<len;l++) { if(s[l]==':') { lm = l; break; } } for(;r>=0;r--) { if(s[r]==']') { break; } } for(;r>=0;r--) { if(s[r]==':') { rm = r; break; } } if(rm==lm||rm==-1||lm==-1) { printf("-1\n"); } else { cnt=4; for(int i=lm;i<=rm;i++) { if(s[i]=='|') cnt++; } printf("%d\n",cnt); } }
C. Division and Union
题意
给定一堆数据区间,问,是否能将它分为两组,要求拥有相同元素的区间必须放在一组。
做法
以左边界为第一优先,右边界为第二优先,现将第一个区间放为第一组,最大值维护右端点,如果接下来的区间左端小于当前有端,加入第一组,反之加入第二组。
代码
#include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <iostream> using namespace std; struct seg { int l,r,num,ans; }s[300000]; bool cmp1(seg a,seg b) { if(a.l==b.l) return a.r<b.r; else return a.l<b.l; } bool cmp2(seg a,seg b) { return a.num<b.num; } int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&s[i].l,&s[i].r); s[i].num = i; } sort(s,s+n,cmp1); int rr=0,rrr=0; bool judge = false; rr = s[0].r; s[0].ans = 1; for(int i=1;i<n;i++) { if(s[i].l<=rr) { s[i].ans = 1; rr = max(s[i].r,rr); } else { s[i].ans = 2; rrr = max(s[i].r,rrr); } } if(rrr==0) { printf("-1\n"); } else { sort(s,s+n,cmp2); for(int i=0;i<n;i++) { printf("%d ",s[i].ans); } printf("\n"); } } }
E. Polycarp’s New Job
题意
判断钱包的大小能否放下当前已有的钞票。
做法
维护小边的最大值和大边的最大值。
代码
#include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <iostream> using namespace std; int main() { int n; scanf("%d",&n); int minn = 0; int maxn = 0; for(int i=0;i<n;i++) { getchar(); char a; scanf("%c",&a); if(a=='+') { int x,y; scanf("%d%d",&x,&y); if(x>y) swap(x,y); minn = max(minn,x); maxn = max(maxn,y); } else { int h,w; scanf("%d%d",&h,&w); if(h>w) swap(h,w); if(h>=minn&&w>=maxn) { printf("YES\n"); } else { printf("NO\n"); } } } }
相关文章推荐
- Educational Codeforces Round 41 (Rated for Div. 2)
- Educational Codeforces Round 34 (Rated for Div. 2)
- Educational Codeforces Round 33 (Rated for Div. 2)【C】【并查集】
- Educational Codeforces Round 37 (Rated for Div. 2)
- Educational Codeforces Round 62 (Rated for Div. 2)C. Playlist(优先队列)
- Educational Codeforces Round 64 (Rated for Div. 2) A Inscribed Figures
- Educational Codeforces Round 39 (Rated for Div. 2) codeforces946 D. Timetable-数据处理+分组背包(处理炸裂)
- Educational Codeforces Round 36 (Rated for Div. 2) A-C
- Educational Codeforces Round 33 (Rated for Div. 2) B题. Beautiful Divisors
- Educational Codeforces Round 33 (Rated for Div. 2) C - Rumor
- Educational Codeforces Round 33 (Rated for Div. 2) F - Subtree Minimum Query
- Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree(并查集)
- Educational Codeforces Round 53 (Rated for Div. 2)
- Wannafly挑战赛9+Educational Codeforces Round 37 (Rated for Div. 2)
- Educational Codeforces Round 35 (Rated for Div. 2) D. Inversion Counting
- Educational Codeforces Round 37 (Rated for Div. 2)-F-SUM and REPLACE(线段树)
- Educational Codeforces Round 40 (Rated for Div. 2) E. Water Taps
- Educational Codeforces Round 34 (Rated for Div. 2) D - Almost Difference
- Educational Codeforces Round 37 (Rated for Div. 2) F. SUM and REPLACE(线段树,区间更新)
- Educational Codeforces Round 48 (Rated for Div. 2)——A. Death Note ##