UVALive - 5908(UVA1517)Tracking RFIDs(暴力)

题目链接

题目大意:给你S个传感器,然后每个传感器的感应半径是R,有W堵墙,已经传感器的感应范围会因为碰到一堵墙而减少1,那么如果这个感应器和某个物品中间有N堵墙的话,感应范围就变为R - N。给你P个物品,要求你求出每个物品可以被哪些感应器感应到。

解题思路:因为这题的S很大,P比较小,而且传感器的位置都是整数点的,那么枚举每个产品的周围不大于R的整数点(最多2?R?2?R).然后判断两点之间有没有墙用向量的差积。复杂度:10000
40 40 * 10.加上极端的数据可能没有,所以还是可以接受的。set的效率比map要快好多。

代码:

#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

const int N = 1e4 + 5;
typedef long long ll;

int S, R, W, P;

struct Point {

    int x, y;
    Point (int x = 0, int y = 0) : x(x) , y(y) {}
    bool operator < (const Point &a) const {

        return a.x == x ? y < a.y : x < a.x;
    }

    Point operator - (const Point &a) const {

        Point ans;
        ans.x = x - a.x;
        ans.y = y - a.y;
        return ans;
    }

    Point operator + (const Point &a) const {

        Point ans;
        ans.x = x + a.x;
        ans.y = y + a.y;
        return ans;
    }

    int operator ^ (const Point &a) const {

        return x * a.y - y * a.x;
    }
};

struct Line {

    Point b, e;
    void init (int bx = 0, int by = 0, int ex = 0, int ey = 0) {
        b.x = bx;
        b.y = by;
        e.x = ex;
        e.y = ey;
    }
}l[15];

vector<Point> p;
set<Point> vis;

ll dis (Point a, Point b) {

    ll dx = a.x - b.x;
    ll dy = a.y - b.y;
    return dx * dx + dy * dy;
}

bool check (Point a, Point b, Point c, Point d) {

    if (min (a.x, b.x) > max (c.x, d.x) ||
        min (a.y, b.y) > max (c.y, d.y) ||
        min (c.x, d.x) > max (a.x, b.x) ||
        min (c.y, d.y) > max (a.y, b.y))
        return false;

    ll i = (a - b) ^ (a - c);
    ll j = (a - b) ^ (a - d);
    ll k = (c - d) ^ (c - a);
    ll l = (c - d) ^ (c - b);
    return i * j <= 0 && k * l <= 0;
}

bool judge (Point a, Point b) {

    if (vis.find(a) == vis.end())
        return false;

    ll d = dis (a, b);
    if (d > R * R)
        return false;

    int cnt = 0;
    for (int i = 0; i < W; i++)
        if (check(a, b, l[i].b, l[i].e))
            cnt++;

    if (cnt > R)
        return false;
    return d <= (R - cnt) * (R - cnt);
}

int main () {

    int T;
    int x, y;
    Point tmp;
    scanf ("%d", &T);
    while (T--) {

        scanf ("%d%d%d%d", &S, &R, &W, &P);
        vis.clear();

        for (int i = 0; i < S; i++) {
            scanf ("%d%d", &tmp.x, &tmp.y);
            vis.insert (tmp);
        }

        int bx, by, ex, ey;
        for (int i = 0; i < W; i++) {

            scanf ("%d%d%d%d", &bx, &by, &ex, &ey);
            l[i].init(bx, by, ex, ey);
        }

        Point a;
        int d;
        for (int i = 0; i < P; i++) {

            p.clear();
            scanf ("%d%d", &tmp.x, &tmp.y);
            for (int j = -R; j <= R; j++) {
                d = sqrt (R * R - j * j);
                for (int k = max (-R, -d) ; k <= min (R, d); k++) {

                    a.x = tmp.x + j;
                    a.y = tmp.y + k;
                    if (judge(a, tmp))
                        p.push_back (a);
                }
            }

            printf ("%d", p.size());
            for (int j = 0; j < p.size(); j++)
                printf (" (%d,%d)", p[j].x, p[j].y);
            printf ("\n");
        }
    }
    return 0;
}
时间: 2024-07-31 06:45:27

