博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder Grand Contest 022
阅读量:5741 次
发布时间:2019-06-18

本文共 4168 字,大约阅读时间需要 13 分钟。

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, atcoderzscoderand 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 xjyj.

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

Copy
atcoder

Sample Output 1

Copy
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

Copy
abc

Sample Output 2

Copy
abcd

Sample Input 3

Copy
zyxwvutsrqponmlkjihgfedcba

Sample Output 3

Copy
-1

This is the lexicographically largest diverse word, so the answer is -1.


Sample Input 4

Copy
abcdefghijklmnopqrstuvwzyx

Sample Output 4

Copy
abcdefghijklmnopqrstuvx

这个比赛也挺棒的啊,但是A题我就惨了啊

一个字符串存不存在下一个全排列,存在的话输出-1,否则输出他最小的,这个方法很棒,要不然得分三种情况

#include 
using namespace std;int a[256];char s[256];int main(){ cin>>s; int l=1; for(int i=0; s[i]; i++)a[s[i]]=1,l++; for(int c='z'; c>='a'; c--) if(!a[c])s[l++]=c; if(next_permutation(s,s+l)) cout<

 

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≤iN, 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 SS 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

Copy
3

Sample Output 1

Copy
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

Copy
4

Sample Output 2

Copy
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
using namespace std;int n,t[9];int main(){ scanf("%d",&n); if(n==3)printf("2 5 63"); else { if(n&1) t[0]=6,t[1]=2,t[2]=10,t[3]=3,t[4]=9,t[5]=4,t[6]=8,t[7]=12; else t[0]=2,t[1]=10,t[2]=3,t[3]=9,t[4]=4,t[5]=8,t[6]=6,t[7]=12; for(int i=0; i

 

转载于:https://www.cnblogs.com/BobHuang/p/8688897.html

你可能感兴趣的文章
10个巨大的科学难题需要大数据解决方案
查看>>
Setting Up a Kerberos server (with Debian/Ubuntu)
查看>>
用 ThreadLocal 管理用户session
查看>>
setprecision后是要四舍五入吗?
查看>>
shiro初步 shiro授权
查看>>
上云就是这么简单——阿里云10分钟快速入门
查看>>
MFC多线程的创建,包括工作线程和用户界面线程
查看>>
我的友情链接
查看>>
FreeNAS8 ISCSI target & initiator for linux/windows
查看>>
cvs文件提交冲突解决方案
查看>>
PostgreSQL数据库集群初始化
查看>>
++重载
查看>>
Rainbond 5.0.4版本发布-做最好用的云应用操作系统
查看>>
nodejs 完成mqtt服务端
查看>>
在ASP.NET MVC 中获取当前URL、controller、action
查看>>
Spring IoC容器初的初始化过程
查看>>
sql server 触发器
查看>>
[工具]前端自动化工具grunt+bower+yoman
查看>>
2-14
查看>>
自动化测试之WatiN(2)
查看>>