Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
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: