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 ...
随机推荐
- Dictionary<string, object>不区分大小写
Dictionary<string, object> dic = new Dictionary<string, object>(StringComparer.OrdinalIg ...
- 破解b站极验验证码
这就是极验验证码,通过拖动滑块移动拼图来验证.我们观察到点击滑块时拼图才会出现,所以我们可以在点击滑块之前截取图像,点击滑块再截取一次图像,将前后两次图像做比较就可以找到图片改动的位置.获得位置后,我 ...
- WeUI logo专为微信设计的 UI 库 WeUI
http://www.oschina.net/p/weui?fromerr=FnwHyWAb http://weui.github.io/weui/
- Splunk大数据分析经验分享
转自:http://www.freebuf.com/articles/database/123006.html Splunk大数据分析经验分享:从入门到夺门而逃 Porsche 2016-12-19 ...
- ASP.NET MVC4 新手入门教程之二 ---2.添加控制器
MVC 代表 模型-视图-控制器.MVC 是一个模式用于开发应用程序是很好的架构. 可检验性和易于维护.基于 MVC 的应用程序包含: Models: 类表示应用程序的数据并使用验证逻辑以执行这些数据 ...
- mybatis学习之分页
分页一般分为物理分页:先查询所有值再分页输出,逻辑分页:直接分页查询输出,mybatis支持物理分页,如下: 1.物理分页: mapper映射: <select id="findStu ...
- 八、profile多环境配置
通常我们的程序有着多个环境: 1.开发环境: 2.生产环境. 等 环境的配置各不相同,我们希望通过一个简单的配置来切换环境,而springboot轻松地实现了该功能: 一.多环境需要多配置文件 一般我 ...
- 关于request请求的基本获取
1.Request对象的作用是与客户端交互,收集客户端的Form.Cookies.超链接,或者收集服务器端的环境变量. request对象是从客户端向服务器发出请求,包括用户提交的信息以及客户端的 ...
- java web 之Session
1.Session简单介绍 由于Http是无状态的协议,所以服务端需要记录用户的状态时,就需要某种机制来识别具体的用户,实现这个机制的方式就是session. 典型的场景比如购物车,当你点击下单按钮时 ...
- Eclipse使用快捷键总结
1.为方法添加注释:Alt + Shift + J