标签:
A certain forest consists of N trees, each of which is inhabited by a squirrel.
The boundary of the forest is the convex polygon of smallest area which contains every tree, as if a giant rubber band had been stretched around the outside of the forest.
Formally, every tree is a single point in two-dimensional space with unique coordinates (Xi,Yi), and the boundary is the convex hull of those points.
Some trees are on the boundary of the forest, which means they are on an edge or a corner of the polygon. The squirrels wonder how close their trees are to being on the boundary of the forest.
One at a time, each squirrel climbs down from its tree, examines the forest, and determines the minimum number of trees that would need to be cut down for its own tree to be on the boundary. It then writes that number down on a log.
Determine the list of numbers written on the log.
The first line of the input gives the number of test cases, T.T test cases follow; each consists of a single line with an integerN, the number of trees, followed by N lines with two space-separated integersXi and Yi, the coordinates of each tree. No two trees will have the same coordinates.
For each test case, output one line containing "Case #x:", followed by N lines with one integer each, where line i contains the number of trees that the squirrel living in treei would need to cut down.
-106 ≤ Xi, Yi ≤ 106.
1 ≤ T ≤ 100.
1 ≤ N ≤ 15.
1 ≤ T ≤ 14.
1 ≤ N ≤ 3000.
Input |
Output |
2 5 0 0 10 0 10 10 0 10 5 5 9 0 0 5 0 10 0 0 5 5 5 10 5 0 10 5 10 10 10 |
Case #1: 0 0 0 0 1 Case #2: 0 0 0 0 3 0 0 0 0 |
In the first sample case, there are four trees forming a square, and a fifth tree inside the square. Since the first four trees are already on the boundary, the squirrels for those trees each write down 0. Since one tree needs to be cut down for the fifth tree to be on the boundary, the fifth squirrel writes down 1.
直接枚举所有点都做一次极角排序,然后枚举所有可能形成的直线将点分成两部分,每次取点最少的那部分
为了让枚举直线部分快一点,采用旋转的方式
#include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<iostream> #include<algorithm> #include<bitset> #include<climits> #include<list> #include<iomanip> #include<stack> #include<set> using namespace std; double a[6010],x[3010],y[3010]; int main() { freopen("C-large-practice.in","r",stdin); freopen("C-large-practice.out","w",stdout); int T; cin>>T; for(int cs=1;cs<=T;cs++) { int n; cin>>n; for(int i=0;i<n;i++) cin>>x[i]>>y[i]; cout<<"Case #"<<cs<<":"<<endl; for(int i=0;i<n;i++) { int k=0; for(int j=0;j<n;j++) if(j!=i) a[k++]=atan2(y[j]-y[i],x[j]-x[i]); sort(a,a+k); for(int j=0;j<k;j++) a[k+j]=a[j]+M_PI*2.0;//方便旋转 int l=0,r=0,ans=n-1; for(int j=0;j<k;j++) { while(l<2*k&&a[l]-a[j]==0)//把跟i,j在同一直线上的点去掉 l++; while(r<2*k&&a[r]-a[j]<M_PI-1e-15)//这里是玄学。。去掉1e-15就wa,不明白 r++; ans=min(ans,r-l); } cout<<ans<<endl; } } }
google code jam Round 1A 2015 Problem C. Logging
标签:
原文地址:http://blog.csdn.net/stl112514/article/details/45115473