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的最小公倍数。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
int main() {
ll n, k, s=;
scanf("%lld %lld", &n, &k);
while(k--) s *= ;
ll t = gcd(n, s);
printf("%lld\n", n / t * s);
return ;
}
15ms
codeforces 858B. Which floor? 【暴力】
题意:已知每层楼的房间数量相同但不知道具体数目,从一楼往上依次给每个房间从小到大编号(从1号开始),现在给出m个房间的信息(房间号和所在楼层),求第n号房间所在楼层,若有多解则输出-1。
题解:暴力,维护每层楼的可能的最小、最大房间数。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main() {
int n, m, k, f;
int mi=, ma=;
scanf("%d%d", &n, &m);
while(m--) {
scanf("%d%d", &k, &f);
if(f>) ma = min(ma, (k-)/(f-));
mi = max(mi, (k+f-)/f);
}
//printf("%d %d\n", mi, ma);
if((f=(n+mi-)/mi) != (n+ma-)/ma) puts("-1");
else printf("%d\n", f);
return ;
}
15ms
codeforces 858C. Did you mean...【水】
题意:给你一个字符串,现在要你给其中加空格隔开单词,使得每个单词不能有连续三个以上不同的辅音字母,输出加的空格最少的字符串。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int N = ;
char s[N], t[N];
map<char, int> mp;
int main() {
mp['a'] = mp['e'] = mp['i'] = mp['o'] = mp['u'] = ;
int i, len;
gets(s);
len = strlen(s);
if(len < ) {puts(s); return ;}
int cnt = ;
t[cnt++] = s[]; t[cnt++] = s[];
for(i = ; i < len; ++i) {
if(!mp[s[i]] && !mp[s[i-]] && !mp[s[i-]] &&
(s[i]!=s[i-] || s[i-] != s[i-])) {
t[cnt++] = ' '; t[cnt++] = s[i];
s[i-] = s[i-] = 'a';
}
else t[cnt++] = s[i];
}
t[cnt++] = '\0';
puts(t);
return ;
}
31ms
待补。。
codeforces 858D. Polycarp's phone book【字典树】
题意:有n个不同的九位数的电话号码(非0开头),求每个电话号的最短的能唯一索引该号码的子串。(输入保证所有号码不同)
题解:将每个字符串的所有后缀插入字典树中,对每个号码的查询就先把其所有后缀删除,然后对其所有后缀查找其前缀出现的次数为0的最短号码即为答案。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
const int M = ;
const int len = ;
char a[N][M];
struct Trie {
int next[M];
int cnt;
void init() {
cnt = ;
memset(next, -, sizeof(next));
}
}T[];
int le;
void inser(char *s) {
int i = , p = ;
while(s[i]) {
int id = s[i] - '';
if(T[p].next[id] == -) {
T[le].init();
T[p].next[id] = le++;
}
p = T[p].next[id];
T[p].cnt++;
i++;
}
}
void add(char *s) {
int i = , p = ;
while(s[i]) {
int id = s[i] - '';
p = T[p].next[id];
T[p].cnt++;
i++;
}
}
void del(char *s) {
int i = , p = ;
while(s[i]) {
int id = s[i] - '';
p = T[p].next[id];
T[p].cnt--;
i++;
}
}
int query(char *s) {
int i = , p = ;
while(s[i]) {
int id = s[i] - '';
p = T[p].next[id];
if(T[p].cnt == ) return i;
i++;
}
return ;
}
int main() {
int n, m, i, j, mi, t, l, r;
scanf("%d", &n);
le = ;
T[].init();
for(i = ; i<= n; ++i) {
scanf("%s", a[i]);
for(j = ; j < len; ++j) inser(a[i]+j);
}
for(i = ; i<= n; ++i) {
mi = ;
for(j = ; j < len; ++j) del(a[i]+j);
for(j = ; j < len; ++j) {
t = query(a[i]+j);
if(t < mi) {mi = t; l = j; r = j+t;}
}
for(j = ; j < len; ++j) add(a[i]+j);
for(j = l; j <= r; ++j) printf("%c", a[i][j]);
puts("");
}
return ;
}
186ms
Codeforces Round #434 (Div. 2)【A、B、C、D】的更多相关文章
- Codeforces Round #434 (Div. 2)
Codeforces Round #434 (Div. 2) 刚好时间对得上,就去打了一场cf,发现自己的代码正确度有待提高. A. k-rounding 题目描述:给定两个整数\(n, k\),求一 ...
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...
- Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...
- Codeforces Round #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...
- Codeforces Round #439 (Div. 2)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
- Codeforces Round #430 (Div. 2) 【A、B、C、D题】
[感谢牛老板对D题的指点OTZ] codeforces 842 A. Kirill And The Game[暴力] 给定a的范围[l,r],b的范围[x,y],问是否存在a/b等于k.直接暴力判断即 ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
随机推荐
- 快手、抖音、微视类短视频SDK接入教程,7步就能搞定
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由视频咖 发表于云+社区专栏 终端部分 按照如下三步操作,可以用 XCode 或者 Android Studio 编译和调试小视频 Ap ...
- Python基础(3) - 数据类型:1数字类型
Python数据类型 数据类型 是否容器 是否可变 存储方式 数字 否 否 直接 字符串 否 否 直接 列表 是 是 顺序 元组 是 否 顺序 字典 是 是 映射 数字类型 整 型:1,234,0, ...
- CentOS 升级 openSSH
openSSH作为linux远程连接工具,容易受到攻击,必须更新版本来解决,低版本有如下等漏洞: a. OpenSSH 远程代码执行漏洞(CVE-2016-10009) b. OpenSSH aut ...
- Boost application performance using asynchronous I/O-ref
http://www.ibm.com/developerworks/linux/library/l-async/?S_TACT=105AGX52&S_CMP=cn-a-l Introducti ...
- java.net.SocketException四大异常解决方案---转
java.net.SocketException如何才能更好的使用呢?这个就需要我们先要了解有关这个语言的相关问题.希望大家有所帮助.那么我们就来看看有关java.net.SocketExceptio ...
- Flask & Vue 构建前后端分离的应用
Flask & Vue 构建前后端分离的应用 最近在使用 Flask 制作基于 HTML5 的桌面应用,前面写过<用 Python 构建 web 应用>,借助于完善的 Flask ...
- viewport其实没那么难理解
在学习移动端布局的时候,你肯定听说过"viewport"这个词,然后去问度娘或谷歌.你会惊奇的发现,这个viewport不简单,居然有那么多兄弟——layout viewport. ...
- 点击checkbox全选,其它被选中,再点击取消
<input type="checkbox" value="" id="checkall" name="" siz ...
- Centos7 linux 安装 redis 遇到的几个问题
环境:centos7 + redis 5.0 解决方案仅供参考,如不能解决问题,请查找请他方案. 1.不能编译没有GCC 编译工具 make报错: make[1]: [persist-set ...
- Rabbit简单队列模式
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/ ...