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:帮帮我看看

Posted by ync at 2004-10-26 19:11:16 on Problem 1944
In Reply To:帮帮!!!!!!!!!!!!!!!!!!! Posted by:ync at 2004-10-26 19:07:29
#include<stdio.h>
#include<string.h>
int main()
{
	int line,k1,k2,P,N,temp,i,a,b;
	while(scanf("%d%d",&N,&P)!=EOF)
	{
		line=0;
		for(i=1;i<=P;i++)
		{
			scanf("%d%d",&a,&b);
			if(a<b) { temp=a; a=b; b=temp;}
			k1=a-b; 
			k2=b+N-a;
			if(k1>k2) k1=k2;
			line+=k1;
		}
		printf("%d\n",line);

	}//while

	return 0;
}
/*
Sample Input 


5 2
1 3
4 5


Sample Output 


3

*/#include<stdio.h>
#include<string.h>
int main()
{
	int line,k1,k2,P,N,temp,i,a,b;
	while(scanf("%d%d",&N,&P)!=EOF)
	{
		line=0;
		for(i=1;i<=P;i++)
		{
			scanf("%d%d",&a,&b);
			if(a<b) { temp=a; a=b; b=temp;}
			k1=a-b; 
			k2=b+N-a;
			if(k1>k2) k1=k2;
			line+=k1;
		}
		printf("%d\n",line);

	}//while

	return 0;
}
/*
Sample Input 


5 2
1 3
4 5


Sample Output 


3

*/#include<stdio.h>
#include<string.h>
int main()
{
	int line,k1,k2,P,N,temp,i,a,b;
	while(scanf("%d%d",&N,&P)!=EOF)
	{
		line=0;
		for(i=1;i<=P;i++)
		{
			scanf("%d%d",&a,&b);
			if(a<b) { temp=a; a=b; b=temp;}
			k1=a-b; 
			k2=b+N-a;
			if(k1>k2) k1=k2;
			line+=k1;
		}
		printf("%d\n",line);

	}//while

	return 0;
}
/*
Sample Input 


5 2
1 3
4 5


Sample Output 


3

*/

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