题意:

在一个 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. 2.1 Spring5源码编译

    一. 准备工作 1. . 编译环境 maven jdk8 idea 2. 编译版本: SpringV5.2.7RELEASE+GradleWapper+jdk1.8.0_131编译 二. 源码下载 g ...

  2. Linux实战(7):centos7安装xrdp

    系统环境:最小化安装,无安装桌面化 操作 yum更新 yum -y update 安装依赖. tigervnc-server.xrdp .GNOME Desktop yum -y install ep ...

  3. Java8学习小记

    转载自https://segmentfault.com/a/1190000006985405 2014年,Oracle发布了Java8新版本.对于Java来说,这显然是一个具有里程碑意义的版本.尤其是 ...

  4. Solon详解(八)- Solon的缓存框架使用和定制

    Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...

  5. springmvc 源码分析(二)-- DiapartcherServlet核心调用流程分析

    测试环境搭建: 本次搭建是基于springboot来实现的,代码在码云的链接:https://gitee.com/yangxioahui/thymeleaf.git 项目结构代码如下: 一: cont ...

  6. selenium3+python3自动化环境搭建

    (我也是小白,刚开始接触自动化,以下内容是我自己在配置环境的时候遇到的问题及解决方法,是后面才记录的要是有什么遗漏或者问题,欢迎帮忙指出来.)1.1首先下载python下载网址:https://www ...

  7. sql注入里关键字绕过的发现

    网上大量文章,甚至<黑客攻防技术实战宝典-WEB实战篇>里面都说一些关键字如 select 等绕过可以用注释符/**/. 例如: select,union.可以用 ,se/**/lect, ...

  8. 2-Java面试-面向对象

    Java面试问题-面向对象 Q1.什么是多态? 多态被简要描述为"一个接口,许多实现".多态性是能够在不同上下文中为某事物赋予不同含义或用法的一种特征-具体来说,就是允许诸如变量, ...

  9. 【3】Java面试-Servlet

    Servlet面试问题 Q1.什么是servlet? Java Servlet是服务器端技术,通过提供对动态响应和数据持久性的支持来扩展Web服务器的功能. javax.servlet和javax.s ...

  10. dirsearch下载与简单实用

    下载 下载地址   我的电脑是Windows,而且我也有python3.6的环境,所以我是直接clone到本地就能使用了.   命令的提示在上面的下载地址里就有,这里给个最简单的命令(脚本小子专属,我 ...