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 147465758 at 2005-12-31 11:44:50 on Problem 2726
#include <stdio.h>
int Solve(int n)
{
	int i1=0;
	int list[10001];
	int temp_distance=0;
	int temp_cost=0;
	int sum_candidate=0;
	int min_cost=20000;
	for(i1=0;i1<10001;i1++)
		list[i1]=20000;
	for(i1=0;i1<n;i1++)
	{
		scanf("%d %d",&temp_distance,&temp_cost);
		if(list[temp_distance]>temp_cost)
			list[temp_distance]=temp_cost;
	}
	for(i1=0;i1<10001;i1++)
	{
		if(list[i1]<=10000 && list[i1]<min_cost)
		{
			min_cost=list[i1];
			sum_candidate++;
		}
	}
	return sum_candidate;
}
int main()
{
	int N=0;
	do
	{
		scanf("%d",&N);
		if(N>0)
			printf("%d\n",Solve(N));
	}while(N>0);
	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