ZJNU 省赛集训 清明节快乐~~

附上网址:?cid=73892#problem/A

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

就是一道水题,让你求某一个集合中有几个不相同的字符。不过呢,水题中也可以学到一些代码的写法,一开始我是for两遍,然后用了一个book数组来标记,数据量小的话还好,但是一旦大了就会TLE。

#include<stdio.h>#include<string.h>int main(){char a[1111];int len,i,j,k;gets(a);len=strlen(a);int map[33]={0};for(i=0;i<len;i++){//用这种标记方法就会方便多了。 if(a[i]>='a'&&a[i]<='z') map[a[i]-'a'+1]++;}int num=0;for(i=1;i<=26;i++) if(map[i]) num++;printf("%d\n",num);}

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 stringsfor his birthday, the string consists of small English letters. He immediately addedkmore characters to the right of the string.

Then Borya came and said that the new string contained atandem repeatof lengthlas a substring. How large couldlbe?

See notes for definition of atandem repeat.

Input

The first line containss(1≤|s|≤200). This string contains only small English letters. The second line contains numberk(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 length2nis strings, where for any positioni(1≤i≤n) the following condition fulfills:si=si+n.

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

读错题意,,还以为添加到后面的字符是从前面来的。还在那边不停的模拟,WA~

题目的意思是给你一个串和一个数字k,然后你可以再串的最右边添加k个任意的字符,目的是为了能得到最长的重复字串。注意这里只能重复2次,“A tandem repeat of length2nis strings”。

所以我们就知道最大的重复长度(这里我们把它叫做周期)肯定是len+k然后再除以2,然后每次对于一种周期,从第一位开始for一遍直到 len-i ,这里的末位置要注意一下。

接下来就是附上代码:

有些代码中讨论了当 k>=len的时候,那么最长的肯定就是len 了,但是这里我没有讨论,因为情况已经被包含在里面了。

那k位是任意添加的!

#include<stdio.h>#include<string.h>int main(){char s[2222];int len,len1,tmax,i,j,k;scanf("%s",s);scanf("%d",&k);len=strlen(s)+k;len1=len/2;for(i=strlen(s);i<len;i++) s[i]='#';s[i]='\0';//这里的i代表的是对周期的循环; int max1=-1;//其实我下面所写的已经包含了当k大于s这个字符串长度的情况; for(i=len1;i>=1;i–){int num=0;//注意这里的j循环到len-i才可以; for(j=0;j<len-i;j++){if(num==i) break;if(s[j]!='#'&&s[j]==s[j+i]) {num++; continue;}else if(s[j]!='#'&&s[j+i]=='#') {num++; continue;}else if(s[j]=='#'&&s[j+i]=='#') {num++; continue;}else {num=0; continue;}}if(num==i){if(i>max1) max1=i;}}printf("%d\n",max1*2);}以后读题还是要仔细一点,说不定想想就能写出来了。

A. Kitahara Haruki’s Gift

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Kitahara Haruki has boughtnapples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.

莫找借口失败,只找理由成功。(不为失败找理由,要为成功找方法)

ZJNU 省赛集训 清明节快乐~~

相关文章:

你感兴趣的文章:

标签云: