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 <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≤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<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的更多相关文章

  1. Atcoder Grand Contest 022 E - Median Replace(dp)

    Atcoder 题面传送门 & 洛谷题面传送门 首先考虑对于固定的 01 串怎样计算它是否可以通过将三个连续的 \(0\) 或 \(1\) 替换为其中位数得到.我们考虑单调栈,新建一个栈,栈底 ...

  2. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  3. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  4. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  5. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  6. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

  7. AtCoder Grand Contest 008

    AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...

  8. AtCoder Grand Contest 007

    AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...

  9. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

随机推荐

  1. python+selenium之中类/函数/模块的简单介绍和方法调用

    # coding=utf-8 class ClassA (object): string1 = "这是一个字符串." def instancefunc(self): print ( ...

  2. WisdomTool REST Client 下载 测试请求,生成api文档

    https://github.com/Wisdom-Projects/rest-client

  3. (转载)Newtonsoft.Json使用总结

    Newtonsoft.Json使用总结 初识JSON.......................................................................... ...

  4. iOS Automated Tests with UIAutomation

    参照:http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation#1 UI Automation JavaScri ...

  5. 百度site网址显示完整站点信息的分析

    去年赛花红就发现百度site本博客网址,仅出现找到相关结果数约多少个,数字为估算值,网站管理员如需了解更准确的索引量,请使用百度站长平台等字样.但赛花红又发现有的网站却显示着完整的站点信息,当时以为是 ...

  6. FiraCode 字体 => 箭头函数变成 整体 还有 等于 不等于

    https://github.com/tonsky/FiraCode Enable in Settings → Editor → Color Scheme → Color Scheme Font →  ...

  7. 2018.5.7 androidStudio中:layout_gravity 与 gravity的属性的区别

    android:gravity:设置的是控件自身上面的内容位置 android:layout_gravity:设置控件本身相对于父控件的显示位置. 看下面 <LinearLayout xmlns ...

  8. a survey for RL

    • A finite set of states St summarizing the information the agent senses from the environment at eve ...

  9. PhoneGap+JQuery Mobile移动应用开发学习笔记

    最近一直在学习使用PhoneGap+JQuery Mobile的开发框架开发Android应用,抛开这个框架的运行效率不说,暂且将使用中遇到的问题进行一下整理. 1.JS文件引用顺序 也许在进行web ...

  10. Bootstrap历练实例:带列表组的面板

    带列表组的面板 我们可以在任何面板中包含列表组,通过在 <div> 元素中添加 .panel 和 .panel-default 类来创建面板,并在面板中添加列表组.您可以从 列表组 一章中 ...