Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)

来源:互联网 发布:诺查丹玛斯 知乎 编辑:程序博客网 时间:2024/05/22 17:39

A

题意:给出一个n,一个k,问你n * m 后 末尾最少有k个0,求最小的n * m

#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <utility>#include <bitset>using namespace std;#define LL long long#define pb push_back#define mk make_pair#define pill pair<int, int>#define mst(a, b)memset(a, b, sizeof a)#define REP(i, x, n)for(int i = x; i <= n; ++i)const int MOD = 1e9 + 7;const int qq = 2e5 + 10;const int INF = 1e9 + 10;LL n, k;int main(){scanf("%lld%lld", &n, &k);if(k == 0) {printf("%lld\n", n);return 0;}int a = 0, b = 0;LL t = n;while(t % 2 == 0) {a++;t /= 2;}t = n;while(t % 5 == 0) {b++;t /= 5;}int c = min(a, b);if(k <= c) {printf("%lld\n", n);return 0;}int w1, w2;w1 = w2 = 0;while(true) {c = min(a, b);if(c == k)break;if(a == b) {a++, b++;w1++, w2++;} else if(a > b) {b++, w2++;} else if(a < b) {a++, w1++;}}while(w1 > 0) {n *= 2LL;w1--;}while(w2 > 0) {n *= 5LL;w2--;}printf("%lld\n", n);return 0;}


B

题意:有无限层楼房,每层楼房可以放一定数量的flat,并且每层楼房可以放的flat数量相同,flat的顺序是连续的,现在给出一些flat被放的楼层,问第n个flat的答案是不是唯一的

思路:这题真的被坑了、我是枚举的每层楼房放的个数,如果只存在一种情况可以满足即答案存在,其实并不是,当每个楼层所发个数不一样的时候第n个flat所在楼层是可以相同的,注意这点基本就没问题了

#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <utility>#include <bitset>using namespace std;#define LL long long#define pb push_back#define mk make_pair#define pill pair<int, int>#define mst(a, b)memset(a, b, sizeof a)#define REP(i, x, n)for(int i = x; i <= n; ++i)const int MOD = 1e9 + 7;const int qq = 2e5 + 10;const int INF = 1e9 + 10;vector<int> G[1005];int pos[1005];int ans[1005];int main(){int n, m;scanf("%d%d", &n, &m);mst(pos, -1);int maxn = 0;for(int i = 1; i <= m; ++i) {int a, b;scanf("%d%d", &a, &b);pos[a] = b;maxn = max(maxn, a);}int id = -1, cnt = 0;bool flag = true;for(int i = 1; i <= max(maxn, n) + 100; ++i) {bool f = true;for(int j = 0; j < max(maxn, n); ++j) {int floor = j / i + 1;if(j + 1 == n)ans[i] = floor;if(pos[j + 1] == -1)continue;if(pos[j + 1] != floor)f = false;}if(f) {if(id == -1) {id = ans[i];} else {if(id != ans[i])flag = false;}}}if(id == -1 || !flag) {puts("-1");} else {printf("%d\n", id);}return 0;}


C


题意:给出一个字符串,如果一个字符串中有连续的三个元音字符串并且存在两个或两个以上的不同字符,则这个字符串是错误的,现在要你用最少的空格分割字符串,是的所有字符串是正确的

思路:直接模拟即可

#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <utility>#include <bitset>using namespace std;#define LL long long#define pb push_back#define mk make_pair#define pill pair<int, int>#define mst(a, b)memset(a, b, sizeof a)#define REP(i, x, n)for(int i = x; i <= n; ++i)const int MOD = 1e9 + 7;const int qq = 2e5 + 10;const int INF = 1e9 + 10;bool iscot(char ch) {if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {return false;}return true;}char st[3005];bool vis[26];int main(){scanf("%s", st);int len = strlen(st);int kind = 0, cot = 0, l = 0;mst(vis, false);int cnt = 0;for(int i = 0; i < len; ++i) {if(iscot(st[i])) {if(!vis[st[i] - 'a'])kind++, vis[st[i] - 'a'] = true;cot++;} else {cot = kind = 0;mst(vis, false);}if(cot >= 3 && kind != 1) {if(cnt > 0)printf(" ");mst(vis, false);cot = kind = 0;if(iscot(st[i])) {if(!vis[st[i] - 'a'])kind++, vis[st[i] - 'a'] = true;cot++;} else {cot = 0;kind = 0;mst(vis, false);}for(int j = l; j < i; ++j) {printf("%c", st[j]);}l = i;cnt++;}}if(cnt > 0)printf(" ");for(int i = l; i < len; ++i) {printf("%c", st[i]);}puts("");return 0;}


