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\),并 ...
随机推荐
- [ros]编译ORBSLAM2时候,ros路径问题
CMake Error at CMakeLists.txt:2 (include): include could not find load file: /core/rosbuild/rosbuild ...
- SharePoint 2016 如何修改Library 地址
Scenario #1 如何为一个Library 修改下访问 网络路径地址 1.点击library,点开open with explorer,使用Windows资源管理器打开文档库 2.在文件夹层次结 ...
- (转载)WPF:DataGrid设置行、单元格的前景色
WPF:DataGrid设置行.单元格的前景色 0. 说明 /********************************** 本示例实现功能1.DataGrid基本操作2.列标题样式3.内容居中 ...
- 在Ubuntu12.04中搭建NFS的步骤
1.首先安装nfs-kernel-server apt-get install nfs-kernel-server 2.然后创建一个目录: mkdir -p /opt/share 并赋予权限777: ...
- 多目标检测分类 RCNN到Mask R-CNN
最近做目标检测需要用到Mask R-CNN,之前研究过CNN,R-CNN:通过论文的阅读以及下边三篇博客大概弄懂了Mask R-CNN神经网络.想要改进还得努力啊... 目标检测的经典网络结构,顺序大 ...
- python_103_属性方法例子
class Flight(object): def __init__(self,name): self.flight_name = name def checking_status(self): pr ...
- 在无TNS配置时,登录到数据库。
sqlplus user/pw@ip:port/servicename sqlplus user/pwd@tnsname sqlplus user/pwd---aix sqlplus /nolog&g ...
- Linux运维笔记--第二部
第2部-重要目录结构详解 1.回顾Linux目录结构知识 /dev/ 设备目录 /etc/ 系统配置及服务配置文件,启动命令的目录 /proc ...
- iOS应用架构谈part4-本地持久化方案及动态部署
前言 嗯,你们要的大招.跟着这篇文章一起也发布了CTPersistance和CTJSBridge这两个库,希望大家在实际使用的时候如果遇到问题,就给我提issue或者PR或者评论区.每一个issue和 ...
- 【转】EM算法原理
EM是我一直想深入学习的算法之一,第一次听说是在NLP课中的HMM那一节,为了解决HMM的参数估计问题,使用了EM算法.在之后的MT中的词对齐中也用到了.在Mitchell的书中也提到EM可以用于贝叶 ...