码迷,mamicode.com
首页 > Web开发 > 详细

<html>

时间:2017-08-15 13:27:34      阅读:611      评论:0      收藏:0      [点我收藏+]

标签:ddr   post   orange   hit   point   操作   基本   ase   scan   

题目链接:uva 1517 - Tracking RFIDs

题目大意:给定S,R。W,P。表示有R个传感器,感应半径为R。W堵墙。P个产品。给定S个传感器的位置,W堵墙的位置(两端点),以及P个产品的位置。

输出每一个产品能够被那些传感器确定位置。假设传感器和产品之间隔着k堵墙。则距离要加上k。

解题思路:S个数非常大,可是R非常小,所以枚举每一个产品周围坐标加减R的距离范围内的点。推断是否存在传感器,假设存在推断距离是否满足。推断距离的时候要枚举墙的位置,推断两条线段是否相交。利用向量叉积的性质推断就可以。

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

using namespace std;
typedef long long ll;

struct point {
    int x, y;
    point (int x = 0, int y = 0) {
        this->x = x;
        this->y = y;
    }

    point operator + (const point& u) {
        return point(x + u.x, y + u.y);
    }
    point operator - (const point& u) {
        return point(x - u.x, y - u.y);
    }
    int operator ^ (const point& u) {
        return x * u.y - y * u.x;
    }
    bool operator < (const point& u) const {
        if (x != u.x)
            return x < u.x;
        return y < u.y;
    }
};
typedef pair<point, point> line;

int S, R, W, P;
set<point> pset;
vector<line> pline;

void init () {
    pset.clear();
    pline.clear();
    scanf("%d%d%d%d", &S, &R, &W, &P);

    point u, v;
    for (int i = 0; i < S; i++) {
        scanf("%d%d", &u.x, &u.y);
        pset.insert(u);
    }

    for (int i = 0; i < W; i++) {
        scanf("%d%d%d%d", &u.x, &u.y, &v.x, &v.y);
        pline.push_back(make_pair(u, v));
    }
}

bool check (point a, point b, point c, point d) {
    if (max(a.x, b.x) < min(c.x, d.x) ||
        max(a.y, b.y) < min(c.y, d.y) ||
        min(a.x, b.x) > max(c.x, d.x) ||
        min(a.y, b.y) > max(c.y, d.y) )
        return false;

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

bool judge (point u, int x, int y) {
    if (x * x + y * y > R * R)
        return false;
    point v = u + point(x, y);

    if (!pset.count(v))
        return false;

    int cnt = 0;
    for (int i = 0; i < W; i++) {
        if (check(u, v, pline[i].first, pline[i].second))
            cnt++;
    }
    if (cnt > R)
        return false;
    return x * x + y * y <= (R - cnt) * (R - cnt);
}

void solve () {
    point u;
    vector<point> ans;

    for (int i = 0; i < P; i++) {
        ans.clear();
        scanf("%d%d", &u.x, &u.y);

        for (int x = -R; x <= R; x++) {
            for (int y = -R; y <= R; y++) {
                if (judge(u, x, y))
                    ans.push_back(u + point(x, y));
            }
        }

        sort(ans.begin(), ans.end());
        printf("%lu", ans.size());
        for (int i = 0; i < ans.size(); i++)
            printf(" (%d,%d)", ans[i].x, ans[i].y);
        printf("\n");
    }
}

int main () {
    int cas;
    scanf("%d", &cas);
    while (cas--) {
        init();
        solve();
    }
    return 0;
}
版权声明:本文为博主原创文章,未经博主同意不得转载。 举报
  • 本文已收录于下面专栏:

相关文章推荐

[UVA512]Spreadsheet Tracking[模拟][STL]

题目链接:[UVA512]Spreadsheet Tracking[模拟][STL] 题意分析:给出一个电子表格,进行若干次操作。然后进行若干次询问,每次询问输出单元格内容从哪里变到哪里。没有则输出...

uva 10641 - Barisal Stadium(dp+几何)

题目链接:uva 10641 - Barisal Stadium 题目大意:依照顺时针给出操场的

UVA 1342 That Nice Euler Circuit(二维几何基础)

UVA 1342 That Nice Euler Circuit(二维几何基础) <a target="_blank" href="http://uva.onlinejudge.org/index.php?

option=com_onlinejudge&amp;Itemid=8&am

UVA - 512 Spreadsheet Tracking

#include #include #include using namespace std; struct ins{ string s; int k=0,a[20]={0},r...
  • 技术分享
  • xyqcl
  • 2014-10-12 21:00
  • 515

uva 1517 - Tracking RFIDs(STL+几何)

<a target="_blank" href="http://uva.onlinejudge.org/index.p

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

UVALive - 5908(UVA1517)Tracking RFIDs(暴力) 题目链接 题目大意:给你S个传感器,然后每一个传感器的感应半径是R,有W堵墙,已经传感器的感应范围会由于碰...

uva 11123 - Counting Trapizoid(容斥+几何)

<a target="_blank" href="http://uva.online

CodeForcesGym 100729I Tracking RFIDs

题意:给你s个传感器的坐标,全部传感器的接收半径都为r,有w条线段。穿过线段传感器的接收半径会减一 ? ?然后有p个询问,每次给你一个点,问有多少个传感器能接收到该点的信号 因为半径非常小,并且传感器之...

uva 11991 - Easy Problem from Rujia Liu?(STL)

<a target="_blank" href="http://uva.onlinejudge.org/index.p

UVALive 5908 Tracking RFIDs(计算几何+数据结构,暴力也可过)

A -?Tracking RFIDs Time Limit:3000MS?????Memory Limit:0KB?????64bit IO Format:%lld & %llu Submit...
  • 微博
    微信
    QQ
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多仅仅同意输入30个字)

技术分享

<html>

标签:ddr   post   orange   hit   point   操作   基本   ase   scan   

原文地址:http://www.cnblogs.com/yxysuanfa/p/7364464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
分享档案
周排行
mamicode.com排行更多图片
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!