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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/428735.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Codeforces Round #735 (Div. 2)(A-D)没有B

Codeforces Round #735 (Div. 2) A 一道小思维题 #include <bits/stdc.h> using namespace std; #define int long long const int N 1000100; int a[N]; signed main() {int t;cin>>t;while(t--){int n;cin>>n;int cou 0;for (int i1;i<n;i){cin>&…

Educational Codeforces Round 112 (Rated for Div. 2)(A-D)

Educational Codeforces Round 112 (Rated for Div. 2) A 我写的挺烦的&#xff0c;其实判断一下奇偶数和有没有a>0就行 #include <bits/stdc.h>using namespace std;#define int long longsigned main(){int t;cin>>t;while (t--){int n;cin>>n;int a n…

PLC与触摸屏练习

电机正反转 触摸屏 要用触摸屏进行仿真是不要忘了先启动梯形图测试 效果 1-2例 行程开关控制的自动循环 梯形图 触摸屏 下面只是用了四个开关&#xff0c;可以根据自己想要实现的按照梯形图添加 题目 梯形图 电动机星三角减压启动控制 题目及要求 触摸屏截图 运算 把显示的数值…

Django里面是文件静态化的方法

看Django官网的时候&#xff0c;由于自己的英语基础较差&#xff0c;而实现的谷歌翻译比较烂&#xff0c;只能看懂个大概。在文件静态化的时候&#xff0c;讲的比较繁琐一点&#xff0c;没怎么看懂&#xff0c;遂询问了一下其他人&#xff0c;明白了许多&#xff0c;但是细节需…

Codeforces Round #736 (Div. 2)(B-C)

Codeforces Round #736 (Div. 2) 花了十分钟帮朋友写了B&#xff0c;C就睡觉了&#xff0c;自己没打 B 先看上&#xff0c;再看左后看右 #include <iostream> #include <cstring> #include <algorithm> using namespace std; #define int long long signed…

RabbitMQ 声明Queue时的参数们的Power

RabbitMQ 声明Queue时的参数们的Power 参数们的Power 在声明队列的时候会有很多的参数 public static QueueDeclareOk QueueDeclare(this IModel model, string queue "", bool durable false, bool exclusive true, bool autoDelete true, IDictionary<strin…

解决Firefox已阻止运行早期版本Adobe Flash

解决Firefox已阻止运行早期版本Adobe Flash 类别 [随笔分类]web 解决Firefox已阻止运行早期版本Adobe Flash 最近火狐浏览器不知抽什么风&#xff0c;每次打开总提示"Firefox已阻止(null)运行早期版本的Adobe Flash"。要命的是它提示的解决办法根本不管用&#xf…

误删path怎么办(已重启)

我是在设置环境变量的时候不懂&#xff0c;新建了一个path&#xff0c;导致我原来的path没了。 但是居然jdk能用。。。。。不太懂。 不要慌&#xff0c;大不了重装系统。其实只要再重新新建就行了。 C:\Program Files\Common Files\Siemens\Automation\Simatic OAM\bin;%Syste…

一个容易被忽视的css选择器

之前学的的迷糊了&#xff0c;也不知道什么会什么不会了&#xff0c;跑去面试了。别人列出一堆css选择器&#xff0c;本以为选择器没啥的&#xff0c;结果到那个多类选择器翻车了&#xff0c;.a.b选择同时含a,b类名的&#xff0c;很尴尬所以回来仔细整理了一下。目前根据W3C手册…

Codeforces Round #756 (Div. 3)

Codeforces Round #756 (Div. 3) A. Make Even 思路&#xff1a;如果末尾是偶数&#xff0c;不需要操作&#xff1b;如果开头是偶数&#xff0c;一次操作&#xff0c;即全翻转&#xff1b;如果开头和末尾都是 奇数&#xff0c;判断里面是否有偶数&#xff0c;如果没有&#xff…

使用MyBatista----上传图像

使用MyBatis上传图像&#xff0c;使用的是Oracle的数据库表&#xff0c;有一个TEACHER表&#xff0c;有7列&#xff0c;有1列是存储图片的&#xff0c;类型用BLOB&#xff0c;最大容量是4G&#xff0c;以二进制的形式写入数据库表。 建立这个表的对应实体类Teacher&#xff0c;…

189A. Cut Ribbon

A. Cut Ribbon:题目地址 题意&#xff1a;一条长为n的彩带切割&#xff0c;切割后每段长度是a或者是b或者是c#include <bits/stdc.h> using namespace std; typedef long long ll; vector<int> a((int)4e5); vector<int> b((int)4e5); int main() {int n,a,…

作业1.3

public class Work{   public static void main(String[] args)   {     System.out.println(" J A V V A");     System.out.println(" J A A V V A A"); //直接输出就好了     System.out.println("J J …

476B. Dreamoon and WiFi

B. Dreamoon and WiFi:题目链接 题意&#xff1a;给你一个正常的走向&#xff0c;在给你一个虚假和不确定的走向&#xff0c;问到达的可能性#include <bits/stdc.h> using namespace std; string str1, str2; double C(double A, double B) {double res 1.0;for (int i…

简易观察者模式

var Event {   on(event,callback){     if(!this.handles){       this.handles {};     }     if(!this.handles[event]){       this.handles[event] [];     }     this.handles[event].push(callback);   },   emit(event){   …

1360E. Polygon

E. Polygon&#xff1a;题目 题意&#xff1a;在一个n*n的方块空间内&#xff0c;上下都有大炮&#xff0c;发射数量和先后由你决定。问能否得到他给的地图。 思路&#xff1a;如果他不是靠下边或者右边&#xff0c;右或者下必有一个炮弹阻挡。所以直接遍历判断就行#include &…

1470A. Strange Birthday Party

A. Strange Birthday Party&#xff1a;题目 题意&#xff1a;有n个朋友&#xff0c;要么给他钱&#xff0c;要么给他买礼物&#xff0c;礼物每样只能买一个 思路&#xff1a;sort&#xff0c;给钱不如给礼物的给礼物&#xff0c;礼物给完了&#xff0c;或者礼物本身太贵不如给…

_INTSIZEOF

在_INTSIZEOF中该有的都有了 1.这其中最小非负剩余和最大正余数例子如下: 设n为4&#xff0c;当r为1时&#xff0c;最小非负剩余就是1&#xff0c;最大非正剩余就是1 - 4 -3&#xff0c;最大正余数为4 - 1 3 2.x nq r推导出qn ((x n - 1) / n) * n的过程如下 1)当x % n等…

Windows下struct和union字节对齐设置以及大小的确定(一 简介和结构体大小的确定)...

在windows下设置字节对齐大小的方式&#xff0c;目前我了解有三种&#xff1a; 1. 在编译程序时候的编译选项 /Zp[n]&#xff0c;如 cl /Zp4 表示对齐大小是4字节&#xff1b; 2. 预处理命令 #pragma pack( [ show ] | [ push | pop ] [, identifier ] , n )&#xff1b; 3…

1285B. Just Eat It

B. Just Eat It!&#xff1a;题目 题意&#xff1a;全部吃是否绝对比吃一部分好 思路&#xff0c;如果一部分总和是0或者负的&#xff0c;就可以通过吃另一部分大于等于全吃。#include <bits/stdc.h> using namespace std; typedef long long ll; vector<int> a((…