2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-F-Color it(暴力)

链接:https://www.nowcoder.com/acm/contest/163/F
来源:牛客网
 

题目描述

There is a matrix A that has N rows and M columns. Each grid (i,j)(0 ≤ i < N, 0 ≤ j < M) is painted in white at first.
Then we perform q operations:
For each operation, we are given (xc, yc) and r. We will paint all grids (i, j) that meets to black.
You need to calculate the number of white grids left in matrix A.

输入描述:

 

The first line of the input is T(1≤ T ≤ 40), which stands for the number of test cases you need to solve.

The first line of each case contains three integers N, M and q (1 ≤ N, M ≤ 2 x 104; 1 ≤ q ≤ 200), as mentioned above.

The next q lines, each lines contains three integers xc, yc and r (0 ≤ xc < N; 0 ≤ yc < M; 0 ≤ r ≤ 105), as mentioned above.

输出描述:

For each test case, output one number.

 

示例1

输入

复制

2
39 49 2
12 31 6
15 41 26
1 1 1
0 0 1

输出

复制

729
0

题意:给你一个n*m的格点,一开始全部是白色的。有q次操作,每次操作给你一个点的坐标和一个半径,使得以该点为圆心的圆所覆盖的所有点全部染成黑色,如果已经是黑色,则还是黑色,不会再变白了!,问你q次操作后还剩多少个点是白色?

题解:我们考虑暴力每一行,对于当前行,暴力q个圆,看每一个圆在这一行所能染的格点数即可。

#include<math.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,m,q;
struct node
{
	int x,y,r;
}a[205];
struct node1
{
	int l,r;
}b[1005];
bool comp(node1 a,node1 b)
{
	if(a.l==b.l)
		return a.r<b.r;
	return a.l<b.l;
}
int main(void)
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int cnt=0,ans=0;
		scanf("%d%d%d",&n,&m,&q);
		for(int i=0;i<q;i++)
			scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);
		for(int i=0;i<n;i++)
		{
			int w,h;cnt=0;
			for(int j=0;j<q;j++)
			{
				if(abs(i-a[j].x)>a[j].r)
					continue;
				w=abs(i-a[j].x);
				h=floor(sqrt(a[j].r*a[j].r-w*w));
				b[++cnt].l=max(0,a[j].y-h);
				b[cnt].r=min(m-1,a[j].y+h);
			}
			sort(b+1,b+cnt+1,comp);
			if(cnt) ans+=b[1].r-b[1].l+1;
			for(int j=2;j<=cnt;j++)
			{
				if(b[j-1].r>=b[j].l)
					b[j].l=b[j-1].r+1;
				if(b[j].r>=b[j].l)
					ans+=b[j].r-b[j].l+1;
				b[j].r=max(b[j].r,b[j-1].r);
			}
		}
		printf("%d\n",n*m-ans);
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值