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. 在开发第一个Android应用之前需要知道的5件事:

    你能否详细讲述一下,在开发Android应用过程中每一阶段要用到的技能和编程语言? 建立一个Android应用程序可以归结为两个主要技能/语言:Java和Android系统.Java是Android的 ...

  2. github入门之更改提交操作--6

    1.回溯历史版本 1.1.回溯到创建feature-A分支前 1.1.1.要让仓库的HEAD.暂存区.当前工作树回溯到指定状态,需要用到提供目标时间点的哈希值 1.1.2.回溯至未创建feature- ...

  3. JAVA加密解密DES对称加密算法

    下面用DES对称加密算法(设定一个密钥,然后对所有的数据进行加密)来简单举个例子. 首先,生成一个密钥KEY. 我把它保存到key.txt中.这个文件就象是一把钥匙.谁拥有它,谁就能解开我们的类文件. ...

  4. python基础教程总结8——特殊方法,属性,迭代器,生成器,八皇后问题

    1. 重写一般方法和特殊的构造方法 1.1 如果一个方法在B类的一个实例中被调用(或一个属性被访问),但在B类中没有找到该方法,那么会去它的超类A里面找. class A: ... def hello ...

  5. 【UML】部署图Deployment diagram(实现图)(转)

    http://blog.csdn.net/sds15732622190/article/details/49049665 前言 下面要介绍UML中的部署图,和构件图一样,它也属于实现图的一种,五种静态 ...

  6. CF Gym 100463A (树状数组求逆序数)

    题意:给你一个序列,和标准序列连线,求交点数. 题解:就是求逆序对个数,用树状数组优化就行了.具体过程就是按照顺序往树状数组了插点(根据点的大小),因为第i大的点应该排在第i位,插进去的时候他前面本该 ...

  7. [论文理解]Region-Based Convolutional Networks for Accurate Object Detection and Segmentation

    Region-Based Convolutional Networks for Accurate Object Detection and Segmentation 概括 这是一篇2016年的目标检测 ...

  8. 如何在vue项目中引用Iview

    iview 安装 npm install iview --save 引入iview import Vue from 'vue' import App from './App' import route ...

  9. 《effective c++》问题总结

    04 确定对象被使用前已先被初始化 1.static/heap/stack对象 2.trivial对象 3.模板隐式具现化 implicit template instantiations 4.Sin ...

  10. CF-1143D. The Beatles

    题意:有间隔为k的n个点在数轴上,下标为 \(1,k+1, 2*k+1,\cdots (n-1)*k+1\) 首尾相接.设起点为s,步长为L,而现在只知道s距离最近的点的距离为a,和(s+L)距离最近 ...