Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
A :
1 second
256 megabytes
standard input
standard output
Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.
The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.
Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color x
such that there are currently at least two puppies of color x and recolor all puppies of the color x into some arbitrary color y
. Luckily, this operation can be applied multiple times (including zero).
For example, if the number of puppies is 7
and their colors are represented as the string "abababc", then in one operation Slava can get the results "zbzbzbc", "bbbbbbc", "aaaaaac", "acacacc" and others. However, if the current color sequence is "abababc", then he can't choose x
='c' right now, because currently only one puppy has the color 'c'.
Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.
The first line contains a single integer n
(1≤n≤105
) — the number of puppies.
The second line contains a string s
of length n consisting of lowercase Latin letters, where the i-th symbol denotes the i
-th puppy's color.
If it's possible to recolor all puppies into one color, print "Yes".
Otherwise print "No".
Output the answer without quotation signs.
6
aabddc
Yes
3
abc
No
3
jjj
Yes
In the first example Slava can perform the following steps:
- take all puppies of color 'a' (a total of two) and recolor them into 'b';
- take all puppies of color 'd' (a total of two) and recolor them into 'c';
- take all puppies of color 'b' (three puppies for now) and recolor them into 'c'.
In the second example it's impossible to recolor any of the puppies.
In the third example all the puppies' colors are the same; thus there's no need to recolor anything.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#pragma GCC diagnostic error "-std=c++11"
#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
#pragma GCC target("avx","sse2")
typedef long long ll;
const double PI = acos(-1.0);
const int INF = ;
const int maxn = ; void Debug()
{
puts("");
cout<<"+++++++++++++++++++++++++++�ֽ���++++++++++++++++++++++++++++++"<<endl;
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
cout<<<<" ";
}
cout<<endl;
}
cout<<"+++++++++++++++++++++++++++�ֽ���++++++++++++++++++++++++++++++"<<endl;
puts("");
}
int vis[]; char f[]; int flag = ; int main ()
{
int n;scanf ("%d" , &n);scanf ("%s" , &f);
if (n == ){printf ("YES\n");return ;}
for (int i = ; i < n ; i++){int h = f[i] - 'a';vis[h]++;if (vis[h] >= ){
flag++;
break;
}
}if (flag) printf ("YES\n");
else printf ("NO\n");
}
B:
1.5 seconds
256 megabytes
standard input
standard output
During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.
For a given list of pairs of integers (a1,b1)
, (a2,b2), ..., (an,bn) their WCD is arbitrary integer greater than 1
, such that it divides at least one element in each pair. WCD may not exist for some lists.
For example, if the list looks like [(12,15),(25,18),(10,24)]
, then their WCD can be equal to 2, 3, 5 or 6 (each of these numbers is strictly greater than 1
and divides at least one number in each pair).
You're currently pursuing your PhD degree under Ildar's mentorship, and that's why this problem was delegated to you. Your task is to calculate WCD efficiently.
The first line contains a single integer n
(1≤n≤150000
) — the number of pairs.
Each of the next n
lines contains two integer values ai, bi (2≤ai,bi≤2⋅109
).
Print a single integer — the WCD of the set of pairs.
If there are multiple possible answers, output any; if there is no answer, print −1
.
3
17 18
15 24
12 15
6
2
10 16
7 17
-1
5
90 108
45 105
75 40
165 175
33 30
5
In the first example the answer is 6
from the third ones. Note that other valid answers will also be accepted.
In the second example there are no integers greater than 1
satisfying the conditions.
In the third example one of the possible answers is 5
开始想复杂勒, 其实只要求出每行两个数的最小公倍数,再求所有最小公倍数的最大公因数,判断是否为1;
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define LL long long
#define mk(a,b) make_pair(a,b)
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
LL a[][];
inline LL gcd(LL x,LL y){
return y?gcd(y,x%y):x;
}
int main(){
int n;
scanf("%d",&n);
LL sum=,ans=;
for(int i=;i<=n;i++){
scanf("%lld%lld",&a[i][],&a[i][]);
sum=gcd(a[i][]*a[i][],sum);
}
if(sum==){
printf("-1\n");
return ;
}
for(int i=;i*i<=a[][];i++){
if(ans==&&sum%i==)ans=i;
while(a[][]%i==)a[][]/=i;
}
if(ans==&&a[][]>&&sum%a[][]==)ans=a[][];
for(int i=;i*i<=a[][];i++){
if(ans==&&sum%i==)ans=i;
while(a[][]%i==)a[][]/=i;
}
if(ans==&&a[][]>&&sum%a[][]==)ans=a[][];
printf("%lld\n",ans);
}
C,D : 不会待补。。。
EFG : 再说吧<>
Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)的更多相关文章
- D. Recovering BST Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd( ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)
B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B. Weakened Common Divis
题目链接 让你找一个数,使得这个数,可以被每个二元组的两个数中的一个数整除. 先将第一个二元组的两个数质因数分解一下,分解的质数加入set中,然后,对剩下的n-1个二元组进行遍历,每次遍历到的二元组对 ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-C. Plasticine zebra
问了学长,感觉还是很迷啊,不过懂了个大概,这个翻转操作,实质不就是在序列后面加上前面部分比如 bw | wwbwwbw 操作过后 wbwbwwbww 而 bw | wwbwwbwbw 这样我们就知道 ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) 题解
真心简单的一场比赛 就是坑比较多(自己太蠢) A是一个水题 3分钟的时候过了 B也是一个比较简单的题 类似的套路见得多了 但是我当时可能比较困 想了一会才想出来 19分钟的时候过掉了 C同样很显然 性 ...
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) C】
[链接] 我是链接,点我呀:) [题意] 给你一个字符串s. 让你在其中的某一些位置进行操作.. 把[1..i]和[i+1..n]翻转. 使得里面01交替出现的那种子串的长度最长. [题解] 可以用a ...
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A】 Doggo Recoloring
[链接] 我是链接,点我呀:) [题意] 你可以把出现次数大于1的颜色换成其他颜色. 问你最后能不能全都变成同一种颜色 [题解] 判断一下有没有出现次数大于1的就好. 有的话.显然可以一直用它变颜色. ...
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B】Weakened Common Divisor
[链接] 我是链接,点我呀:) [题意] 给你n个数对(ai,bi). 让你求一个大于1的数字x 使得对于任意的i x|a[i] 或者 x|b[i] [题解] 求出第一个数对的两个数他们有哪些质因子. ...
- E - Down or Right Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #i ...
随机推荐
- 第四百一十四节,python常用算法学习
本节内容 算法定义 时间复杂度 空间复杂度 常用算法实例 1.算法定义 算法(Algorithm)是指解题方案的准确而完整的描述,是一系列解决问题的清晰指令,算法代表着用系统的方法描述解决问题的策略机 ...
- JavaScript学习历程03
一闪一闪亮晶晶 <script type="text/javascript"> var nn = Number(prompt('请输入一个1-9的正整数!')); va ...
- CSS面试题
1.有哪些方式可以对一个DOM设置它的CSS样式? 外部样式表.引入一个外部CSS文件: 内部样式表.将CSS代码放在<head>标签内部: 内联样式,将CSS样式直接定义在HTML元素内 ...
- 零拷贝sendfile解析
传统方式read/write send/recv 在传统的文件传输里面(read/write方式),在实现上事实上是比較复杂的,须要经过多次上下文的切换.我们看一下例如以下两行代码: 1. read( ...
- P5173 传球
题目背景 临近中考,pG的班主任决定上一节体育课,放松一下. 题解:https://blog.csdn.net/kkkksc03/article/details/85008120 题目描述 老师带着p ...
- [Golang] kafka集群搭建和golang版生产者和消费者
一.kafka集群搭建 至于kafka是什么我都不多做介绍了,网上写的已经非常详尽了. 1. 下载zookeeper https://zookeeper.apache.org/releases.ht ...
- webpack使用小记
前言 webpack是目前前端开发必不可少的一款模块加载器兼构建工具,它能极其方便的处理各种资源的打包和使用, 让前端开发获得与后端开发几乎一致的体验. webpack特点 webpack 是以 co ...
- CentOS7.X中设置nginx和php-fpm的开机自启动
一.设置nginx的开机自启动方法 1.在/etc/init.d/目录下创建nginx文件 vi /etc/init.d/nginx 编写内容如下: #!/bin/sh # # nginx - thi ...
- linux Ubuntu系统安装百度aip
1.下载百度api pip install baidu-aip 2.配置视频转码工具ffmpeg Ubuntu16.04下安装FFmpeg(超简单版) 第一步:添加源. sudo add-apt-re ...
- nginx_ssl_tomcat配置
<Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" ...