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),要注意点在内部,往内凹的情况。
代码:
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; }
相关文章推荐
- Codeforces Round #246 (Div. 2)
- Codeforces Coder-Strike 2014 - Finals (online edition, Div. 1)
- Codeforce Maximal Area Quadrilateral
- UVALive 4244 Party Party Party(HDU 2779 && Sicily 1663)
- UVALive 6741 The Sacrificial Firepits
- UVALive 5870 - Smooth Visualization
- UVALive 5876 - Writings on the Wall 【KMP】
- UVALive 5878 - Shortest Leash 【计算几何】
- UVALive 5873 - Tree Inspections 【模拟】
- UVALive 6800 The Mountain of Gold (bellman_ford判负环)
- codeforce之最少加多少能组成一个凸三角形
- codeforce之Magic Powder
- codeforce之 Bear and Colors
- codeforce之problems for round
- CF之Recycling Bottles
- CF之Vasya and String
- code force 之 Money transfer
- UVALive 6436 The Busiest City
- C. NP-Hard Problem
- Uvalive 6855 Banks