2018-BNUZ-ACM-GDCPC选拔赛 【补题】

第一次GDCPC选拔,说不想去是不可能的,中午回来就赶紧休息,下午又早早的来到教室,可是还是自己的问题吧,又是卡题,就是一点思路都没有,就想着暴力,结果过不去各种wa还有tle,第一次出校打比赛的机会就没了,唉,真的不知道自己到底是怎么了,就是感觉越学越菜,然后那种肯定能过的水题,就是死活卡在那里,是该加强数学训练?还是读题方式?还是思考方式?大概还是基础不扎实吧,感觉和协会里的人不知不觉中差了好多题没写,然后就慢慢拉开差距了,导致这种题老过不去,今天以后尝试每天或每几天刷刷cf的题吧,多加练习,还有以前讲的,真的没了模板就不会用了。也该好好复习了。

A. Mahmoud and Longest Uncommon Subsequence

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.

Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.

A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.

Input

The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.

Output

If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.

Examples
Input
Copy
abcd
defgh
Output
Copy
5
Input
Copy
a
a
Output
Copy
-1
Note

In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.

这个题着实把我坑了一把,读题读出来是找最长不同子序列,然后wa了几发后,在读样例感觉并不是,结果开始各种尝试,最后也没过,后来才明白这个题就是如果两个字符串不同,就输出最长的字符串长度,如果相同,就输出-1,真的想吐血,被这种水题卡真的难受的要死。

#include<bits/stdc++.h>
using namespace std;
int main() {
	int t,alen,blen,j =0,num;
	char a[100005],b[100005];
	scanf("%s",&a);
	getchar();
	scanf("%s",&b);
	alen = strlen(a);
	blen = strlen(b);
	for(int i = 0; i < alen; i++) {
		if(a[i] != b[i]) {
			j = 1;
		}
	}
	for(int i = 0; i < blen; i++) {
		if(a[i] != b[i]) {
			j = 1;
		}
	}
	if(j) {
		if(alen > blen) {
			printf("%d\n",alen);
		} else {
			printf("%d\n",blen);
		}
	} else {
		printf("%d\n",-1);
	}

}

B. Mahmoud and a Triangle

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.

Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.

Input

The first line contains single integer n (3 ≤ n ≤ 105) — the number of line segments Mahmoud has.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the lengths of line segments Mahmoud has.

Output

In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.

Examples
Input
Copy
5
1 5 3 2 4
Output
Copy
YES
Input
Copy
3
4 1 2
Output
Copy
NO
Note

For the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.

然后是这个题,给你一堆边,从中选三个能否组成三角形,能就是yes,否则是no,这个一看就是水题,上来第一道就尝试这个,结果脑袋就不转了,就想着暴力暴力,三个for怎么想都是tle,然后又想复杂了,想着先排序,然后第一个第二个相加,在二分查找找到比他们大的值,然后再判断是否三角形,这样更写不出来。。真的不知道怎么了,反正脑子就是一片空白,除了暴力,什么都想不到,然后优化又没有想法,最后无奈放弃。。结束看了题解后才发现根本没有那么复杂,甚至都不用挨个判断两边之和大于第三边,直接排序然后遍历用两个小的边相加大于最大边就有符合条件的直接yes,否则就no,真的没有那么麻烦,但是自己就是死活想不到,怀疑自己需要学习小学数学了,唉,继续努力,下次再有机会,一定不能错过。

#include<bits/stdc++.h>
using namespace std;
int main() {
	int t,ans,n,num[100005],p,l;
	p = 0;
	l = 1;
	scanf("%d",&t);
	for(int i = 0; i < t; i++) {
		scanf("%d",&num[i]);
	}
	sort(num,num+t);
	for(int i =0; i < t-2;i++){
		if(num[i]  + num[i+1] >num[i+2]){
			p = 1;
		}
	}
	if(p){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
}



阅读更多
个人分类: 训练赛
上一篇[2018-4-8]BNUZ套题比赛div2 【补题】
下一篇[2018-4-20]BNUZ套题比赛div2 【补题】
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