【codechef】Chef and Polygons(灵活题,坑题)
来源:互联网 发布:mysql语言 编辑:程序博客网 时间:2024/05/16 11:13
Input:136-2 2 -1 1 2 2 2 -1 1 -2 -2 -23-1 -1 1 -1 1 143 3 -3 3 -3 -3 3 -3Output:1 0 2
Explanation
In the picture the first polygon is marked in green, second - in red and third in blue color.
http://www.codechef.com/JUNE15/problems/CHPLGNS
对于这题我只能说,我想得实在是太复杂了……
第一眼是马上去找 一个多边形是否在另一个多边形内 的模板,然后没找到;后来又尝试用面积相等的方法求,但是忽略了它可以是凹多边形;过了n天突然想到可以转化成只要求多边形任意一点是否在另一个多边形内,然后提交,10分。
【任意两个多边形都是一个包含另一个】这句话非常重要。仔细分析,每个多边形横坐标最靠左的点的横坐标,肯定是最外面的多边形在最左边,然后依次。
要仔细分析题目里面的细节,抓住可以投机取巧的点。
#include<iostream>#include<algorithm>#include<string>#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}#include<vector>#include<cmath>#include<queue>#include<string.h>#include<stdlib.h>#include<cstdio>#define mod 1e9+7#define ll long longusing namespace std;pair<int,int> x[100001];int cmp(pair<int,int> a,pair<int,int> b){return a.second<b.second;}int main(){int t;scanf("%d",&t);while(t--){int n,m,a,b,min;scanf("%d",&n);for(int i=0;i<n;++i){x[i].second=i;scanf("%d",&m);min=1000000001;for(int j=0;j<m;++j){scanf("%d %d",&a,&b);if(a<min)min=a;}x[i].first=min;} sort(x,x+n);for(int i=0;i<n;++i)x[i].first=n-i-1;sort(x,x+n,cmp);for(int i=0;i<n;++i)printf("%d ",x[i].first);printf("\n");} return 0;}再顺便附上求一个点是否在多边形内的模板吧:
int pnpoly (int nvert, float *vertx, float *verty, float testx, float testy) { int i, j, c = 0; for (i = 0, j = nvert-1; i < nvert; j = i++) { if ( ( (verty[i]>testy) != (verty[j]>testy) ) &&(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) c = !c; } return c;}
0 0
- 【codechef】Chef and Polygons(灵活题,坑题)
- 【codechef】Chef and Strange Formula(找规律,灵活题)
- 【codechef】 Chef and Piano Scales (简单题)
- 【codechef】Chef and A Large Permutation(技巧题)
- codechef(MAY15)第三题Chef and Prime Divisors
- CodeChef:Chef and Problems(分块 & 二分)
- CodeChef:Chef and Subsequences(思维 & dfs)
- CodeChef Chef and Segments
- codechef Chef and sequence
- codechef Chef and Swaps
- Codechef Chef and Reversing
- Codechef Chef and Frogs
- Codechef Chef and Churu
- 【CodeChef】 Chef and Stones
- 【CodeChef】Chef and Interview
- codechef Chef and Churu
- codechef Chef and easy problem
- codechef Chef and Left-Right
- 巧用Linq分组
- java基础 构造方法
- 广播接收者(BroadcastReceiver)详解
- python编码问题总结
- mysql配置中关于编码格式的理解
- 【codechef】Chef and Polygons(灵活题,坑题)
- 第七章
- springmvc接收请求参数的方法
- oracle初次开发问题记录
- GRE作文备考——网络审查的必要性
- adb (Android Debug Bridge) 命令行的使用方法
- 用心看世界——身边
- C#操作Excell常用方法
- Android应用开发之使用PhoneGap(cordova)实现拍照上传功能