您的位置:首页 > 其它

F - Buggy Sat

2016-07-23 01:18 281 查看
Discovery Co. ltd. builds a satellite using a new kind of an intelligent camera. The camera has special software to detect cities and roads from an image, and is also able to detect every region (which is a connected part of surface), bounded by a series of connected roads with no other region inside. Using this technology, the satellite is able to compress the picture before sending it. The compressed format of a picture is the city locations and its regions.

Discovery has launched the satellite, without testing the software completely. So, after a while, they received some buggy pictures which includes one more extra region: the outer region. The outer region is the region of the plane enclosing every other region (which has infinite area). Further analysis shows that all images sent have the following properties:

1. All cities, in the image, have at least two roads to the other cities.

2. There is a path connecting every pair of cities.

3. There is at most one road between each pair of cities.

4. Roads do not cross each other except at the cities.



The above Figure shows a sample image received (see sample input).

You are to write a program to read a buggy image and report the outer region.

Input

The first line of the input consists of a single integer N (1 ≤ N ≤ 20), which is the number of test cases. The test cases appear with no blank lines in between. The first line of each test case consists of the number of cities (between 1 and 50) followed by pairs of integers (x, y) which are location of cities (each pair in one line), followed by number of faces in a separate line (between 1 and 50), followed by face information on each line. Face information consists of number of cities making the face and the city numbers in clockwise (or counterclockwise) order.

Output

There should be a single line containing the boundary face number for each test case, with no blank lines in between.

Sample Input

1

5

2 6

4 4

4 7

8 6

4 10

3

4 1 2 4 3

4 1 3 4 5

4 1 2 4 5

Sample Output

3

题意:给你一幅图,和若干个分块,问哪一个才有可能是原来的那个分块。(原来是只有一个分块的,然后这个东西出bug了,然后就多了几块)

其实就是求最大面积的那块。

多边形面积可以分成多个三角形,三角形面积是两边向量相乘*(1/2),要注意点在内部,往内凹的情况。

代码:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
struct Point
{
int x;
int y;
}point[55];
struct Line
{
int x;
int y;
}line1,line2;
int work(Line a,Line b)
{
return (a.x*b.y-a.y*b.x);
//可能会有负值,就是凹进去的情况
}
void solve()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d %d",&point[i].x,&point[i].y);
}
int m;
cin>>m;
int b[55][550];
int cnt[55];
for(int i=0;i<m;i++)
{
cin>>cnt[i];
for(int j=0;j<cnt[i];j++)
{
scanf("%d",&b[i][j]);
}
}
int smax=0;
int id=0;
for(int i=0;i<m;i++)
{
int s=0;
for(int j=1;j<cnt[i]-1;j++)
{
line1.x=point[b[i][0]].x-point[b[i][(j)]].x;
line1.y=point[b[i][0]].y-point[b[i][(j)]].y;
line2.x=point[b[i][0]].x-point[b[i][(j+1)]].x;
line2.y=point[b[i][0]].y-point[b[i][(j+1)]].y;
s+=work(line1,line2);
}
s=abs(s);//在最后取正值比较
if(s>smax)
{
id=i+1;
smax=s;
}
}
printf("%d\n",id);
}
int main (void)
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforce UVALive