POJ 1696 Space Ant(卷包裹 计算几何)
来源:互联网 发布:c语言中if else语句 编辑:程序博客网 时间:2024/04/28 18:25
题目链接:http://poj.org/problem?id=1696
一只蚂蚁,只能往左拐,求一条路线能让蚂蚁走过所有的点
题目比较简单,每次找最外面一层的,可以直接凸包,每次求凸包
我是直接每次找和上一条路线夹角最小的为下一次的目标点,直到走完所有点!
#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <cmath>using namespace std;#define maxn 100struct point{ double x,y; bool is_use; int num;}po[maxn],temp,now;double angle(point a, point b, point c){ c.x-=(b.x-a.x); c.y-=(b.y-a.y); double ux = b.x - a.x, uy = b.y - a.y; double vx = c.x - a.x, vy = c.y - a.y; return acos((ux*vx + uy*vy) / sqrt((ux*ux + uy*uy) * (vx*vx + vy*vy)));}int n,pos;int main(){ int i,j,k,t; double ang,re; scanf("%d",&t); while(t--){ scanf("%d",&n); printf("%d ",n); temp.y=100000; for(i=0;i<n;i++){ scanf("%d%lf%lf",&po[i].num,&po[i].x,&po[i].y); if(po[i].y < temp.y) pos=i,temp=po[i]; po[i].is_use=true; } printf("%d ",po[pos].num); po[pos].is_use=false; temp.x-=10; now=po[pos]; for(i=0;i<n-1;i++){ ang=3.14; for(j=0;j<n;j++){ if(po[j].is_use==false) continue; re=angle(temp,now,po[j]); if(re<ang){ pos=j; ang=re; } } printf("%d ",po[pos].num); po[pos].is_use=false; temp=now; now=po[pos]; } printf("\n"); } return 0;}
- POJ 1696 Space Ant(卷包裹 计算几何)
- POJ 1696 Space Ant(卷包裹)
- poj 1696 Space Ant 卷包裹法
- POJ 1696 Space Ant(卷包裹法)
- POJ 1696 Space Ant(凸包-卷包裹法)
- poj 1696 Space Ant(计算几何)
- POJ 1696 Space Ant(类卷包裹法)
- poj 1696 Space Ant 计算几何
- POJ 1696 Space Ant <计算几何>
- POJ 1696 Space Ant (卷包裹法求变形凸包)
- Poj 1696 Space Ant (凸包卷包裹)
- POJ 1696 Space Ant 计算几何 叉积的应用
- POJ 1696 Space Ant (计算几何 + 极角排序)
- [Poj 1113] 计算几何之凸包(一){卷包裹算法}
- POJ 1696 Space Ant (极角排序、凸包卷包裹(GiftWrapping)算法)
- poj1696 Space Ant 计算几何
- 【转载】[Poj 1113] 计算几何之凸包(一) {卷包裹算法}
- zoj 1429 || poj 1696 Space Ant 计算几何叉积或凸包改进版
- Photoshop中的常用快捷键
- 坤卦
- request.getAttribute()与request.getParameter()区别
- OCP-1Z0-052-V8.02-75题
- 基于DNN的CKeditor配置与使用
- POJ 1696 Space Ant(卷包裹 计算几何)
- Linux 添加环境变量和删除环境变量
- 开源框架二次开发-------php手记
- asp.net中配置文件web.config文件的读取和修改
- 谨记使用ajax忽视的小错误
- chmod命令之rwx
- 乾为天
- 富士通面试
- 你让工人为你工作7天,回报是一根金条.....