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 ...
随机推荐
- C语言socket编程
建议先去看一下思路 真的写的很不错呦~ 思路参考博客:https://www.cnblogs.com/renfanzi/p/5713054.html linux c语言socket编程代码(单一服务端 ...
- Direct3D 11 Tutorial 1: Basics_Direct3D 11 教程1:基础
Github-LearnDirectX-DX3D11 tutorial01 概述 在这第一篇教程中,我们将通过介绍创建最小Direct3D应用程序所必需的元素.每一个Direct3D应用程序必需拥有这 ...
- open-falcon实现邮件报警
1.请安装好Go的环境,参考上一篇open-falcon的安装博文 2.安装 mail-provider https://github.com/open-falcon/mail-provider 安装 ...
- 并发编程基础之ThreadLocal
一:概念 在多线程并发访问的情况下,为了解决线程安全,一般我们会使用synchronized关键字,如果并发访问量不是很大,可以使用synchronized, 但是如果数据量比较大,我们可以考虑使用T ...
- 【Java核心技术】类型信息(Class对象 反射 动态代理)
1 Class对象 理解RTTI在Java中的工作原理,首先需要知道类型信息在运行时是如何表示的,这是由Class对象来完成的,它包含了与类有关的信息.Class对象就是用来创建所有“常规”对象的,J ...
- C#队列Queue实现一个简单的电商网站秒杀程序
电商的秒杀和抢购,对程序员来说,都不是一个陌生的东西.然而,从技术的角度来说,这对于Web系统是一个巨大的考验.当一个Web系统,在一秒钟内收到数以万计甚至更多请求时,系统的优化和稳定至关重要. 我们 ...
- jenkins git 之 Advanced clone behaviours
jenins 上的 Git Plugin插件,默认是下载完整的历史版本,随着分支约多,历史版本约多,整个文件会很大,下载常常会超时. 单独的git命令可以使用以下方式来优化 git clone --d ...
- mysql中的事物处理
首先,事物的概念,保证一组sql语句操作的完整性,在这个过程中要充分考虑到多用户同时访问数据库数据的情况. 关键词有COMMIT,ROLLBACK,,START TRANSACTION
- LPVOID 没有类型的指针
可以将LPVOID类型的变量赋值给任意类型的指针,比如在参数传递时就可以把任意类型传递给一个LPVOID类型为参数的方法,然后在方法内再将这个“任意类型”从传递时的“LPVOID类型”转换回来. 示例 ...
- java JVM虚拟机
JVM垃圾处理方法(标记清除.复制.标记整理) 1.标记清除 标记阶段:先通过根节点,标记所有从根节点开始的对象,未被标记的为垃圾对象. 清除阶段:清除所有未被标记的对象. 2.复制算法 将原有的空间 ...