UVALive 5878 - Shortest Leash 【计算几何】
来源:互联网 发布:mac怎么安装程序 编辑:程序博客网 时间:2024/05/29 17:14
题目大意:给你一堆向量,每个向量可以选择正向或者反向,最后加起来,求最大模。
把向量和反向量一起按极角排序,从中任取连续的n个,这n个向量一定不会全部包含任意一个向量的正反向量,所以找n次,每次找连续n个,找最大模出来就行了。
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<map>using namespace std;struct xiangliang{int x,y;int hao;bool friend operator<(xiangliang a,xiangliang b){if(a.hao!=b.hao)return a.hao<b.hao;return a.x*b.y-a.y*b.x>0;}}a[210];int n;double MAKE(int x){double xx=0,yy=0;for(int i=1;i<=n;i++){xx+=a[x+i-1].x;yy+=a[x+i-1].y;}return sqrt(xx*xx+yy*yy);}int main(){while(~scanf("%d",&n)){if(!n)break;for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);for(int i=1;i<=n;i++){a[i+n].x=-a[i].x;a[i+n].y=-a[i].y;}for(int i=1;i<=2*n;i++){if(a[i].x>0&&a[i].y>0)a[i].hao=1;if(a[i].x<0&&a[i].y>0)a[i].hao=1;if(a[i].x<0&&a[i].y<0)a[i].hao=2;if(a[i].x>0&&a[i].y<0)a[i].hao=2;if(a[i].x>0&&a[i].y==0)a[i].hao=1;if(a[i].x<0&&a[i].y==0)a[i].hao=2;if(a[i].x==0&&a[i].y==0)a[i].hao=0;if(a[i].x==0&&a[i].y>0)a[i].hao=1;if(a[i].x==0&&a[i].y<0)a[i].hao=2;}sort(a+1,a+1+2*n);double ans=0;for(int i=1;i<=n;i++)ans=max(ans,MAKE(i));printf("%.3f\n",ans);}return 0;}
0 0
- UVALive 5878 - Shortest Leash 【计算几何】
- UVALIVE 5893 计算几何+搜索
- UVALive 2221 Frontier(计算几何 + DP)
- UVALive 5908 Tracking RFIDs 【计算几何】
- UVALive 6835Space Golf-计算几何
- UVAlive 7366 Brocard(二分+计算几何)
- UVALive-7351-The Agglomerator(计算几何)
- UVALive 6092 Catching Shade in Flatland --枚举+几何计算
- UVALive - 3263 - That Nice Euler Circuit (计算几何~~)
- UVALive 6041 Retrenchment(KD树 + 计算几何)
- UVALive 6188 (LA 6188) Let There Be Light 计算几何
- [UVALive 6693]Flow Game计算几何,线代相交
- UVALive 3263 That Nice Euler Circuit(计算几何)
- POj 2002 UVALive - 3047 C - Squares 【计算几何+二分求解】
- 计算几何【套模板,推荐模板】 Separating Pebbles UVALive
- UVALive 3263 That Nice Euler Circuit 计算几何欧拉定理
- UVALive 5908 Tracking RFIDs(计算几何+数据结构,暴力也可过)
- UVALive 3263 That Nice Euler Circuit 计算几何+欧拉定理
- JVM学习笔记4—GC参数
- ArrayList嵌套存储变长数组
- iOS9下有关CoreLocation学习一
- 嵌入式开发的基本环境配置大全
- #HDU 1372 Knight Moves 【BFS】
- UVALive 5878 - Shortest Leash 【计算几何】
- !!!!!!!!!!!!!!!!!!!!!!!!!
- cocos2dx学习之路----第五篇(切换场景的另一种方式:使用popScene与pushScene)
- 图像分割简单处理
- android studio导入SlidingMenu的方法
- 016-Storm借助tick消息定时器统计统计周期性业务
- jquery动态改变form属性提交表单
- UVALive 5873 - Tree Inspections 【模拟】
- #HDU 1016 Prime Ring Problem 【DFS+溯回求组数】