Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~
来源:互联网 发布:武汉淘宝产品拍摄 编辑:程序博客网 时间:2024/06/06 13:47
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.
这道题题意很简单,就是一连串的数字排列在一起,求第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;}其实考的就是思路,思路清晰代码能力可以这题就没什么问题了;
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.
2aa
1
4koko
2
5murat
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".
题意:给你一个长度为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 #395 (Div. 2) A B题 题解
- Codeforces Round #344 (Div. 2) B 题题解 (暴力)
- Codeforces Round #241 (Div. 2) A B C题解
- Codeforces Round #292 (Div. 2) A,B,C,D 题解
- Codeforces Round #303 (Div. 2) A,B,D题解
- Codeforces Round #304 (Div. 2) A,B,C题解
- Codeforces Round #364 (Div. 2)(A,B,C,D) 题解
- Codeforces Round #377 (Div. 2)部分题解A+B+C!
- Codeforces Round #388 (Div. 2) A,B,C,D 题解
- Codeforces Round #395 (Div. 2) A,B,C,D 题解
- Codeforces Round #436 div 2 A B C D 题解
- Codeforces Round #451 (Div. 2) A-B 题解
- Codeforces Beta Round #34 (Div. 2) A题解题报告
- Codeforces Round #179 (Div. 2) A题解题报告
- Codeforces Round #188 (Div. 2) A题解题报告
- Codeforces Round #185 (Div. 2) A题解题报告
- Codeforces Round #344 (Div. 2) A 题题解 (暴力)
- 面试中的排序算法总结
- ARM FP寄存器及frame pointer介绍
- GoogleCloudMessage推送的使用二(正式使用走起)
- 仿微信开发(二)--系统语言设置
- MVC流程图
- Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~
- 【转载】SQL中declare申明变量 declare @id int
- android蓝牙4.0开发
- Swift网络请求,数据模型,图片缓存,自动布局,上拉刷新下拉加载
- Spring4+Hibernate4+Mybatis Maven的pom配置
- OpenGL学习脚印: 向量和矩阵要点(math-vector and matrices)
- BAT命令--FOR使用方法及举例
- Qml和C++开发的学生信息管理软件一
- iOS真机运行出现The certificate used to sign "APP名" has either expired or has been revoked.