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\),并 ...
随机推荐
- document.all.item作用
1.document.all.myCheckBox和 document.all.item通过控件的名字定位控件,item()中是控件的名字例如:<input type="checkbo ...
- C#语言基础 Main 函数中的输出输入
C# 是一门面向对象的编程语言,保留了C C++等等强大功能,但是它与 Java 非常相似,有许多强大的编程功能,它是微软(Microsoft)专门为.NET应用而开发的一门语言. 也就是人与计算机 ...
- python 之网页解析器
一.什么是网页解析器 1.网页解析器名词解释 首先让我们来了解下,什么是网页解析器,简单的说就是用来解析html网页的工具,准确的说:它是一个HTML网页信息提取工具,就是从html网页中解析提取出“ ...
- python基础教程总结15——7 自定义电子公告板
1. Python进行SQLite数据库操作 简单的介绍 SQLite数据库是一款非常小巧的嵌入式开源数据库软件,也就是说没有独立的维护进程,所有的维护都来自于程序本身.它是遵守ACID的关联式数据库 ...
- javaweb基础(18)_jsp属性范围
所谓的属性范围就是一个属性设置之后,可以经过多少个其他页面后仍然可以访问的保存范围. 一.JSP属性范围 JSP中提供了四种属性范围,四种属性范围分别指以下四种: 当前页:一个属性只能在一个页面中取得 ...
- C#数组添加元素
一.向数组添加元素 在C#中,只能在动态数组ArrayList类中向数组添加元素.因为动态数组是一个可以改变数组长度和元素个数的数据类型. 示例: using System;using System. ...
- iOS跳转到各种系统设置界面
定位服务 定位服务有很多APP都有,如果用户关闭了定位,那么,我们在APP里面可以提示用户打开定位服务.点击到设置界面设置,直接跳到定位服务设置界面.代码如下: //定位服务设置界面 NSURL *u ...
- message() 信息提示
//样式部分 .message { position: fixed;top: -100px;width: 400px;left: 50%;margin-left: -200px;z-index: 10 ...
- 【转】BP神经网络
学习是神经网络一种最重要也最令人注目的特点.在神经网络的发展进程中,学习算法的研究有着十分重要的地位.目前,人们所提出的神经网络模型都是和学习算 法相应的.所以,有时人们并不去祈求对模型和算法进行严格 ...
- C语言输出多位小数
#include<stdio.h>#include<stdlib.h>int main(){int i=0;int m=19;int n=3;int s=0;s=m/n;pri ...