AtCoder Grand Contest 022
A - Diverse Word
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order.
A word is called diverse if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, atcoder
, zscoder
and agc
are diverse words while gotou
and connect
aren't diverse words.
Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist.
Let X=x1x2…xn and Y=y1y2…ym be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or xj>yj where j is the smallest integer such that xj≠yj.
Constraints
- 1≤|S|≤26
- S is a diverse word.
Input
Input is given from Standard Input in the following format:
S
Output
Print the next word that appears after S in the dictionary, or -1
if it doesn't exist.
Sample Input 1
atcoder
Sample Output 1
atcoderb
atcoderb
is the lexicographically smallest diverse word that is lexicographically larger than atcoder
. Note that atcoderb
is lexicographically smaller than b
.
Sample Input 2
abc
Sample Output 2
abcd
Sample Input 3
zyxwvutsrqponmlkjihgfedcba
Sample Output 3
-1
This is the lexicographically largest diverse word, so the answer is -1
.
Sample Input 4
abcdefghijklmnopqrstuvwzyx
Sample Output 4
abcdefghijklmnopqrstuvx
这个比赛也挺棒的啊,但是A题我就惨了啊
一个字符串存不存在下一个全排列,存在的话输出-1,否则输出他最小的,这个方法很棒,要不然得分三种情况
#include <bits/stdc++.h>
using namespace std;
int a[];
char s[];
int main()
{
cin>>s;
int l=;
for(int i=; s[i]; i++)a[s[i]]=,l++;
for(int c='z'; c>='a'; c--)
if(!a[c])s[l++]=c;
if(next_permutation(s,s+l))
cout<<s;
else
cout<<-;
return ;
}
B - GCD Sequence
Time limit : 2sec / Memory limit : 256MB
Score : 600 points
Problem Statement
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S={a1,a2,…,aN} of distinct positive integers is called special if for all 1≤i≤N, the gcd (greatest common divisor) of ai and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
- 3≤N≤20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
- The elements must be distinct positive integers not exceeding 30000.
- The gcd of all elements of S is 1, i.e. there does not exist an integer d>1 that divides all elements of S.
- S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Sample Input 1
3
Sample Output 1
2 5 63
{2,5,63} is special because gcd(2,5+63)=2,gcd(5,2+63)=5,gcd(63,2+5)=7. Also, gcd(2,5,63)=1. Thus, this set satisfies all the criteria.
Note that {2,4,6} is not a valid solution because gcd(2,4,6)=2>1.
Sample Input 2
4
Sample Output 2
2 5 20 63
{2,5,20,63} is special because gcd(2,5+20+63)=2,gcd(5,2+20+63)=5,gcd(20,2+5+63)=10,gcd(63,2+5+20)=9. Also, gcd(2,5,20,63)=1. Thus, this set satisfies all the criteria.
让你构造一个序列,首先这个序列的值的gcd值为1,其他的每一个数和其他数的和的gcd不是1
这个构造好难啊,看到别人的那个序列才知道还有这种操作
#include<bits/stdc++.h>
using namespace std;
int n,t[];
int main()
{
scanf("%d",&n);
if(n==)printf("2 5 63");
else
{
if(n&)
t[]=,t[]=,t[]=,t[]=,t[]=,t[]=,t[]=,t[]=;
else
t[]=,t[]=,t[]=,t[]=,t[]=,t[]=,t[]=,t[]=;
for(int i=; i<min(n,); i++)printf("%d ",t[i]);
for(int i=; i<n; i++)t[i%]=t[i%]+,printf("%d ",t[i%]);
}
return ;
}
AtCoder Grand Contest 022的更多相关文章
- Atcoder Grand Contest 022 E - Median Replace(dp)
Atcoder 题面传送门 & 洛谷题面传送门 首先考虑对于固定的 01 串怎样计算它是否可以通过将三个连续的 \(0\) 或 \(1\) 替换为其中位数得到.我们考虑单调栈,新建一个栈,栈底 ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 007
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...
- AtCoder Grand Contest 006
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...
随机推荐
- ArcSDE 10.1 For Windows 创建空间数据库与常见错误_SQL Server
本文是2013年时候参加ESRI竞赛,创建ArcSDE 10.1 for SQL Server时候出问题了,因此写了该文档. 由于一直忙于学习,忘了发布.今天一师弟也遇到同样问题,为此我觉得可能有不少 ...
- Cordova for iOS
Cordova,对这个名字大家可能比较陌生,大家肯定听过 PhoneGap 这个名字,Cordova 就是 PhoneGap 被 Adobe 收购后所改的名字. Cordova 是一个可以让 JS 与 ...
- UVA 11997 K Smallest Sums (多路归并)
从包含k个整数的k个数组中各选一个求和,在所有的和中选最小的k个值. 思路是多路归并,对于两个长度为k的有序表按一定顺序选两个数字组成和,(B表已经有序)会形成n个有序表 A1+B1<=A1+B ...
- UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
任意线可以贪心移动到两点上.直接枚举O(n^3),会TLE. 所以采取扫描法,选基准点,然后根据极角或者两两做叉积比较进行排排序,然后扫一遍就好了.旋转的时候在O(1)时间推出下一种情况,总复杂度为O ...
- Android(java)学习笔记110:Java中操作文件的类介绍(File + IO流)
1.File类:对硬盘上的文件和目录进行操作的类. File类是文件和目录路径名抽象表现形式 构造函数: 1) File(String pathname) Creat ...
- Problem T: 结构体--学生信息排序
Problem T: 结构体--学生信息排序 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2219 Solved: 1305[Submit][Sta ...
- k8s1.13.0二进制部署-flannel网络(二)
Flannel容器集群网络部署 Overlay Network:覆盖网络,在基础网络上叠加的一种虚拟网络技术模式,该网络中的主机通过虚拟链路连接起来.VXLAN:将源数据包封装到UDP中,并使用基础网 ...
- Linux运维笔记--第二部
第2部-重要目录结构详解 1.回顾Linux目录结构知识 /dev/ 设备目录 /etc/ 系统配置及服务配置文件,启动命令的目录 /proc ...
- 使用 CFile 的子类 CStdioFile 的注意事项
目前为止只用到了 ReadString,也了解了一下 WriteString. 由于程序需要,本来程序中是用的CFile, 但是需要逐行读取文件数据,所以谷歌找到了 ReadString 类 —— 继 ...
- 控件中添加的成员变量value和control的区别
control型变量是这个控件所属类的一个实例(对象)可以通过这个变量来对该控件进行一些设置.而value只是用来传递数据,不能对控件进行其它的操作.control型变量可以获得控件的实例,通过这个变 ...