ZZUOJ-1245-Looking for happiness of Small L (Zhengzhou University Eighth annual ACM College Student Program Design Competition f)

Source: Internet
Author: User


1245: Looking for a happy little L time limit: 1 Sec Memory Limit: MB
Submit: Solved: 14
[Submit] [Status] [Web Board] Description

Small L recently saw a female classmate called small A, but small a is a high-cold girl, so she gave small l a problem, she gave small l left a note, the above only a coordinate, and a time, so small l need to find the coordinates in the specified time location, and at that time to where to wait for small a, but very helpless, Small L is not a geography, so he found a small a roommate, want to know a little bit of information, small A's roommate gave small L a total of N City Corner coordinates (assuming each city is a M polygon), small l need to do is to judge whether small a is in the city (on the edge or at the top of the city also counted in the city) So small l found the magical acmer, and everyone help him find his little a.

Input

There are several sets of test data that you need to process to the end of the file (EOF), with each group formatted as follows:

First behavior one coordinate x, y and two digits n,m ( -1000<=x,y<=1000, 1<=n<=100, 3<=m<=100)
The next n rows have m coordinates for each row (coordinates are given in a counterclockwise order, where the coordinates are integers)

Output

Output in the first few cities

Sample Input
5 5 2 42 0 4 0 4 4 2 4 2 0 6 0 6 6 2 6
Sample Output
2
HINT

There must be an answer to that question . , and will only be in one city. (even if the city has overlapping) . and the polygon of a given city is convex polygons.


Source


Competition, do the most fun than a problem, simply ah, I am still silly X did not do it, before the idea is wrong, the sample did not (in fact, it is true, as long as add a fabs almost), and then saw the template, excitedly knocked up the template, really his mother wasted time ah. I haven't had it since. Alas, I really want to hold a personal cry ah.


Idea: First all input, then the city, using from the first point to divide the triangle to calculate the entire area of the city, and then use this can calculate the point and the city every two points (counterclockwise a circle) to make up the triangle area of the sum, if the two areas of equal points in the cities.


AC Code:


#include <cstdio> #include <cstring> #include <algorithm> #include <cmath>using namespace std; typedef struct{double x, y;} Point;struct node{point pos[110];}      CITY[110];d ouble area2 (Point A, point B, point C) {Double TMP1 = a.x * b.y + c.x * a.y + b.x * C.Y;            Double TMP2 = c.x * b.y + a.x * c.y + b.x * A.Y;  return Fabs (TMP1-TMP2);  } int main () {point p;int N, M;while (scanf ("%lf%lf%d", &p.x, &p.y, &n, &m)!=eof) {for (int i=0; i<n; i++) {for (int j=0; j<m; J + +) {scanf ("%lf%lf", &city[i].pos[j].x, &AMP;CITY[I].POS[J].Y);}} int i;for (i=0; i<n; i++) {double ar1=0, ar2=0;for (int j=1; j<m-1; j + +)//calculates the area of the entire city {ar1+=area2 (city[i].pos[0], CI TY[I].POS[J], city[i].pos[j+1]);} for (int j=0; j<m-1; j + +)//calculate point and city every two points (counterclockwise) make up the triangle area of the sum {AR2+=AREA2 (P, City[i].pos[j], city[i].pos[j+1]);} AR2+=AREA2 (P, city[i].pos[m-1], city[i].pos[0]); if (Fabs (AR1-AR2) <=1e-7) break;} printf ("%d\n", i+1);} return 0;}






ZZUOJ-1245-Looking for happiness of Small L (Zhengzhou University Eighth annual ACM College Student Program Design Competition f)

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.