题意:

在一个 n x n 的平面上,给定 m 个等腰直角三角形(各点均为整数),问该平面上被三角形覆盖奇数次的点有多少个。

思路:

由于 n 较大,不能模拟解决,故使用离散化思想。

考虑每一行有多少点被覆盖了奇数次,题目从二维转换成一维。

对于每一行,考虑每个三角形在此行覆盖的线段,记录下每条线段的左端点 l 、右端点 r 保存在同一个数组中。

排序后则容易知道第一个到第二个数、第三到第四个数...的部分是覆盖奇数次,以此累加结果。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct Radar
{
int x, y, w, d;
} radars[105];
int dir[4][2]= {{1, -1}, {1, 1}, {-1, 1}, {-1, -1}}; int main()
{
int n, m, ans=0;
while(cin>>n>>m)
{
ans=0;
for(int i=0; i<m; ++i)
{
cin>>radars[i].x>>radars[i].y>>radars[i].w>>radars[i].d;
/*if(radars[i].d==0) radars[i].y--;
if(radars[i].d==2) radars[i].x--; //uva数据有误,此处处理错误数据
if(radars[i].d==3) radars[i].x--, radars[i].y--;*/
}
for(int i=0; i<n; ++i)
{
int cnt=0, v[202]= {0};
for(int j=0; j<m; ++j)
{
if(radars[j].d<=1 && radars[j].x>i) continue;
if(radars[j].d>1 && radars[j].x<i) continue;
if(abs(radars[j].x-i) >= radars[j].w) continue;
int l=radars[j].y + dir[radars[j].d][1] * (radars[j].w - abs(radars[j].x - i) - 1);
int r=radars[j].y;
if(l>r) swap(l, r);
l--;
l=max(-1, l);
r=min(r, n-1);
v[cnt++]=l, v[cnt++]=r;
}
sort(v, v+cnt);
for(int j=1; j<cnt; j+=2)
ans+=v[j]-v[j-1];
}
cout<<ans<<endl;
}
return 0;
}

uvalive6468,51cthink1419 Strange Antennas (离散化)的更多相关文章

  1. UVALive - 6864 Strange Antennas 扫描线

    题目链接: http://acm.hust.edu.cn/vjudge/problem/87213 Strange Antennas Time Limit: 3000MS 题意 一个雷达能够辐射到的范 ...

  2. 扫描线 - UVALive - 6864 Strange Antennas

    Strange Antennas Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=87213 M ...

  3. Gym 101470 题解

    A:Banks 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt&q ...

  4. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  5. CodeForces - 55D(数位dp,离散化)

    题目来源:http://codeforces.com/problemset/problem/55/D Volodya is an odd boy and his taste is strange as ...

  6. Codeforces 777E(离散化+dp+树状数组或线段树维护最大值)

    E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  7. CodeForces - 55D - Beautiful numbers(数位DP,离散化)

    链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...

  8. Codeforces #55D (数位dp+离散化)

    Description Volodya is an odd boy and his taste is strange as well. It seems to him that a positive ...

  9. NBUT 1457 莫队算法 离散化

    Sona Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Submit Status Practice NBUT 145 ...

随机推荐

  1. C#开发PACS医学影像处理系统(十八):Dicom使用LUT色彩增强和反色

    在医生阅片确诊的过程中,当发线疑似病灶时在灰度显示下有时并不清晰,这时候就需要色彩增强效果来使灰度图像变为彩色图像. LUT可以简单的理解为0-255的颜色映射值,例如:彩虹编码,将其打包成LUT格式 ...

  2. spring boot 源码之SpringApplicationRunListeners

    SpringApplicationRunListeners SpringApplicationRunListener的集合,内部存储了SpringApplicationRunListener的集合,提 ...

  3. MyBatis常用实现方式

    MyBatis 是一个优秀的基于 java 的持久层框架,它内部封装了 jdbc,使开发者只需要关注 sql 语句本身,而不需要花费精力去处理加载驱动.创建连接.创建 statement 等繁杂的过程 ...

  4. 1.8HDFS细节

  5. Depthwise Separable Convolution(深度可分离卷积)的实现方式

    按照普通卷积-深度卷积-深度可分离卷积的思路总结. depthwise_conv2d来源于深度可分离卷积,如下论文: Xception: Deep Learning with Depthwise Se ...

  6. noSql 的应用场景简述

    选型一定要结合实际情况而不是照本宣科,比如: 企业发展之初,明明一个关系型数据库就能搞定且支撑一年的架构,搞一套大而全的技术方案出来 有一些数据条件查询多,更适合使用ElasticSearch做存储降 ...

  7. Centos-目录或文件拷贝-cp

    cp 拷贝或者备份文件或者目录 相关选项 -a 拷贝目录保存文件所有信息 -r  递归拷贝目录 -d 保留连接 -p 保留修改时间和存取权限 -i 有同名提醒是否覆盖 相关应用 1. 备份文件 cp ...

  8. Centos-内核核心组成

    linux内核,相当于linux大脑,高可靠和高稳定都是针对内核来说 完整linux核心组成部分 1. 内存管理 合理有效的管理整个系统的物理内存,同时快速响应内核各子系统对内存分配的请求 2. 进程 ...

  9. Jetson AGX Xavier/ubuntu查找文件

    用以下命令查找文件 sudo updatedb locate xxx #xxx是文件名 如果找不到命令,则需要安装mlocate sudo apt-get install mlocate

  10. SQL审核平台Yearning部署

    SQL审核平台Yearning部署  Yearning优势: Yearning SQL 审计平台 基于Vue.js与Django的整套mysql-sql审核平台解决方案.提供基于Inception的S ...