首页 技术 正文
技术 2022年11月15日
0 收藏 664 点赞 3,525 浏览 1963 个字

题目链接:

http://acm.hust.edu.cn/vjudge/problem/87213

Strange Antennas

Time Limit: 3000MS
## 题意
> 一个雷达能够辐射到的范围为等腰三角形,现在给你雷达的坐标,辐射范围和方向,问你求被奇数个雷达辐射到的网格有多少个。

题解

首先,雷达是建在交叉点上的,而考虑覆盖范围是在网格上的,所以需要坐标转换(题目样例第四行有错,应为1,5,4,0)。

其次我们可以考虑每一行都做一遍,然后枚举每个雷达对这一行的影响,没个雷达对这一行的影响就变成了一个区间,这样会变成区间覆盖问题,我们要求的就是覆盖奇数次的区间的长度。这个问题可以用扫描线+离散化来做。(具体看代码)

时间复杂度:O(nmlogm)

代码

#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;//start----------------------------------------------------------------------const int maxm=111;
const int maxn=30101;int n,m;struct Node {
int x,y,p,d;
} nds[maxm];int main() {
while(scanf("%d",&n)==1) {
scanf("%d",&m);
rep(i,0,m) {
scanf("%d%d%d%d",&nds[i].x,&nds[i].y,&nds[i].p,&nds[i].d);
if(nds[i].d==0) nds[i].y--;
else if(nds[i].d==2) nds[i].x--;
else if(nds[i].d==3) nds[i].x--,nds[i].y--;
}
int ans=0;
rep(i,0,n) {
VPII arr;
rep(j,0,m) {
int l=INF,r=-1,len;
Node& e=nds[j];
if(e.d==2) {
if(i>e.x-e.p&&i<=e.x) {
len=e.p-(e.x-i);
l=e.y;
r=l+len;
}
} else if(e.d==3) {
if(i>e.x-e.p&&i<=e.x) {
len=e.p-(e.x-i);
r=e.y+1;
l=r-len;
}
} else if(e.d==0) {
if(i<e.x+e.p&&i>=e.x) {
len=e.p-(i-e.x);
r=e.y+1;
l=r-len;
}
} else if(e.d==1) {
if(i<e.x+e.p&&i>=e.x) {
len=e.p-(i-e.x);
l=e.y;
r=l+len;
}
}
l=max(0,l);
r=min(r,n);
if(l<r){
arr.push_back(mkp(l, 1));
arr.push_back(mkp(r,-1));
}
}
sort(all(arr));
int cnt=0,res=0;
rep(j,0,arr.size()) {
if(cnt&1){
res+=arr[j].X-arr[j-1].X;
}
cnt+=arr[j].Y;
}
ans+=res;
}
printf("%d\n",ans);
}
return 0;
}//end-----------------------------------------------------------------------
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,033
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862