POJ 1113 wall(凸包模板)
来源:互联网 发布:k线图制作软件 编辑:程序博客网 时间:2024/05/16 14:35
嗯。。鉴于在练习也无所谓正确率,,就在WA了之后一点一点不停的改。。终于AC了。。。激动之情溢于言表好嘛!好嘛!!
OK。。来总结。。
WA的第一个可能的地方:没有考虑三点在同一条直线的情况;
WA的第二个可能的地方:最开始学习凸包的时候在网上找的代码使用坐标排序不是用极角排序的,改成了极角感觉会比坐标排序适用性更大一点;
WA的第三个可能的地方:(这个应该不是可能而是一定。。)题目要求四舍五入,,开始我用的是%.0lf。。因为发现它好像默认可以四舍五入。。。后来测试了一下发现它会把类似16.500000这种约成16而16.50000001约成17.。。好神奇啊嘿嘿嘿嘿。。。后来改成了(int)(ans+0.5);
WA的第四个可能的地方(挖槽这么多):网上某答案的代码是把前三个保存之后继续考虑后面的。。默默的改成了保存前两个。。万一前三个共线了呢。。。
第四个源代码类似这样
<pre name="code" class="cpp"> ch[0]=p[0]; ch[1]=p[1]; ch[2]=p[2]; for(i=3;i<n;i++){ if((i+1<n)&&(xmult(p[i],p[i+1],p[0])==0)) continue; while(xmult(p[i],ch[top],ch[top-1])>=0) top--; ch[++top]=p[i]; }
被我改成了这样。。。
<pre name="code" class="cpp"> res[0]=point[0]; res[1]=point[1]; for(int i=2;i<n;i++) { if((i+1<n)&&(multi(point[i],point[i+1],point[0])==0)) continue; while(multi(point[i],res[m],res[m-1])>=0&&m>=1) m--; res[++m]=point[i]; }
我的明显更科学啊有木有哈哈哈哈。。。
来,上AC的代码。。一个下午加一个晚上的辛苦成果,,,喵的
<pre name="code" class="cpp">#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const double pi=3.14159265;struct POINT{ float x,y;};struct POINT point[1005],res[1005];double len(POINT x,POINT y){ return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y);}double multi(POINT x,POINT y,POINT z){ return (x.x-z.x)*(y.y-z.y)-(x.y-z.y)*(y.x-z.x);}int cmp(POINT x,POINT y){ double xx=multi(x,y,point[0]); if(xx>0) return 1; if((xx==0) && (len(x,point[0])<len(y,point[0]))) return 1; return 0;}int convex(int n){ int m=1,k; int p=0; if(n<=3) { for(int i=0;i<4;i++) res[i]=point[i]; return n; } for(int i=1;i<n;i++) if((point[i].y<point[p].y)||((point[i].y==point[p].y)&&(point[i].x>point[p].x))) p=i; POINT temp; temp=point[0],point[0]=point[p],point[p]=temp; sort(point+1,point+n,cmp); res[0]=point[0]; res[1]=point[1]; for(int i=2;i<n;i++)//对!最后一发WA错在了这!原来是3忘记改成2了。。。。 { if((i+1<n)&&(multi(point[i],point[i+1],point[0])==0)) continue; while(multi(point[i],res[m],res[m-1])>=0&&m>=1) m--; res[++m]=point[i]; } return ++m;}int n,l,t;int main(){ //freopen("in","r",stdin); double ans; scanf("%d%d",&n,&l); ans=0; for(int i=0;i<n;i++) scanf("%f%f",&point[i].x,&point[i].y); int m=convex(n); //printf("m=%d\n",m); for(int i=0;i<m;i++) {ans+=sqrt(len(res[i%m],res[(i+1)%m])); //printf("%lf %lf\n",res[i].x,res[i].y); } ans+=2*pi*l; //printf("%lf.....\n",ans+0.5); if(ans-(int)ans >= 0.5) printf("%d\n",(int)ans+1); else printf("%d\n",(int)ans);//诶?什么时候 改成这样的。。。 return 0;}
0 0
- POJ 1113 wall(凸包模板)
- poj 1113 Wall 凸包模板题
- POJ 1113 Wall 凸包(模板题)
- POJ 1113 WALL (凸包问题)
- POJ 1113 Wall (凸包)
- poj 1113 Wall(凸包周长)
- POJ 1113 Wall (凸包)
- POJ 1113 Wall (凸包)
- poj 1113 wall (凸包)
- poj 1113wall (凸包)
- POJ 1113 Wall(凸包)
- POJ 1113 wall (凸包)
- POJ 1113 Wall(凸包周长)
- POJ 1113 Wall(凸包)
- POJ 1113 Wall(凸包)
- POJ 1113 Wall (凸包)
- POJ 1113 Wall (凸包)
- POJ 1113 Wall (凸包)
- 游戏服务器JVM调优(Java)
- java迭代器PECS
- 第五单元5.18
- 技术博客整理
- nyoj7 街区最短路径问题
- POJ 1113 wall(凸包模板)
- 创建线程的第一种方法:继承Thread类
- C++内存配置操作和释放操作
- java 第五次实验
- java.lang.IllegalArgumentException: node to traverse cannot be null!
- HTTP深入浅出 http请求
- HC-SR04 连接 Raspberry Pi B+
- uva_11624_Fire!(bfs)
- HDU--1394(线段树)