Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:帮帮我看看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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator