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

附上网址: http://acm.hust.edu.cn/vjudge/contest/view.action?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
#include
int main(){
	char a[1111];
	int len,i,j,k;
	gets(a);
	len=strlen(a);
	int map[33]={0};
	for(i=0;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 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
aaba
2
output
6
input
aaabbbb
2
output
6
input
abracadabra
10
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.


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

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

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

接下来就是附上代码:

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

那k位是任意添加的!

#include
#include
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=1;i--){
		int num=0;
		//注意这里的j循环到len-i才可以; 
		for(j=0;jmax1) 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 bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.

Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.

But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100or wi = 200), where wi is the weight of the i-th apple.

Output

In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).

Sample test(s)
input
3
100 200 100
output
YES
input
4
100 100 100 200
output
NO
Note

In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.


这道题可以算是一道想法题或是暴力模拟题吧。两种方法都可以做。

题意是:a买了n个苹果,然后苹果的重量只有100与200这两种,然后他要把这n个苹果平均分给2个人,苹果不能被切开,问能不能完成这个任务。

一法:当时比赛时有点急,就直接暴力做了。

#include
#include
int w[111]={0};
int main(){
	int n,i,j,k;
	while(~scanf("%d",&n)){
		int sum=0,t1=0,t2=0;
		memset(w,0,sizeof(w));
		for(i=1;i<=n;i++)  {
			scanf("%d",&w[i]); sum+=w[i];
			if(w[i]==100) t1++;
			if(w[i]==200) t2++;
		}	
		int t=0,flag=0;
		for(i=0;i<=t1;i++){
			t=0;
			for(j=0;j<=t2;j++){
				t=100*i+200*j;
				if((sum-t)==t) {flag=1; break;}
			}
			if(flag) break;
		}
		if(flag) puts("YES");
		else puts("NO");
	}
}
枚举了两种重量的个数,然后去for两遍判断,就相当与是硬币找钱问题。




#include
#include
int main()
{
	int n,j,i,m,sum,t1,t2,c;
	while(scanf("%d",&n)!=EOF)
	{
		sum=0;
		t1=t2=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&c);
			sum=sum+c;
			if(c==100)
			t1++;
			else t2++;
		}
		if((sum/2)%100!=0)
		printf("NO\n");
		else 
		{
			if(t2%2==0)
			printf("YES\n");
			else if(t2%2==1)
			{
				if(t1>=2)
				printf("YES\n");
				else printf("NO\n");
			}
		}
	}
}

算是想法吧。


B. Kuriyama Mirai's Stones
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

  1. She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .
  2. Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .

For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

Input

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.

The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers typel and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.

Output

Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

Sample test(s)
input
6
6 4 2 7 2 7
3
2 3 6
1 3 4
1 1 6
output
24
9
28
input
4
5 5 2 3
10
1 2 4
2 1 4
1 1 1
2 1 4
2 1 2
1 1 1
1 3 3
1 1 3
1 4 4
1 2 2
output
10
15
5
15
5
5
2
12
3
5
Note

Please note that the answers to the questions may overflow 32-bit integer type.


乍一看很简单,但是不优化一下的话会TLE的,于是我就想到了前缀和(这个名词是赛后才知道的。。)就是把前n个的和分别保存在一个数组中。

#include
#include
__int64 v[111111]={0},u[111111]={0},sum1[111111]={0},sum2[111111]={0};
void quicksort(int left,int right){
	int i,j,t,temp;
	if(left>right) return;
	temp=u[left];
	i=left;
	j=right;
	while(i!=j){
		while(u[j]>=temp && i

1320: Scoop water

Time Limit: 2 Sec   Memory Limit: 128 MB
Submit: 530   Solved: 142
[ Submit][ Status][ Web Board]

Description

  zzy今天刚买了两个水瓢A和B,容量都是为1升,童心未泯的他打算用这个水瓢来玩游戏。

  首先zzy准备了一个容量可看作无穷大的水缸,刚开始水缸是空的,然后用水瓢A往水缸里加水,用水瓢B把水缸里的水舀出去,当使用 水瓢B把水舀出去时水缸里必须要至少有1升的水。这样子使用N次水瓢A,也使用N次水瓢B,最后水缸会依旧空的。

Input

  输入有多个例子,直到文件结束。

  每个例子仅含一个数N(0

Output

  对于每个例子,请输出一个数,表示一共有多少种正确的舀水方式使得舀水过程中 使用B水瓢时水缸里总会有足够的水。

 (由于数字比较大,输出的答案模1000000007)

Sample Input

1
2

Sample Output

1

这道题我感觉与以前的杭电oj的那个下沙的沙子有多少粒很相似,于是我就试着用dp写了下,结果MLE。

#include
#include
#define mod 1000000007
long long dp[11111][11111];
int main(){
	int n,i,j,k;
	while(~scanf("%d",&n)){
		memset(dp,0,sizeof(dp));
		dp[1][1]=1;
		dp[1][0]=1;
		dp[0][1]=0;
		for(i=1;i<=n;i++) dp[i][0]=1;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if(i
思路是对的,但是我觉得有可能是因为重复计算了导致内存超出限制,而且这回的数字过大了,不像上次只有20个,那就可以过了。

但是有人说可以从这些答案中找到规律,是一个叫卡特兰数的数列。

#include
#include
#define mod 1000000007
int main(){
	int i,j,k;
	int n;
	long long f[11111]={0};
	f[0]=1;  f[1]=1;
	for(i=2;i<=10000;i++){
		for(j=1;j<=i;j++){
			f[i]+=(f[j-1]*f[i-j])%mod;
		}
		f[i]=f[i]%mod;
	}
	while(~scanf("%d",&n)){
		f[n]=f[n]%mod;
		printf("%lld\n",f[n]);
	}
}
然后就AC了,这里附一个卡特兰数列的链接:http://baike.baidu.com/link?url=Bk56cbvgnvwTXrBrqDPJqqB9s2Jd-WxdK1iBi7Iob2jqFqxOqFE_0yuh10R8fxzhLmXL3TKXW1R2b8lyf4SZgq




1318: Small change

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 360   Solved: 213
[ Submit][ Status][ Web Board]

Description

打完网赛,就到了晚饭的时间,但CSU_ACM的同学们都已经没力气出去了,这时CX建议大伙一起点餐吧,因为正是饭点,CX为了不让大家等太久,找了一个承诺20分钟送到超时要打折的外卖。但CX的RP都在网赛上用光了,果然送餐的迟到了,按规定咱们是要少给钱的。可是那些送餐员十分的狡猾,他们没有带零钱,于是乎,原价为N元的饭,由于他们的迟到可能需要降价,这些狡猾的送餐员会随机报一个数∈(1,N),如果CSU_ACM的小基友没有恰好这么多钱的话,送餐员还是按原价收取饭钱。为了CSU_ACM的最大利益,想知道最少由多少张钞票可以应对送餐员的任意要求(每张钞票的价值可为任意正整数),不论送餐员报的数字为多少总能给出相应的零钱。

Input

多组数据(不超过20组),输入到文件结束。

输入为CSU_ACM的小基友们点餐的总价N.(1<=N<=100000)

Output

输出为CSU_ACM的小基友们准备的零钱的最少张数。每个测试数据一行。

Sample Input

1
2
5

Sample Output

1
2
这道题是有规律的,多列几个就能发现了,就是类似于等比数列的东西。

#include
#include
#include
int main(){
	int n,i,j;
	int num;
	while(~scanf("%d",&n)){
		num=0;
		for(i=1; ;i++){
			if(n<=pow(2,i)-1)  break;
		}
		num=i;
		printf("%d\n",num);
	}
}



感觉自己真的在不停地进步,哈哈,加油,哈迪斯!

你可能感兴趣的:(模拟题)