Codeforces Round #434 (Div. 2)【A、B、C、D】
Codeforces Round #434 (Div. 2)
codeforces 858A. k-rounding【水】
题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0。
题解:答案就是10^k和n的最小公倍数。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 using namespace std; 6 typedef long long ll; 7 ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;} 8 int main() { 9 ll n, k, s=1; 10 scanf("%lld %lld", &n, &k); 11 while(k--) s *= 10; 12 ll t = gcd(n, s); 13 printf("%lld\n", n / t * s); 14 return 0; 15 }
15ms
codeforces 858B. Which floor? 【暴力】
题意:已知每层楼的房间数量相同但不知道具体数目,从一楼往上依次给每个房间从小到大编号(从1号开始),现在给出m个房间的信息(房间号和所在楼层),求第n号房间所在楼层,若有多解则输出-1。
题解:暴力,维护每层楼的可能的最小、最大房间数。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int main() { 6 int n, m, k, f; 7 int mi=1, ma=100; 8 scanf("%d%d", &n, &m); 9 while(m--) { 10 scanf("%d%d", &k, &f); 11 if(f>1) ma = min(ma, (k-1)/(f-1)); 12 mi = max(mi, (k+f-1)/f); 13 } 14 //printf("%d %d\n", mi, ma); 15 if((f=(n+mi-1)/mi) != (n+ma-1)/ma) puts("-1"); 16 else printf("%d\n", f); 17 return 0; 18 }
15ms
codeforces 858C. Did you mean...【水】
题意:给你一个字符串,现在要你给其中加空格隔开单词,使得每个单词不能有连续三个以上不同的辅音字母,输出加的空格最少的字符串。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<map> 5 using namespace std; 6 const int N = 3001; 7 char s[N], t[N]; 8 map<char, int> mp; 9 int main() { 10 mp['a'] = mp['e'] = mp['i'] = mp['o'] = mp['u'] = 1; 11 int i, len; 12 gets(s); 13 len = strlen(s); 14 if(len < 3) {puts(s); return 0;} 15 int cnt = 0; 16 t[cnt++] = s[0]; t[cnt++] = s[1]; 17 for(i = 2; i < len; ++i) { 18 if(!mp[s[i]] && !mp[s[i-1]] && !mp[s[i-2]] && 19 (s[i]!=s[i-1] || s[i-1] != s[i-2])) { 20 t[cnt++] = ' '; t[cnt++] = s[i]; 21 s[i-1] = s[i-2] = 'a'; 22 } 23 else t[cnt++] = s[i]; 24 } 25 t[cnt++] = '\0'; 26 puts(t); 27 return 0; 28 }
31ms
待补。。
codeforces 858D. Polycarp's phone book【字典树】
题意:有n个不同的九位数的电话号码(非0开头),求每个电话号的最短的能唯一索引该号码的子串。(输入保证所有号码不同)
题解:将每个字符串的所有后缀插入字典树中,对每个号码的查询就先把其所有后缀删除,然后对其所有后缀查找其前缀出现的次数为0的最短号码即为答案。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N = 70010; 6 const int M = 10; 7 const int len = 9; 8 char a[N][M]; 9 struct Trie { 10 int next[M]; 11 int cnt; 12 void init() { 13 cnt = 0; 14 memset(next, -1, sizeof(next)); 15 } 16 }T[3150005]; 17 int le; 18 void inser(char *s) { 19 int i = 0, p = 0; 20 while(s[i]) { 21 int id = s[i] - '0'; 22 if(T[p].next[id] == -1) { 23 T[le].init(); 24 T[p].next[id] = le++; 25 } 26 p = T[p].next[id]; 27 T[p].cnt++; 28 i++; 29 } 30 } 31 void add(char *s) { 32 int i = 0, p = 0; 33 while(s[i]) { 34 int id = s[i] - '0'; 35 p = T[p].next[id]; 36 T[p].cnt++; 37 i++; 38 } 39 } 40 void del(char *s) { 41 int i = 0, p = 0; 42 while(s[i]) { 43 int id = s[i] - '0'; 44 p = T[p].next[id]; 45 T[p].cnt--; 46 i++; 47 } 48 } 49 int query(char *s) { 50 int i = 0, p = 0; 51 while(s[i]) { 52 int id = s[i] - '0'; 53 p = T[p].next[id]; 54 if(T[p].cnt == 0) return i; 55 i++; 56 } 57 return 11; 58 } 59 int main() { 60 int n, m, i, j, mi, t, l, r; 61 scanf("%d", &n); 62 le = 1; 63 T[0].init(); 64 for(i = 1; i<= n; ++i) { 65 scanf("%s", a[i]); 66 for(j = 0; j < len; ++j) inser(a[i]+j); 67 } 68 for(i = 1; i<= n; ++i) { 69 mi = 11; 70 for(j = 0; j < len; ++j) del(a[i]+j); 71 for(j = 0; j < len; ++j) { 72 t = query(a[i]+j); 73 if(t < mi) {mi = t; l = j; r = j+t;} 74 } 75 for(j = 0; j < len; ++j) add(a[i]+j); 76 for(j = l; j <= r; ++j) printf("%c", a[i][j]); 77 puts(""); 78 } 79 return 0; 80 }
186ms
转载于:https://www.cnblogs.com/GraceSkyer/p/7538541.html
Codeforces Round #434 (Div. 2)【A、B、C、D】相关推荐
- Codeforces Round #496 (Div. 3)【未完结】
2022.3.5 题目地址:https://codeforces.com/contest/1005 目录 A. Tanya and Stairways[找规律] B. Delete from the ...
- Codeforces Round #479 (Div. 3)【完结】
2022.2.28 开始复盘div3 题目链接:https://codeforces.com/contest/977 目录 A. Wrong Subtraction[签到模拟题] B. Two-gra ...
- Codeforces Round #744 (Div. 3)【A-E1】
后面的题没做,不想补了.因为最近才开始在cf上刷题,打比赛. 主要是英语太差,div3目前打算到可以很快的AC前5道,再开始攻克前6道. 以此类推,慢慢的进步吧. 目录 A. Casimir's St ...
- Codeforces Round 870 (Div. 2)【A、B、C、D】
文章目录 A. Trust Nobody(暴力) B. Lunatic Never Content(数学) C. Dreaming of Freedom(数学.暴力) D. Running Miles ...
- Codeforces Round #515 (Div. 3)【未完结】
2022.3.9 题单地址:https://codeforces.com/contest/1066 目录 A. Vova and Train[思维] B. Heaters[贪心] C. Books Q ...
- Codeforces Round #501 (Div. 3)【未完结】
2022.3.7 题单地址:https://codeforces.com/contest/1015 目录 A. Points in Segments B. Obtaining the String[模 ...
- Codeforces Round #498 (Div. 3)【完结】
2022.3.6 题单地址:https://codeforces.com/contest/1006 目录 A. Adjacent Replacements B. Polycarp's Practice ...
- Codeforces Round #494 (Div. 3)【未完结】
2022.3.4 题目地址:https://codeforces.com/contest/1003 目录 A. Polycarp's Pockets[模拟] B. Binary String Cons ...
- Codeforces Round #490 (Div. 3)【完结】
2022.3.3 题单地址:https://codeforces.com/contest/999 目录 A. Mishka and Contest[模拟] B. Reversing Encryptio ...
最新文章
- 收银机打印数据截取_智能收银机助力社区零售,挖掘消费新潜力
- 紧急!Log4j 史诗级漏洞来袭,已引起大规模入侵,速速自查!
- 数据结构之——队列与循环队列
- ValueError: Shape mismatch: The shape of labels (received (768,)) should equal the shape of logits e
- hdu 5230(整数划分,dp)
- XLSReadWriteII 4.00.62 XE2 可以使用
- 角谷定理python每次输出数_角谷定理C++递归问题,求问步数为什么总输出0?
- OpenShift 与 OpenStack:让云变得更简单
- 塞班自带浏览器下载路径问题
- [html] html如何创建图片热区(img usemap)?
- 计算机常见的多媒体端口,常用的多媒体设备接口有哪些?
- centos:清理磁盘空间
- 中小尺寸OLED面板面临价格战,中国手机可捡便宜
- Git子模块使用-管理多个git项目
- An unexpected error prevented the server from fulfilling your request. (HTTP 500)
- Go语言核心之美 3.4-Struct结构体
- vray许可服务器信息怎么看不到,VRay for sketchup的许可证问题怎么解决?
- mysql查询同名同姓重名人数,查全国同名同姓人数,姓名重名查询系统全国
- CentOS最新版本与历史版本下载
- 数字密码锁(数字逻辑大作业)
热门文章
- 操作系统进程学习(Linux 内核学习笔记)
- 震惊!垃圾分类居然能用Python搞定!
- 「洛谷2495」「BZOJ3052」「SDOI2001」消耗战【虚树+树形动态规划】
- 简单理解bash和常规操作
- Linux 编译安装BIND
- 万事开头难,用HTML写的第一个界面,收获颇多
- Python:IndentationError: unexpected indent
- Netty Associated -- ByteBuf
- Win配置Apache+mod_wsgi+django环境+域名
- [开发技巧3]不显示报表直接打印