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\),并 ...
随机推荐
- eclipse3.4+对的处理插件(附SVN插件安装实例)
Eclipse 3.4以前安装插件无非有两种方式, 直接copy插件到features/plugins目录或者在links目录下创建链接文件. Eclipse 3.4又推出另一种新的安装途径, 更加灵 ...
- 实现strcpy函数
不使用库函数,实现strcpy函数: char *my_strcpy(char *t,char *s){ char *strDest=t; if(t==NULL && s==NULL) ...
- Unity3D中使用Projector生成阴影
在Unity3D中使用Projector实现动态阴影 无意中看见一篇博客叙述使用Projector实现动态阴影可以在移动平台拥有非常好的性能,遂按照其想法实现了一遍,发现其中竟有许多细节,写下这篇博客 ...
- CMDB API验证
CMDB API验证 为什么做API验证 API验证是防止数据在传输的过程中,保证数据不被篡改 如何设计的API验证 灵感来源于Torando中加密Cookie的源码,主要是生成加密的随机字符串. M ...
- ubuntu 16.04 连接 wifi
我的电脑是win10+ubuntu16.04双系统.在ubuntu下无法连接wifi,一直用usb连接的手机流量,不太方便.现在来用安装无线驱动,顺便翻个墙. https://blog.csdn.ne ...
- [Codeforces Round #250]小朋友和二叉树
题目描述: bzoj luogu 题解: 生成函数ntt. 显然这种二叉树应该暴力薅掉树根然后分裂成两棵子树. 所以$f(x)= \sum_{i \in c} \sum _{j=0}^{x-c} f( ...
- Spring Security和Shiro的比较和使用
https://blog.csdn.net/it_java_shuai/article/details/78054951 Spring Security和Shiro的比较和使用 2017年09月21日 ...
- Golang 简单 http 代理转发
程序基本实现了对http的完整转发,目前暂不支持https windows需要在设置中的网络>代理设置为手动,并开启代理服务器,填写ip和端口 // httpForward package ma ...
- Voyager如何使用Compass
Compass由Resources,Commands,Logs三个部分组成 Resources包含了Links和Fonts: Commands可以执行php命令,比如创建model: 创建一个Down ...
- 序列内置方法详解(string/list/tuple)
一.常用方法集合 1.1.string,字符串常用方法 以下举例是python2.7测试: 函数名称 作用 举例 str.capitalize() 字符串第一个字符如果是字母,则把字母替换为大写字母. ...