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 ...
随机推荐
- SAP S4HANA1610/Fiori安装过程全记录
经历各种坑,从硬件到文件,终于安装成功. 有需要安装或使用S4HANA(含Fiori)的同学可以参考. 安装文件分享给大家 链接:http://pan.baidu.com/s/1mi7LfIS 密码: ...
- SAR指标(转)
转自(https://zhidao.baidu.com/question/187156399.html) SAR指标又叫抛物线指标或停损转向操作点指标,其全称叫“Stop and Reverse,缩写 ...
- SpringBoot面试题及答案整理
1. Spring 和 SpringBoot 有什么不同? Spring 框架提供多种特性使得 web 应用开发变得更简便,包括依赖注入.数据绑定.切面编程.数据存取等等. 随着时间推移,Spring ...
- 在eclipse中使用Tomcat时出现Could not publish server ...错误
在使用eclipse加载tomcat服务器运行项目时遇到问题: 在Tomcat的安装目录下的\conf\server.xml中将<Context>标签所对应的重复名称项目删除 这 ...
- Java基础学习笔记十九 File
IO概述 回想之前写过的程序,数据都是在内存中,一旦程序运行结束,这些数据都没有了,等下次再想使用这些数据,可是已经没有了.那怎么办呢?能不能把运算完的数据都保存下来,下次程序启动的时候,再把这些数据 ...
- socket与http
参考文档:http://blog.csdn.net/zeng622peng/article/details/5546384 1.TCP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可 ...
- Android启动页欢迎界面大全 (网址)
地址:http://download.csdn.net/detail/u013424496/9539810
- vue设置初始对象时为空报错
解决办法:在初始化时提供完整的数据结构
- C++标准模板库之vector
vector(向量容器),是 C++ 中十分有用一个容器.它能够像容器一样存放各种类型的对象,vector 是一个能够存放任意类型(类型可以是int, double, string, 还可以是类)的动 ...
- Codeforces 455A - Boredom - [DP]
题目链接:https://codeforces.com/problemset/problem/455/A 题意: 给出一个 $n$ 个数字的整数序列 $a[1 \sim n]$,每次你可以选择一个 $ ...