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】的更多相关文章

  1. Codeforces Round #434 (Div. 2)

    Codeforces Round #434 (Div. 2) 刚好时间对得上,就去打了一场cf,发现自己的代码正确度有待提高. A. k-rounding 题目描述:给定两个整数\(n, k\),求一 ...

  2. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  3. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  4. Codeforces Round #436 (Div. 2)【A、B、C、D、E】

    Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...

  5. Codeforces Round #435 (Div. 2)【A、B、C、D】

    //在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...

  6. Codeforces Round #440 (Div. 2)【A、B、C、E】

    Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...

  7. Codeforces Round #439 (Div. 2)【A、B、C、E】

    Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...

  8. 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.直接暴力判断即 ...

  9. 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 ...

随机推荐

  1. bzoj 5368: [Pkusc2018]真实排名

    Description 小C是某知名比赛的组织者,该比赛一共有n名选手参加,每个选手的成绩是一个非负整数,定义一个选手的排名是 :成绩不小于他的选手的数量(包括他自己).例如如果3位选手的成绩分别是[ ...

  2. jQuery实现单击和鼠标感应事件。

    1.实现单击事件动态交替http://www.cnblogs.com/ahthw/p/4232837.html讲到了toggleClass(),对于单击事件而言,jQuery同样提供了动态交替的tog ...

  3. MongoDB 线上环境按照及配置(授权方式启动)

    1创建文件repo文件 #vim /etc/yum.repos.d/mongodb-org-3.4.repo [mongodb-org-3.4] name=MongoDB Repository bas ...

  4. 添加jquery脚本文件

    对于后台添加JQuery需要加上../js {insert_scripts files ="../js/jquery.1.14.min.js"}

  5. 互联网轻量级框架SSM-查缺补漏第七天(MyBatis的解析和运行原理)

    第七章MyBatis的解析和运行原理 SqlSessionFactory是MyBatis的核心类之一,其最重要的功能就是提供创建MyBatis的核心借口SqlSession,所以要先创建SqlSess ...

  6. JAVA SwingWorkder的使用例

    最近在学习Swing,我们都知道在UI表现线程里面长时间执行操作时,画面会假死,为了能够让费时操作不影响画面表现,就需要用多线程了.首先考虑的就是Swing内部的 SwingWorkder对象,但是网 ...

  7. thinkphp下判断状态值语法

    在thinkphp框架下我们经常会用到状态值的判断:但是这样写会引起语法错误. <div> <if condition="{$res.status} eq '0'" ...

  8. ajax接收flask传递的json数据

    from flask import Flask, request import json app = Flask(__name__) @app.route('/') def func(): res = ...

  9. JS里的居民们6-数组排序

    编码 var arr = [43, 54, 4, -4, 84, 100, 58, 27, 140]; 将上面数组分别按从大到小以及从小到大进行排序后在console中输出 var arr = ['a ...

  10. 怎样修改织梦网站的favicon图标

    现在很多的网站浏览器栏上都有favicon图标,比如百度,大家用织梦做好网站后,可能发现自己的网站favicon图标默认的不好看,如何修改织梦网站的favicon导航图标呢,很多人肯定有过困惑,小编遇 ...