题意:一个N*M的矩形,每个点初始都是白色的,有Q次操作,每次操作将以(x,y)为圆心,r为半径的区域涂成黑点。求最后剩余白色点数。

分析:对每行,将Q次操作在该行的涂色视作一段区间,那么该行最后的白色点数即列数-区间覆盖的总长度。这就转化成了扫描线的问题。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn =1e4+;
struct Circle{
LL x,y,r;
}p[maxn];
struct Node{
LL l,r;
bool operator <(const Node & p ) const{
if(l==p.l) return r>p.r;
return l<p.l;
}
}; vector<Node> vz; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int T;scanf("%d",&T);
while(T--){
LL N,M,Q;
scanf("%lld%lld%lld",&N,&M,&Q);
LL ans = N*M;
for(int i =;i<Q;++i) scanf("%lld%lld%lld",&p[i].x,&p[i].y,&p[i].r);
for(int i=;i<N;++i){
vz.clear();
for(int j=;j<Q;++j){
LL delx = abs(i-p[j].x);
if(delx>p[j].r) continue;
LL range = (LL)sqrt(p[j].r*p[j].r-delx*delx);
LL l = max((LL),p[j].y-range);
LL r = min(M-,p[j].y+range);
vz.push_back((Node){l,r});
}
sort(vz.begin(),vz.end());
int sz = vz.size();
LL r = -,tot = ;
for(int j=;j<sz;++j){
if(vz[j].r<=r) continue;
if(vz[j].l>r) r = vz[j].l;
else tot--;
tot += vz[j].r -r +;
r = vz[j].r;
}
ans -=tot;
}
printf("%lld\n",ans);
}
return ;
}

2018 ACM 国际大学生程序设计竞赛上海大都会 F - Color it (扫描线)的更多相关文章

  1. 2018 ACM 国际大学生程序设计竞赛上海大都会部分题解

    题目链接 2018 ACM 国际大学生程序设计竞赛上海大都会 下午午休起床被同学叫去打比赛233 然后已经过了2.5h了 先挑过得多的做了 .... A题 rand x*n 次点,每次judge一个点 ...

  2. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it

    链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...

  3. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...

  4. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  5. 2018 ACM 国际大学生程序设计竞赛上海大都会赛

    传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...

  6. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)

    题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...

  7. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D

    A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...

  8. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-B-Perfect Numbers(完数)

    题目描述 We consider a positive integer perfect, if and only if it is equal to the sum of its positive d ...

  9. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-K-Matrix Multiplication(矩阵乘法)

    题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a m ...

随机推荐

  1. pl/sql 实例精解 04

    本章主要讨论, IF 语句的应用. 1: if condition1 then 2: statement1 3: elsif condition2 then 4: statement2 5: else ...

  2. jfinal_BLOG v1.0

    http://git.oschina.net/fleam/jfinal_AmazeUI

  3. Oracle 10gR2 RAC 启动与关闭

    一. 检查共享设备 一般情况下, 存放OCR 和 Voting Disk 的OCFS2 或者raw 都是自动启动的. 如果他们没有启动,RAC 肯定是启动不了的. 1.1 如果使用ocfs2的,检查o ...

  4. 【SR】正则化超分辨率复原

    正则化超分辨率图像重建算法研究--中国科学技术大学 硕士学位论文--路庆春 最大后验概率(MAP)的含义就是在低分辨率图像序列已知的前提下,使高分辨率图像出现的概率达到最大.

  5. SR领域文献资源汇总(链接地址)

    DRCN http://www.drcn.org/   The International Workshop on Design of Reliable Communication Networks ...

  6. flask渲染模板

    Flask自身使用了jinja2模板,可以使用render_template()方法来渲染模板,只需要将模板名和关键字的参数传入. 该渲染模板的模块(views.py)会在 templates 文件夹 ...

  7. springMVC的url-pattern /和/*的区别

    总之,关于web.xml的url映射的小知识: <url-pattern>/</url-pattern> 会匹配到/login这样的路径型url,不会匹配到模式为*.jsp这样 ...

  8. [LintCode] 合并排序数组

    A subroutine of merge sort. class Solution { public: /** * @param A and B: sorted integer array A an ...

  9. [Algorithms] Longest Common Substring

    The Longest Common Substring (LCS) problem is as follows: Given two strings s and t, find the length ...

  10. 160728、Spark Streaming kafka 实现数据零丢失的几种方式

    定义 问题开始之前先解释下流处理中的一些概念: At most once - 每条数据最多被处理一次(0次或1次) At least once - 每条数据最少被处理一次 (1次或更多) Exactl ...