D

题意:用一个最短的字串唯一标识每一个字符串

思路:直接暴力居然给过

#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <utility>#include <bitset>using namespace std;#define LL long long#define pb push_back#define mk make_pair#define pill pair<int, int>#define mst(a, b)memset(a, b, sizeof a)#define REP(i, x, n)for(int i = x; i <= n; ++i)const int MOD = 1e9 + 7;const int qq = 2e5 + 10;const int INF = 1e9 + 10;char st[70005][11];char ch[11];map<string, int> mp, str;int main(){int n;scanf("%d", &n);for(int i = 1; i <= n; ++i) {scanf("%s", st[i]);for(int len = 1; len <= 9; ++len) {for(int l = 0; l < 9; ++l) {int r = l + len - 1;if(r >= 9)break;int cnt = 0;for(int k = l; k <= r; ++k) {ch[cnt++] = st[i][k];}ch[cnt] = '\0';mp[ch]++;}}}for(int i = 1; i <= n; ++i) {bool f = false;str.clear();for(int len = 1; len <= 9; ++len) {if(f)break;for(int l = 0; l < 9; ++l) {if(f)break;int r = l + len - 1;if(r >= 9)break;int cnt = 0;for(int k = l; k <= r; ++k) {ch[cnt++] = st[i][k];}ch[cnt] = '\0';str[ch]++;}}f = false;for(int len = 1; len <= 9; ++len) {if(f)break;for(int l = 0; l < 9; ++l) {if(f)break;int r = l + len - 1;if(r >= 9)break;int cnt = 0;for(int k = l; k <= r; ++k) {ch[cnt++] = st[i][k];}ch[cnt] = '\0';if(mp[ch] == str[ch]) {puts(ch);f = true;break;}}}}return 0;}



写了个字典树版本的

对每个字符串的所有后缀插入到字典树当中,然后求答案的时候把某个字符串的所有后缀删掉,然后枚举后缀找答案,最后又加回来

#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <utility>#include <bitset>using namespace std;#define LL long long#define pb push_back#define mk make_pair#define pill pair<int, int>#define mst(a, b)memset(a, b, sizeof a)#define REP(i, x, n)for(int i = x; i <= n; ++i)const int MOD = 1e9 + 7;const int qq = 70000 + 10;const int INF = 1e9 + 10;int ch[qq * 11][11], val[qq * 11], node_cnt;char st[qq][11], ans[12];int minx;void Init() {mst(ch[0], 0), mst(val, 0);node_cnt = 1;}void Insert(char *p) {int cur = 0;for(int i = 0; p[i] != '\0'; ++i) {int idx = p[i] - '0';if(!ch[cur][idx]) {mst(ch[node_cnt], 0);ch[cur][idx] = node_cnt++;}cur = ch[cur][idx];val[cur]++;}}void Delete(char *p) {int cur = 0;for(int i = 0; p[i] != '\0'; ++i) {int idx = p[i] - '0';cur = ch[cur][idx];val[cur]--;}}void Query(char *p) {int cur = 0;char tmp[12];int cnt = 0;for(int i = 0; p[i] != '\0'; ++i) {int idx = p[i] - '0';tmp[cnt++] = p[i];cur = ch[cur][idx];if(val[cur] == 0) {if(cnt < minx) {minx = cnt;tmp[cnt] = '\0';strcpy(ans, tmp);break;}}}}int main(){Init();int n;scanf("%d", &n);for(int i = 0; i < n; ++i) {scanf("%s", st[i]);for(int j = 0; j < 9; ++j) {Insert(st[i] + j);}}for(int i = 0; i < n; ++i) {for(int j = 0; j < 9; ++j) {Delete(st[i] + j);}minx = 10;for(int j = 0; j < 9; ++j) {Query(st[i] + j);}for(int j = 0; j < 9; ++j) {Insert(st[i] + j);}puts(ans);}return 0;}


阅读全文
0 0
原创粉丝点击