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 |
一直WA,无语……为什么???#include<iostream> using namespace std; #define M 100001 struct IN { int x,y; }node[M]; int cmpx(const void *a,const void *b) { if((*(IN *)a).x == (*(IN *)b).x) return (*(IN *)a).y - (*(IN *)b).y; else return (*(IN *)a).x - (*(IN *)b).x; } int cmpy(const void *a,const void *b) { if((*(IN *)a).y == (*(IN *)b).y) return (*(IN *)a).x - (*(IN *)b).x; else return (*(IN *)a).y - (*(IN *)b).y; } int main() { int i,j; int p,sum; while(scanf("%d",&p) && p!=0) { for(i=0; i<p; i++) { scanf("%d%d",&node[i].x,&node[i].y); } qsort(node,p,sizeof(node[0]),cmpx); sum = 0; for(i=0; i<p; i++) { if(i%2) sum += node[i].y; else sum -= node[i].y; } qsort(node,p,sizeof(node[0]),cmpy); for(i=0; i<p; i++) { if(i%2) sum += node[i].x; else sum -= node[i].x; } printf("Then thength of the fence will be %d units.\n",sum); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator