博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #253 (Div. 2)
阅读量:6904 次
发布时间:2019-06-27

本文共 5034 字,大约阅读时间需要 16 分钟。

A. Anton and Letters
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.

Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.

Input

The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.

Output

Print a single number — the number of distinct letters in Anton's set.

Sample test(s)
input
{a, b, c}
output
3
input
{b, a, b, a}
output
2
input
{}
output
0

//15 ms	 0 KB#include
#include
char s[1007];int z[30];int main(){ gets(s); int len=strlen(s),count=0; memset(z,0,sizeof(z)); for(int i=0;i
='a'&&s[i]<='z') z[s[i]-'a'+1]++; } for(int i=1;i<=26;i++) if(z[i])count++; printf("%d\n",count);}

B. Kolya and Tandem Repeat
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?

See notes for definition of a tandem repeat.

Input

The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.

Output

Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.

Sample test(s)
input
aaba2
output
6
input
aaabbbb2
output
6
input
abracadabra10
output
20
Note

A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.

In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.

//15 ms	 0 KB#include
#include
char s[1007];int main(){ int n; scanf("%s",s); scanf("%d",&n); int len=strlen(s),maxlen=0; if(n>=len){printf("%d\n",(n+len)/2*2);return 0;}//假设加入的长度大于等于原串长度 for(int i=1;i
=0;i--)//枚举加入之后的最长长度 { int flag=0; for(int j=len-1,num=1;num<=(i-n);j--,num++) if(s[j]!=s[len-i-num]){flag=1;break;} if(!flag) { if(i>maxlen)printf("%d\n",i*2); else printf("%d\n",maxlen*2); break; } }}

D. Andrey and Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.

Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi(0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.

Output

Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.

Sample test(s)
input
40.1 0.2 0.3 0.8
output
0.800000000000
input
20.1 0.2
output
0.260000000000
Note

In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.

In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.

题意是说给你n个数,每一个数代表为1的概率是多少,让你从中选择一个或者多个数使其概率为1的最大。

将n个数从大到小排序,假设选择一个要使概率最大,则肯定选择第一个数。

假设选择两个使其概率最大,则肯定选择前两个数,选择三个。则选择前三个数,以此推类。

仅仅要求出前一个到前n个全部情况。然后取最大即是所求。

//31 ms	 0 KB#include
#include
using namespace std;double s[107];int cmp(double a,double b){return a>b;}int main(){ int n; double maxx=0; scanf("%d",&n); for(int i=0;i

转载地址:http://vhldl.baihongyu.com/

你可能感兴趣的文章
Bash 测试和比较函数
查看>>
【转】(译)iOS Code Signing: 解惑详解
查看>>
HTML5开发-在你的游戏应用中加入广告(转)
查看>>
10 个很有用的高级 Git 命令(转)
查看>>
粘包的处理
查看>>
在Visual Studio中使用层关系图描述系统架构、技术栈
查看>>
LightOJ 1428 Melody Comparison(后缀数组)
查看>>
java学习笔记-5 泛型
查看>>
Csharp windowform controls clear
查看>>
如何让ASP.NET默认的资源编程“.NET研究”方式支持非.ResX资源存储
查看>>
c#修改系统时间的方法
查看>>
R安装package报ERROR: a 'NAMESPACE' file is required
查看>>
关于main()函数的小技巧
查看>>
phpnow配置
查看>>
使用mailx发送邮件
查看>>
Webbrowser中模拟连接点击(非鼠标模拟)
查看>>
HDU 1049 Climbing Worm(水题)
查看>>
类 不包含 方法的定义
查看>>
Servlet与JSP有什么区别?
查看>>
OK335xS psplash Screen 移植
查看>>