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 |
JAVA 怎么就这么烦,老是不明不白就RE~哪位大牛帮我看看好不import java.util.*; //RE why? class Node { int x; int y; double ang; } public class Main { int N; int L; Node[] s; Node[] t; Node[] cs; public Main() { Scanner r=new Scanner(System.in); N=r.nextInt(); L=r.nextInt(); s=new Node[N]; for (int i=0;i<N ;i++ ) { s[i]=new Node(); s[i].x=r.nextInt(); s[i].y=r.nextInt(); } for (int i=1;i<N ;i++ ) //找出y坐标最小且在最右边,赋值去s[0] { if ((s[i].y<s[0].y)||((s[i].y==s[0].y)&&(s[i].x<s[0].x))) { Node temp=new Node(); temp=s[0]; s[0]=s[i]; s[i]=temp; } } t=new Node[N-1]; for (int i=1;i<N ;i++ ) //其他各个点以s[0]为原点做坐标变换 { t[i-1]=new Node(); t[i-1].x=s[i].x-s[0].x; t[i-1].y=s[i].y-s[0].y; t[i-1].ang=Math.atan2(t[i-1].y,t[i-1].x); } for (int i=1;i<t.length ;i++ ) //冒泡排序 以t[i].ang作非降序排序 for (int j=0;j<t.length-i ;j++ ) { if (t[j].ang>t[j+1].ang) { Node temp=t[j]; t[j]=t[j+1]; t[j+1]=temp; } } cs=new Node[N]; for (int i=0;i<N ;i++ ) { cs[i]=new Node(); } cs[0]=t[N-2]; cs[1].x=0;cs[1].y=0; int sp=1; int k=0; while (k<N-1) { double D=cs[sp-1].x*cs[sp].y+cs[sp].x*t[k].y+t[k].x*cs[sp-1].y-cs[sp-1].y*cs[sp].x-cs[sp].y*t[k].x-t[k].y*cs[sp-1].x; if (D>=0) cs[++sp]=t[k++]; else sp--; } double result=0; double a; double b; for (int i=0;i<sp ;i++ ) { a=cs[i+1].x-cs[i].x; b=cs[i+1].y-cs[i].y; result+=Math.sqrt(a*a+b*b); } a=cs[sp].x-cs[0].x; b=cs[sp].y-cs[0].y; result+=Math.sqrt(a*a+b*b); result+=Math.PI*2*L; System.out.println((int)result); } public static void main(String[] args) { Main p=new Main(); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator