A. Summer Camp
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The only line of the input contains a single integer n (1 ≤ n ≤ 1000) —
the position of the digit you need to print.

Output

Print the n-th digit of the line.

Examples
input
3
output
3
input
11
output
0
Note

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;
}

其实考的就是思路,思路清晰代码能力可以这题就没什么问题了;

B. Different is Good
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input
2
aa
output
1
input
4
koko
output
2
input
5
murat
output
0
Note

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题题解代码,水过~~的更多相关文章

  1. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

  2. Codeforces Round #303 (Div. 2) D. Queue 傻逼题

    C. Woodcutters Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...

  3. Codeforces Round #352 (Div. 1) B. Robin Hood

    B. Robin Hood 讲道理:这种题我是绝对不去(敢)碰的.比赛时被这个题坑了一把,对于我这种不A不罢休的人来说就算看题解也要得到一个Accepted. 这题网上有很多题解,我自己是很难做出来的 ...

  4. 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 ...

  5. Codeforces Round #352 (Div. 2) A. Summer Camp 水题

    A. Summer Camp 题目连接: http://www.codeforces.com/contest/672/problem/A Description Every year, hundred ...

  6. Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分

    D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...

  7. Codeforces Round #352 (Div. 2) C. Recycling Bottles 暴力+贪心

    题目链接: http://codeforces.com/contest/672/problem/C 题意: 公园里有两个人一个垃圾桶和n个瓶子,现在这两个人需要把所有的瓶子扔进垃圾桶,给出人,垃圾桶, ...

  8. 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 ...

  9. Codeforces Round #352 (Div. 2) D. Robin Hood

    题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...

随机推荐

  1. Oracle代码 规则 创建表 表空间 用户等

    -----创建表空间----------create tablespace bdccslogging datafile 'D:\oracle\product\10.2.0\oradata\bdccs\ ...

  2. overlaps the location of another project Zendstudio导入已经存在的目录

    转 http://blog.csdn.net/kdchxue/article/details/50633745 最近弄zendstuido导入已经存在的项目,找了很多地方终于找到了导入的方法,特别记录 ...

  3. E. Dasha and Puzzle 数学题

    http://codeforces.com/contest/761/problem/E 给出一颗树,要求在坐标系中用平行于坐标轴的线描绘出来. 要求边不能相交,而且点的坐标唯一. 注意到2^1 + 2 ...

  4. CSS ul li a 背景图片与文字对齐

    <div class="four"> <h2>电子商务</h2> <img src="images/photo2.gif&quo ...

  5. JS中的Promise

    Promise 对象有以下两个特点. (1)对象的状态不受外界影响.Promise 对象代表一个异步操作,有三种状态:Pending(进行中).Resolved(已完成,又称 Fulfilled)和 ...

  6. [Android]Android Design之Navigation Drawer

    概述 在以前ActionBar是Android 4.0的独有的,后来的ActionBarSherlock的独步武林,对了还有SlidingMenu,但是这个可以对4.0下的可以做很好的适配.自从Goo ...

  7. 洛谷 P1615 西游记公司

    题目背景 一道极其无厘头的题目 题目描述 事情是这样的:西游记中的孙沙猪(孙杀猪)三徒弟在西天取经之后开始进入厦门大学经贸系学习经济,在1个小时的学习后,他们用暴力手段毕业了.然后,他们创办了三个公司 ...

  8. windows下管理ubuntu服务器以及切换root身份

    远程连接Linux云服务器-命令行模式 1.远程连接工具.目前Linux远程连接工具有很多种,您可以选择顺手的工具使用.下面使用的是名为Putty(putty.rar)的Linux远程连接工具.该工具 ...

  9. iTOP-6818开发板-Android4.4系统下RFID射频模块测试例程

    平台:迅为iTOP-6818开发板 系统:Android4.4版本 例程:RFID射频模块测试例程 rc522 驱动在 Android 系统的内核是默认集成的,用户可以在开发板上使用命令“ls /de ...

  10. js 作用域 ?????

    ///*第一种情况 */ //var mycars = new Array() //mycars[0] = 0; //mycars[1] = 1; //mycars[2] = 2; //functio ...