poj 1696 Space Ant
来源:互联网 发布:军工软件是什么意思 编辑:程序博客网 时间:2024/05/05 06:24
题意:对顶点圈出一个向左转的最长的罗璇, 顶点只能走过一次,罗璇没有交线;
分析:对任意点集, 都能圈出一个罗璇包含所有节点; 用叉积判断罗璇方向,圈出罗璇就行,注意输出点数和起始位置的判定
#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <algorithm>#include <vector>#include <queue>#define MAX 10005#define INF 100000000#include <iostream>#define PI acos(-1.0)#define eps 1e-8#define INF 1e8using namespace std;struct Point{ int index; int x, y; Point() {} Point(int xx, int yy):x(xx), y(yy){} bool operator < (const Point & p)const { if(x != p.x) return ( x < p.x); return y < p.y; } void input(){ cin>>index>>x>>y; } void output(){ cout<<x<<" "<<y<<endl; } int xmult(const Point &vec)const{ return x * vec.y - y * vec.x; } Point sub(const Point &p)const{ return Point(x - p.x, y - p.y); }}p[MAX];vector<Point>ansArray;int M, N;void init(){ cin>>N; for(int i = 0; i < N; i++){ p[i].input(); } ansArray.clear(); sort(p, p + N);}void getAnsArray(){ bool v[MAX]; memset(v, 0, sizeof(v)); int m = 0, mMin = 1, j = 0, sign = 1, miny = INF; for(int i = 0; i < N; i++){ if(p[i].y < miny){ miny = p[i].y; j = i; } } while(true){ //串完所有点 for( ; j < N && j >= 0; j+= sign){ if(!v[p[j].index]){ while(m > mMin && (ansArray[m -1].sub(ansArray[m - 2]).xmult(p[j].sub(ansArray[m - 2]))) < 0){ m --; ansArray.pop_back(); } m++; ansArray.push_back(p[j]); } } if(m >= N)break; mMin = m; sign *= -1; j += sign; for(int jj = 0; jj < ansArray.size(); jj++){ v[ansArray[jj].index] = true; } } cout<<ansArray.size(); for(int i = 0; i < ansArray.size(); i++){ cout<<" "<<ansArray[i].index; }cout<<endl;}int main(){ cin>>M; while(M--){ init(); getAnsArray(); } return 0;}
- POJ 1696 Space Ant
- POJ 1696 Space Ant
- poj 1696 Space Ant
- POJ 1696 Space Ant
- poj 1696 Space Ant
- poj 1696Space Ant
- Poj-1696-Space Ant
- POJ 1696Space Ant
- POJ 1696 Space Ant
- POJ 1696 Space Ant 贪心
- Space Ant - POJ 1696 叉积
- zoj 1429 || 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(卷包裹)
- 逆向iOS SDK -- _UIImageAtPath 的实现(SDK 6.1)
- 分享一个网络图片控件(WebImage for wp8)
- uva 133 The Dole Queue 双向约瑟夫环 模拟实现
- javapoi读写数据 excel
- ruby+python
- poj 1696 Space Ant
- C/C++ 取整函数ceil(),floor()
- HDU-1672-Cuckoo Hashing
- Java基础之Hello World
- 2013年暑假队内选拔赛题解2
- libcurl (ftp)库
- Java基础之进制转换(图解)
- C++虚函数复习
- maven仓库和转换eclipse工程