UVALive - 5908(UVA1517)Tracking RFIDs(暴力)的相关文章

uva 1517 - Tracking RFIDs(STL+几何)

题目链接:uva 1517 - Tracking RFIDs 题目大意:给定S,R,W,P,表示有R个传感器,感应半径为R,W堵墙,P个产品,给定S个传感器的位置,W堵墙的位置(两端点),以及P个产品的位置.输出每个产品可以被那些传感器确定位置.如果传感器和产品之间隔着k堵墙,则距离要加上k. 解题思路:S个数很大,但是R很小,所以枚举每个产品周围坐标加减R的距离范围内的点,判断是否存在传感器,如果存在判断距离是否满足,判断距离的时候要枚举墙的位置,判断两条线段是否相交,利用向量叉积的性质判断即

UVaLive 7457 Discrete Logarithm Problem (暴力)

题意:求一个x使得 a^x%p = b p为素数: 析:从1开始扫一下就好,扫到p-1就可以了,关键是这个题为什么要用文件尾结束,明明说是0,但是不写就WA... 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #incl

UVALive 6585 &amp;&amp; Gym 100299F Draughts (暴力+回溯)

题意:给定一个 10*10的矩阵,每一个W可以跳过一个B向对角走到#并把B吃掉,并且可以一直跳直到不能动为止,现在是W走的时候,问你最多吃几个B. 析:直接暴力+回溯,深搜就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath&g

UVALive - 6185 Find the Outlier暴力填表+高斯消元+卡eps

https://cn.vjudge.net/problem/UVALive-6185 我真的是服了orz eps 1e5,1e6过不了 开1e2 1e1都能过 题意:给你一个d阶多项式f的f(0),f(1)...f(d+1),f(d+2) 有一个是错误的,问第几个是错的 题解:题目多给了两个方程(约束). 想了一下如果只给一个,是找不出来的. 给两个的话,可以这么考虑: 先取出一个方程X,再取剩下的n个高斯消元一下,将解得的系数带入最后一个方程,if成立,说明X是错的,else再取另一个(说明错

关于10月15日#5的四道图论题的心得与感悟

还是我,接着补..... 第一题:UVA 10943 送分题,几乎是动规入门的例题 第二题:UVA 11584 Partitioning by Palindromes .关于在字符串中寻找回文串,一开始的直观想法是先预处理再利用类似于线段覆盖的手法处理.但是两者之间存在差别.还是只有老老实实利用动规求解. 第三题:UVALive 6270一开始想暴力模拟后找规律,结果暴力没写出来.在手推的时候,经人指点,发现了规律F[i] = F[i - 1] + F[i - 2].过后才发现是斐波拉契数列.

Gym 100299C &amp;&amp; UVaLive 6582 Magical GCD (暴力+数论)

题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点时,我们对gcd相同的只保留一个,那就是左端点最小的那个,只有这样才能保证是最大,然后删掉没用的. UVaLive上的数据有问题,比赛时怎么也交不过,后来去别的oj交就过了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&qu

UVALive 6163(暴力枚举)

这道题我的做法就是枚举这四个数的所有排列所有运算所有计算顺序. 略有考验代码能力,不能漏掉情况,注意模块化的思想,一些功能写成函数调试的时候结构清晰好分析. 比赛时没有AC是对next_permutation()函数理解的不透,根本没有想到是没有从最小字典序开始枚举的问题. 就是next_permutation()函数是从当前顺序枚举到字典序最大的,而我开始时do里面的a数组不一定是字典序最小的,但是next_permutation()函数一定是从当前字典序往最大的枚举,所以漏掉了字典序很小的那

UVaLive 3401 Colored Cubes (暴力)

题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostrea

UVALive 2145 Lost in Space(暴力)

题目并不难,就是暴力,需要注意一下输出形式和精度. #include<iostream> #include<cstdio> #include<cmath> using namespace std; #define maxn 100 #define jd 0.0001 double x[maxn],y[maxn],z[maxn],d,e,f; double getdis(double x,double y,double z,double x1,double y1,doub