Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:1A, 提供一个相似的思路吧

Posted by yjyongz at 2012-04-17 12:24:27 on Problem 1029
In Reply To:1A, 提供一个相似的思路吧 Posted by:popzkk at 2012-03-12 10:33:24
> 首先明确 数据中放在天平两端的硬币没有交集, 就是不会有 1 2 < 2 3 这种情况
> 然后弄两个数组, less和more, 记录硬币i出现在轻端和重端的次数.
> 
> 1. 对于等式两边的硬币, 不可能为假
> 2. 对于轻端和重端都出现过的硬币, 显然不可能为假
> 3. 对于轻端和重端出现次数不足K(K是不等式总数)的, 也可不能为假.
> 
> 排除上述3种情况后, 如果只有一枚硬币还没确定, 那就是答案, 如果有多枚硬币没确定, 那就输出0.
> 
> #include <cstdio>
> #include <cstring>
> 
> int less[1010], more[1010];
> bool isTrue[1010];
> int p[510], q[510];
> int Ans[1010];
> 
> int main()
> {
> 	int N, M;
> 	scanf("%d%d", &N, &M);
> 	memset(isTrue, false, sizeof(isTrue));
> 	memset(less, 0, sizeof(less));
> 	memset(more, 0, sizeof(more));
> 	int K = 0;
> 	for (int i = 1; i <= M; ++ i)
> 	{
> 		int x;
> 		scanf("%d", &x);
> 		for (int j = 1; j <= x; ++ j)
> 			scanf("%d", &p[j]);
> 		for (int j = 1; j <= x; ++ j)
> 			scanf("%d", &q[j]);
> 		char str[10];
> 		scanf("%s", str);
> 		switch (str[0])
> 		{
> 			case '=' :
> 				for (int j = 1; j <= x; ++ j)
> 					isTrue[p[j]] = isTrue[q[j]] = true;
> 				break;
> 			case '<' :
> 				++ K;
> 				for (int j = 1; j <= x; ++ j)
> 					++ less[p[j]], ++ more[q[j]];
> 				break;
> 			case '>' :
> 				++ K;
> 				for (int j = 1; j <= x; ++ j)
> 					++ more[p[j]], ++ less[q[j]];
> 				break;
> 		}
> 	}
> 	for (int i = 1; i <= N; ++ i)
> 		if (less[i] + more[i] < K || (less[i] && more[i]))
> 			isTrue[i] = true;
> 	int tot = 0;
> 	for (int i = 1; i <= N; ++ i)
> 		if (! isTrue[i])
> 			Ans[++ tot] = i;
> 	printf("%d\n", tot == 1 ? Ans[1] : 0);
> 	return 0;
> }
思路牛逼啊。。 但是还有一个排除的方法 就是没出现在不等式的item也是真的。。。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator