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 ...
随机推荐
- linux-pm2用法
devo.ps团队对JavaScript的迷恋已经不是什么秘密了;node.js作为服务器端,AngularJS作为客户端,某种程度上说,我们的堆栈是用它建成的.我们构建静态客户端和RESTful J ...
- 判断img图片是否加载成功
上班之余,记录一下工作中遇到的有趣问题... 事情是这样的...在做一个内嵌H5的app时,有一个“个人名片”页面...要求:如果后台接口有给头像的图片链接就用他们给的,如果没给,前端给个默认头像.. ...
- 封装常用的跨浏览器的事件对象EventUtil
var EventUtil = { addHandler: function(element,type,handler) { //事件监听 if(element.addEventListener) { ...
- C#实体对象序列化成Json,格式化,并让字段的首字母小写
解决办法有两种:第一种:使用对象的字段属性设置JsonProperty来实现(不推荐,因为需要手动的修改每个字段的属性) public class UserInfo { [JsonProperty(& ...
- ASP.NET MVC4 新手入门教程之一 ---1.介绍ASP.NET MVC4
你会建造 您将实现一个简单的电影清单应用程序支持创建. 编辑. 搜索和清单数据库中的电影.下面是您将构建的应用程序的两个屏幕截图.它包括显示来自数据库的电影列表的网页: 应用程序还允许您添加. 编辑和 ...
- Redis - 数据类型常用命令
5种数据类型都离不开key,先列出key的相关命令. KEY相关操作 列出符合规则的KEYS KEYS pattern pattern支持glob风格的通配符格式,即: ? 一个字符 * 任意多个字符 ...
- JS实现队列
JS实现队列: 队列是一种特殊的线性表,特殊之处在于它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作,和栈一样,队列是一种操作受限制的线性表.进行插入操作的端称为队尾 ...
- webservice log4net日志写入失败
原因1:如果webservice和调用者都部署在一台机器上,日志有可能写到了项目所在目录中,虽然你添加的服务引用是部署在iis下的,但不会写到这.暂时解决办法,把webservice部署到内网服务器上 ...
- https如何工作
一.http 网络协议基于分层架构构建了七层模型,是ISO建立的用于计算机或者通信系统之间的互联的标准体系.下图展示了其中的五层: http被称为超文本传输协议,是互联网上应用最为广泛的一种网络协议, ...
- Java多线程系列--CopyOnWriteArraySet
转载:http://www.cnblogs.com/skywang12345/p/3498497.html 概要 本章是JUC系列中的CopyOnWriteArraySet篇.接下来,会先对CopyO ...