"Codejam2015 round1a" C Logging

Source: Internet
Author: User

Problem

A certain forest consists of N trees, each of which are 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 a unique coordinates (XI, Yi), and the boundary is the Convex hull of those points.

Some trees is on the boundary of the forest, which means they is on an edge or a corner of the polygon. The squirrels wonder how close their trees is to being on the boundary of the forest.

One at a time, each squirrel climbs to the its tree, examines the forest, and determines the minimum number of trees th At would need to is cut down for its own tree to is on the boundary. It then writes a and a log.

Determine the list of numbers written on the log.

Input

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 integer N, the number of trees, followed by N lines with the space-separated intege RS Xi and Yi, the coordinates of each tree. No. Trees would have the same coordinates.

Output

For each test case, the output one line containing ' case #x: ', followed by N lines with one integer, where line I contain s the number of trees the squirrel living in tree I would need to cut down.

Limits

-106≤xi, yi≤106.
Small DataSet

1≤t≤100.
1≤n≤15.
Large DataSet

1≤t≤14.
1≤n≤3000.
Sample

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 is four trees forming a square, and a fifth tree inside the square. Since The first four trees is already on the boundary and the squirrels for those trees each write down 0. Since One tree needs to is cut down for the fifth tree to is on the boundary, the fifth squirrel writes down 1.

Briefly describe the topic:
There are some points on the plane that ask to remove those points so that a point becomes a point on the convex hull boundary.

The necessary and sufficient conditions for a point to become a point on a convex hull are:

There is no point on one side of a line that is over that point.

Then we enumerate each point and then build the point as the origin and sort the other point angles.

Then just use a straight line to turn around in the polar order to calculate the minimum point on one side.

How to sort the polar corners?
① need to use the functions in C + + aT aN2(y,x ) :

In simple terms, starting with the third quadrant, incrementing the counter-clockwise

② Another way is to look at the quadrant, and then use the cross product calculation.

int CMP (const point&a, const POINT&AMP;B) {if(a==B)return 0;int s1= (a. y<=0&&a. x<=0||a.y<0);int s2= (b.y<=0&& b.x<=0|| b.y<0);    if(S1!=S2)returnS1>s2;    return a*b>0;}

Code: O( n 2 l ogN)

#include <iostream>#include <cmath>#include <cstdio>#include <cstring>#include <cstdlib>#define EPS 1e-9#define Pi ACOs ( -1)using namespace STD;intx[3005],y[3005],t,n;Doublea[6005];intMain () {Cin>>T; for(intt=1; t<=t;t++) {printf("Case #%d:\n", t);scanf("%d", &n); for(intI=1; i<=n;i++)scanf("%d%d", &x[i],&y[i]); for(intI=1; i<=n;i++) {intn=0; for(intj=1; j<=n;j++)if(I!=J) a[++n]=atan2(Y[j]-y[i],x[j]-x[i]); Sort (A +1, A +1+N); for(intj=1; j<=n;j++) a[j+n]=a[j]+2*pi;intj=1, Ans=n; for(intk=1; k<=n;k++) {J=max (k,j); while(a[j+1]<a[k]+pi-eps) j + +;            Ans=min (ANS,J-K); }cout<<ans<<endl; }    }return 0;}

"Codejam2015 round1a" C Logging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.