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 ...
随机推荐
- JNI注册调用完整过程-安卓4.4
在Android系统中,JNI方法是以C/C++语言来实现的,然后编译在一个so文件里面,以我之前的例子为例Android Studio使用JNI,调用之前要加载到当前应用程序的进程的地址空间中: s ...
- 正则表达式识别字符串中的URL
一般我们经常看到一些在帖子或者别人的文章里,文字中间还会夹带着很多的网址还有URL而且URL还是可以点击进去的:还有另外一个较常用到的地方就是聊天系统中识别对话的URL,废话不多说,入正题请看下面的代 ...
- android studio应用获取系统属性权限(SystemProperties)
dependencies { provided files(getLayoutLibPath()) } /** ZhangChao time:2014-12-31,get layoutlib.jar ...
- javascript进行base64加密,解密
function Base64() { // private property _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr ...
- VMware workstation 虚拟机安装Windows Server 2008 r2
问题秒速: VMware workstation 虚拟机安装Windows Server 2008 r2,配置好参数后,选择开机,报错,错误如图:
- 从 C#编写的Exe里面提取图标和图片
记得原来是可以通过PE直接提取Exe里面的图片的,不知道为什么不能用了,下面是通过加载程序集反射出Resources 里面的图片或者图标: 提取结果直接存放到编译目录了,不知道向左向右,自己又回到Wi ...
- 借助 CORS 从 JavaScript 使用 API 应用
应用服务提供内置的跨域资源共享 (CORS) 支持,可让 JavaScript 客户端对 API 应用中托管的 API 进行跨域调用.应用服务允许配置对 API 的 CORS 访问,无需在 API 中 ...
- C++命名空间使用代码
namesp.h #pragma once #include <string> namespace pers { using namespace std; struct Person { ...
- express常用中间件
整理一下工作中经常使用到的Express中间件 config-lite: 读取配置文件 不同环境下配置文件使用 - Node实战 config-lite express-session: sessio ...
- Linux基础之-Bash命令优先级
一. Bash简介 命令解释器,也就是 Bourne Again Shell,起源于shell.shell俗称壳,它是指UNIX系统下的一个命令解析器:主要用于用户和系统的交互.UNIX系统上有很多种 ...