Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~
1 second
256 megabytes
standard input
standard output
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line.
The prefix of these line is "123456789101112131415...". Your task is to print the n-th
digit of this string (digits are numbered starting with 1.
The only line of the input contains a single integer n (1 ≤ n ≤ 1000) —
the position of the digit you need to print.
Print the n-th digit of the line.
- 3
- 3
- 11
- 0
In the first sample the digit at position 3 is '3',
as both integers 1 and 2 consist
on one digit.
In the second sample, the digit at position 11 is '0',
it belongs to the integer 10.
与其做BC还不如做CF,CF上的题真的是很好,虽然每次只能做两个。
这道题题意很简单,就是一连串的数字排列在一起,求第n位是几;其实一看这种题就知道是规律题,但奈何脑袋笨,只能用笨方法做,我们可以打表将这些位都存起来,数据范围不大,所以估算到400就足够有1000位了;
- #include<bits/stdc++.h>
- using namespace std;
- const int N=1000+10;
- int a[N];
- int main()
- {
- int n,i,j=1;
- for(i=1;i<550;i++)//其实到400就足够了;
- {
- int x=i;
- if(x<=9)
- a[j++]=x;
- else if(x<=99)//将两位数拆开存起来,下面同理;
- {
- int x1=x%10,x2=x/10;
- a[j++]=x2,a[j++]=x1;
- }
- else
- {
- int x1=x%10,x2=(x%100)/10,x3=x/100;
- a[j++]=x3,a[j++]=x2,a[j++]=x1;
- }
- if(j>=N) break;//N应该稍微开大一点,我在开始定义1000结果贡献了一个WA;
- }
- while(~scanf("%d",&n))
- {
- printf("%d\n",a[n]);
- }
- return 0;
- }
其实考的就是思路,思路清晰代码能力可以这题就没什么问题了;
2 seconds
256 megabytes
standard input
standard output
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants allsubstrings of
his string s to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string
"aba" has substrings "" (empty substring), "a",
"b", "a", "ab",
"ba", "aba".
If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters.
Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) —
the length of the string s.
The second line contains the string s of length n consisting
of only lowercase English letters.
If it's impossible to change the string s such that all its substring are distinct print -1.
Otherwise print the minimum required number of changes.
- 2
- aa
- 1
- 4
- koko
- 2
- 5
- murat
- 0
In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b',
so the string becomes "abko".
第一次看见B题这么水,哈哈,还没A题麻烦;
题意:给你一个长度为n的字符串,在其所有的子集中如果至少有两个相同的则要替换某个字母,其实单个字母就是一个子集,所以只要这个字符串中有多少个相同的就得替换多少个字母,但是,我们知道,超过26个字母无论怎么替换都有相同的,所以只要长度大于26则应该输出-1,反之求出重复字母个数输出;
至于怎么求出不同字母个数嘛;介绍一个简单函数unique(),这个我在文章分类中的知识点中已经给出了具体用法,下面来看超简洁代码:
- #include<bits/stdc++.h>
- using namespace std;
- const int N=100000+10;
- char a[N];
- int main()
- {
- int n;
- while(~scanf("%d",&n))
- {
- scanf("%s",a);
- sort(a,a+n);
- int x=unique(a,a+n)-a;
- if(n>26)
- printf("-1\n");
- else
- printf("%d\n",n-x);//输出重复的个数;
- }
- return 0;
- }
目前能力只能水前两个题,请见谅;
Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~的更多相关文章
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #303 (Div. 2) D. Queue 傻逼题
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #352 (Div. 1) B. Robin Hood
B. Robin Hood 讲道理:这种题我是绝对不去(敢)碰的.比赛时被这个题坑了一把,对于我这种不A不罢休的人来说就算看题解也要得到一个Accepted. 这题网上有很多题解,我自己是很难做出来的 ...
- Codeforces Round #352 (Div. 2) B. Different is Good 水题
B. Different is Good 题目连接: http://www.codeforces.com/contest/672/problem/B Description A wise man to ...
- Codeforces Round #352 (Div. 2) A. Summer Camp 水题
A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心
题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...
- Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题
A. Case of the Zeros and Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- Codeforces Round #352 (Div. 2) D. Robin Hood
题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...
随机推荐
- [ZPG TEST 118] 最大值【dp+离线】
题4 最大值(findmax) [题目描述] 找到一个数组的最大值的一种方法是从数组开头从前到后对数组进行扫描,令max=a[0](数组下表从0..N-1),如果a[i]>max,就更新max ...
- 修改SolrCloud在ZooKeeper中的配置文件操作记录
修改SolrCloud在ZooKeeper中的配置文件操作记录. 命令执行目录: /opt/solr-/server/scripts/cloud-scripts/ 1.下载配置文件 ./zkcli., ...
- Android偏好设置(2)为应用定义一个偏好设置xml
1.Defining Preferences in XML Although you can instantiate new Preference objects at runtime, you sh ...
- 数据流和ByteArray
问题:如何把一个long类型的数写进一个文件里 所以现在有DataInputStream和DataOutputStream 这两个是节点流 例子代码: import java.io.*; public ...
- HBase简介(很好的梳理资料) 转
一. 简介 history started by chad walters and jim 2006.11 G release paper on BigTable 2007.2 inital HBas ...
- A8通用权限框架
- linux小白成长之路11————linux命令大全
1. 启动,关机,登入,登出相关命令 登录:login 登出:logout 登出:exit 停止系统:shutdown 停止系统:halt 重启动:reboot 切断电源:poweroff 把内存里的 ...
- vim插件minibuf配置
1.去下载网站下载minibufexpl.vim文件放入到~/vim/plugins中,有的系统路径是~/.vim/plugins; 下载网址如下 https://www.vim.org/script ...
- HTML a标签的href 属性 tel 点击可以直接拨打电话 ( 移动端 )
<a href="tel:13828172679">13622178579</a>
- CE工具里自带的学习工具--第二关
图解: