Submit Info #38113

Problem Lang User Status Time Memory
Sort Points by Argument cpp pandi AC 63 ms 14.62 MiB

ケース詳細
Name Status Time Memory
example_00 AC 1 ms 0.62 MiB
max_random_00 AC 60 ms 14.62 MiB
max_random_01 AC 62 ms 14.62 MiB
max_random_02 AC 62 ms 14.55 MiB
near_arg_00 AC 63 ms 14.30 MiB
near_arg_01 AC 62 ms 14.30 MiB
near_arg_02 AC 62 ms 14.23 MiB
near_arg_shuffle_00 AC 63 ms 14.30 MiB
near_arg_shuffle_01 AC 63 ms 14.30 MiB
near_arg_shuffle_02 AC 63 ms 14.30 MiB
random_00 AC 39 ms 9.55 MiB
random_01 AC 47 ms 11.17 MiB
random_02 AC 16 ms 4.30 MiB
small_all_00 AC 0 ms 0.62 MiB

#include <cstdio> using std::fread; using std::fwrite; #include<cmath> using std::atan2; #include <algorithm> using std::sort; char buf[4800007], *i=buf,*l,*r; struct pt { int x,y; long double arg; } pts[200000]; bool cmp(const pt&a,const pt&b){return a.arg<b.arg;} unsigned N; int x,y;bool neg; int main() { buf[fread(buf,1,sizeof buf,stdin)]='\n'; while(*i!='\n')N=N*10+*i++-'0'; ++i; for (unsigned j=0;j<N;++j){ x=y=neg=0; if(*i=='-')neg=1,++i; while(*i!=' ')x=x*10+*i++-'0'; if(neg)x=-x; ++i; neg=0; if(*i=='-')neg=1,++i; while(*i!='\n')y=y*10+*i++-'0'; if(neg)y=-y; ++i; char temp=*i;*i=0; //printf("[%s] %d %d\n",buf,x,y); *i=temp; pts[j].x=x;pts[j].y=y;pts[j].arg=atan2l(y,x); } sort(pts,pts+N,cmp); i=buf; for(unsigned j=0;j<N;++j){ //printf("%d %d\n",pts[j].x,pts[j].y);continue; x=pts[j].x;y=pts[j].y; if(x<0)*i++='-',x=-x; l=i;while(x)*i++=x%10+'0',x/=10; if(i==l)*i++='0'; for(r=i-1;l<r;++l,--r)*l^=*r,*r^=*l,*l^=*r; *i++=' '; if(y<0)*i++='-',y=-y; l=i;while(y)*i++=y%10+'0',y/=10; if(i==l)*i++='0'; for(r=i-1;l<r;++l,--r)*l^=*r,*r^=*l,*l^=*r; *i++='\n'; } fwrite(buf,1,i-buf,stdout); }