题目:戳这里

题意:有n*m个点全为白色,q个圆,将q个圆内所有的点都染成黑色,问最后剩下多少白色的点。

解题思路:每一行当做一个扫描线,扫描所有的圆,记录每一行在圆中的点即可,O(n*q)。

附ac代码:

 1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <algorithm>
5 #include <string>
6 #include <cmath>
7 using namespace std;
8 const int maxn = 2e5 + 10;
9 struct nod
10 {
11 int x;
12 int y;
13 int r;
14 nod(){}
15 bool operator < (const nod & b) const
16 {
17 if(x == b.x) return y < b.y;
18 return x < b.x;
19 }
20 }nu[maxn],a[maxn];
21 int main()
22 {
23 int t;
24 int n, m, q;
25 scanf("%d", &t);
26 while(t--)
27 {
28 int ans = 0;
29 scanf("%d %d %d", &n, &m, &q);
30 for(int i = 1; i <= q; ++i)
31 {
32 scanf("%d %d %d", &a[i].x, &a[i].y, &a[i].r);
33 }
34 int len = 0;
35 for(int i = 0; i < n; ++i)
36 {
37 len = 0;
38 for(int j = 1; j <= q; ++j)
39 {
40 int u = a[j].r * a[j].r - (a[j].x - i) * (a[j].x - i);
41 if(u < 0) continue;
42 u = sqrt(u);
43 //printf("%d u\n", u);
44 nu[++len].x = max(a[j].y - u, 0);
45 nu[len].y = min(a[j].y + u, m - 1);
46 //printf("%d len %d %d\n", len, nu[len].x, nu[len].y);
47 }
48 if(len == 0) continue;
49 sort(nu + 1, nu + 1 + len);
50 int lt = nu[1].x, rt = nu[1].y;
51 for(int j = 2; j <= len; ++j)
52 {
53 if(nu[j].y < 0) continue;
54 if(nu[j].x >= m) break;
55 if(rt >= nu[j].x)
56 {
57 rt = max(rt,nu[j].y);
58 }
59 else
60 {
61 ans += rt - lt + 1;
62 //printf("%d i %d %d lt %d rt\n", i, ans, lt, rt);
63 lt = nu[j].x;
64 rt = nu[j].y;
65 }
66 }
67 ans += rt - lt + 1;
68 //printf("%d i %d %d lt %d rt\n", i, ans, lt, rt);
69 }
70 printf("%d\n", n * m - ans);
71 }
72 return 0;
73 }

2018ACM上海大都会赛 F Color it【基础的扫描线】的更多相关文章

  1. 【数位dp】Beautiful Numbers @2018acm上海大都会赛J

    目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...

  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 国际大学生程序设计竞赛上海大都会赛

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

  5. 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...

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

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

  7. 2018 ICPC上海大都会赛重现赛 D Thinking-Bear magic (几何)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 D Thinking-Bear magic (几何) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  8. 牛客 Fruit Ninja 2018 ACM 上海大都会赛 (随机化算法)

    题目链接:Fruit Ninja 比赛链接:2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 题目描述 Fruit Ninja is a juicy action game enjoyed ...

  9. [2019上海网络赛F题]Rhyme scheme

    题目链接 题意,求出合法的长度为n的字典序第k小字符串,合法的定义为除了最后一位,每一位的取值范围为'A'到'A'+pos-1,而最后一位的取值范围'A'到当前字符串最大值+1. 队友tql,Orz ...

随机推荐

  1. Windows10下Canvas对象获得屏幕坐标不正确的原因排查与处理

    因为Canvas没有直接将画布内容保存为图片的方法,所以很多时候是通过获得Canvas画布的坐标,然后通过截图的方式来将画布内容保存为本地图片. 如何取得Canvas画布的坐标呢,比较简单实用的方式如 ...

  2. 开源AwaitableCompletionSource,用于取代TaskCompletionSource

    1 TaskCompletionSource介绍 TaskCompletionSource提供创建未绑定到委托的任务,任务的状态由TaskCompletionSource上的方法显式控制,以支持未来的 ...

  3. smtplib.py

    def _print_debug(self, *args): if self.debuglevel > 1: print(datetime.datetime.now().time(), *arg ...

  4. get_or_create update_or_create

    django/query.py at master · django/django https://github.com/django/django/blob/master/django/db/mod ...

  5. 风险识别系统-大数据智能风控管理平台-企业风控解决方案– 阿里云 https://www.aliyun.com/product/saf

    风险识别系统-大数据智能风控管理平台-企业风控解决方案– 阿里云 https://www.aliyun.com/product/saf

  6. By default, the connection will be closed if the proxied server does not transmit any data within 60 seconds.

    WebSocket proxying https://nginx.org/en/docs/http/websocket.html By default, the connection will be ...

  7. Hash Map集合和Hash Set集合

    HashMap集合的使用 1.1.每个集合对象的创建(new) 1.2.从集合中添加元素 1.3.从集合中取出某个元素 1.4.遍历集合 public class HashMapTest { publ ...

  8. linux 下解决mysql root 权限无法远程连接问题

    问题描述:MySQL数据库安装成功后,在服务器本地可以连接成功,但是使用工具navicat无法进行远程连接,如图: 原因:MySQL默认只允许root帐户在本地登录,如果要在其它机器上连接mysql, ...

  9. (十四)整合 ClickHouse数据库,实现数据高性能查询分析

    整合 ClickHouse数据库,实现数据高性能查询分析 1.ClickHouse简介 1.1 数据分析能力 2.SpringBoot整个ClickHouse 2.1 核心依赖 2.2 配属数据源 2 ...

  10. redis防止重复提交

    public interface DistributedLock { boolean getLock(String var1, String var2, int var3);//加锁 void unL ...