UVa11030-Predator II


Problem D


Predator II


Time limit: 2 seconds

Oh No!!! The predator has entered the room again. But this time it is a different kind of room.

The room is a square of size 10000 X 10000. There are several compartments of different shapes and sizes, situated strictly inside the room. The walls of different compartments don’t overlap, but a compartment can be completely inside that of another.

This time the predator has learned to hop over walls, but it can jump over at most one wall at a time. Given the starting and ending coordinates of the predator, and the positions of the compartments, your job is to find out the minimum number of hops required
for the predator to reach his destination from the start.

The starting and ending positions are never on the boundary of any compartment.

Input

 

The first line of input is an integer (T ≤ 20), that indicates the number of test cases. Each case starts with an integer

(n ≤ 20), that determines the number of compartments in the room. The next n lines give the positions of the compartments. The compartments are simple polygons. The description of each compartment starts with an integers
(S ≤ 10), that gives the number of sides of the polygon, followed by pairs of x, y coordinates in order. Next there is an integer that determines the number of queries for this scenario.
Each of the next Q lines contains 4 integers x1, y1, x2, y2(x1, y1) is the starting position and (x2, y2) is the ending position.

The lower left and upper right coordinates of the room are (0, 0) and (10000, 10000) respectively.

Output

 

For each case, output the case number. Then for each query, output the minimum number of hops required.


Sample Input


Output for Sample Input


2

3

4 1 1 5 1 5 5 1 5

4 2 2 4 2 4 4 2 4

3 7 7 10 10 7 10

1

3 3 8 9

1

4 1 1 10 1 10 10 1 10

2

2 2 100 100

100 100 2 2


Case 1:

3

Case 2:

1

1

ProblemSetter: Sohel Hafiz

Next Generation Contest 2

 

Illustration

The following diagram depicts the first sample input.

Pink spot à starting position

Black spot à target

The three hops are shown by three broad line segments.

题目大意就是有 n个polygon, m组询问,每次询问一个点最少要越过多少条边才能到达另一个点, 用容斥可以解决  包括a点的polygon数量+b点的polygon数量-2*(同时包括a,b的polygon数量)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
const double eps = 1e-8;
struct Point{
    double x,y;
    friend bool operator < (Point a,Point b){
        if(fabs(a.x-b.x)>eps) return a.x < b.x;
        else return a.y < b.y;
    }
    friend bool operator == (Point a,Point b){
        return fabs(a.x-b.x)<eps && fabs(a.y-b.y)<eps;
    }
    Point(double x=0,double y=0):x(x),y(y){}
};
Point operator - (const Point &a,const Point &b){
    return Point(a.x-b.x,a.y-b.y);
}
int dcmp(double x){
    if(fabs(x) < eps) return 0;
    else if(x > 0) return 1;
    else return -1;
}
double det(Point p1,Point p2){
    return p1.x*p2.y-p1.y*p2.x;
}
int inPolygon(vector<Point> p, Point q) {
    int cnt = 0;
    int n = p.size();
    for(int i = 0, j = n-1; i < n; j = i++) {
        if(p[i].y > q.y != p[j].y > q.y &&
           q.x < (p[j].x-p[i].x)*(q.y-p[i].y)/(p[j].y-p[i].y) + p[i].x)
           cnt++;
    }
    return cnt&1;
}
int n;
vector<vector<Point> > vp;
int main(){

    int ncase,T=1;
    cin >> ncase;
    while(ncase--){
        cin >> n;
        vp.clear();
        for(int i = 0; i < n; i++){
            vector<Point> t;
            t.clear();
            int m;
            cin >> m;
            for(int k = 0; k < m; k++){
                double x,y;
                cin >> x >> y;
                t.push_back(Point(x,y));
            }
            vp.push_back(t);
        }
        int fd;
        cin >> fd;
        printf("Case %d:\n",T++);
        while(fd--){
            int a=0,b=0,c=0;
            double x,y;
            cin >> x >> y;
            Point t1(x,y);
            cin >> x >> y;
            Point t2(x,y);
            for(int i = 0; i < n; i++){
                int flag1 = inPolygon(vp[i],t1),flag2 = inPolygon(vp[i],t2);
                if(flag1)
                    a++;
                if(flag2)
                    b++;
                if(flag1&&flag2) c++;
            }
            cout<<a+b-2*c<<endl;
        }
    }
    return 0;
}

UVa11030-Predator II,码迷,mamicode.com

时间: 2024-10-17 12:28:37

UVa11030-Predator II的相关文章

Gopher II UVA 10080,最后被抓的地鼠有多少只?

. Gopher II UVA, 10080 Time Limit: 3000 MS The gopher family, having averted the canine threat, must face a new predator. The are n gophers and m gopher holes, each at distinct (x, y) coordinates. A hawk arrives and if a gopher does not reach a hole

NOIP前夕:noi.openjudge,Gopher II

Gopher II 总Time Limit:2000msMemory Limit:65536kB Description The gopher family, having averted the canine threat, must face a new predator.  The are n gophers and m gopher holes, each at distinct (x, y) coordinates. A hawk arrives and if a gopher doe

POJ 2536 之 Gopher II(二分图最大匹配)

Gopher II Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6675   Accepted: 2732 Description The gopher family, having averted the canine threat, must face a new predator. The are n gophers and m gopher holes, each at distinct (x, y) coor

POJ2536_Gopher II(二分图最大匹配)

解题报告 http://blog.csdn.net/juncoder/article/details/38156509 题目传送门 题意: n只地鼠,m个洞,老鹰的到达地面的时间s,地鼠的移动速度v,求多少只地鼠会被老鹰吃了. 思路: 地鼠和洞看成两集合,建立二分图.只有当地鼠到洞的时间少于老鹰到地面的时间才连边. #include <cmath> #include <cstdio> #include <cstring> #include <iostream>

poj 2536 Gopher II (二分匹配)

Gopher II Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6345   Accepted: 2599 Description The gopher family, having averted the canine threat, must face a new predator. The are n gophers and m gopher holes, each at distinct (x, y) coor

[LeetCode] 349 Intersection of Two Arrays &amp; 350 Intersection of Two Arrays II

这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/intersection-of-two-arrays/description/ 350 Intersection of Two Arrays II:https://leetcode.com/problems/intersection-of-two-arrays-ii/description/ 题目&解法

使用华邦的SPI FLASH作为EPCS时固化NIOS II软件报错及解决方案

Altera器件有EPCS系列配置器件,其实,这些配置器件就是我们平时通用的SPIFlash,据AlteraFAE描述:"EPCS器件也是选用某家公司的SPIFlash,只是中间经过Altera公司的严格测试,所以稳定性及耐用性都超过通用的SPIFlash".就本人看来,半导体的稳定性问题绝大部分都是由本身设计缺陷造成的,而成熟的制造工艺不会造成产品的不稳定:并且,现在Altera的器件在读入配置数据发生错误时,可以重新读取SPIFlash里面的数据,所以在工艺的稳定性以及设计的可靠性

hdu 1207 汉诺塔II (DP+递推)

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往

AC日记——小A和uim之大逃离 II 洛谷七月月赛

小A和uim之大逃离 II 思路: spfa: 代码: #include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f struct NodeType { int x,y,k; NodeType(int x_,int y_,int k_):x(x_),y(y_),k(k_){} NodeType(){} }; const int dx[5]={0,-1,0,1,0}; const int dy[5]={0,0,1,0,-