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

有没有大牛给解释一下啊??

Posted by Sempr at 2006-02-25 23:03:01 on Problem 2366
In Reply To:全部输入后再一个个检查就WA,一边输入一边检查等到找到合适的数据就退出程序的就AC Posted by:oeym at 2006-02-25 23:01:32
> WA的程序:
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> int cmp(const void *a, const void *b)
> {
> 	return *(int *)a - *(int *)b;
> }
> 
> int main()
> {
> 	
> 	int a[50000], b[50000], la, lb, i, j, tmp, *p;
> 
> 	scanf("%d", &la);
> 
> 	for (i = 0; i < la; i++)
> 	{
> 		scanf("%d", &a[i]);
> 	}
> 
> 	scanf("%d", &lb);
> 
> 	for (i = 0; i < lb; i++)
> 	{
> 		scanf("%d", &b[i]);
> 	}
> 
> 	qsort(a, la, sizeof(a[0]), cmp);
> 		
> 	for (i = 0; i < lb; i++)
> 	{
> 		tmp = 10000 - b[i];
> 		p = (int *) bsearch(&tmp, a, la, sizeof(a[0]), cmp);
> 		if (p != NULL)
> 		{
> 			printf("YES\n");
> 			break;
> 		}
> 	}
> 	if (i == lb)
> 	{
> 		printf("NO\n");
> 	}
> 	return 0;
> }
> 
> AC的程序:
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> int cmp(const void *a, const void *b)
> {
> 	return *(int *)a - *(int *)b;
> }
> 
> int main()
> {
> 	
> 	int a[50000], bi, la, lb, i, j, tmp, *p;
> 
> 	scanf("%d", &la);
> 
> 	for (i = 0; i < la; i++)
> 	{
> 		scanf("%d", &a[i]);
> 	}
> 
> 	scanf("%d", &lb);
> 
> 	for (i = 0; i < lb; i++)
> 	{
> 		scanf("%d", &bi);
> 		tmp = 10000 - bi;
> 		p = (int *) bsearch(&tmp, a, la, sizeof(a[0]), cmp);
> 		if (p != NULL)
> 		{
> 			printf("YES\n");
> 			return 0;
> 		}
> 	}
> 
> 	printf("NO\n");
> 	return 0;
> }
> 
> 

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