网格黑白染色(思维)

题目链接

#include <iostream>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstring>
#include <assert.h>
#include <functional>
#define  lowbit(x) (x&(-x))
#define  ll long long
#define  ull unsigned long long
#define  max(a,b) (a>b?a:b)
#define  min(a,b) (a>b?b:a)
#define  PI acos(-1.0)
#define  fir first
#define  sec second
#define  SZ(x) (x.size())
#define  inf 0x3f3f3f3f
#define  pb push_back
#define  MP make_pair
#define  all(x) (x).begin(),(x).end()
#define  PII pair<int,int>
#define  E 2.7182818284590452353602874713527
using namespace std;

/**********************************************Head-----Template****************************************/
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
/********************************Head----Template**********************************************/
const ll mod = 1e9+7;
ll ksm(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}

const int maxn = 2e2+7;
struct node {
	int x,y,r;
}a[maxn];

vector<pair<int,int> >vec;
bool cmp(PII a,PII b){
	if(a.fir==b.fir) return a.sec<b.sec;
	return a.fir<b.fir;
}

int main (){
	int t;read(t);
	while(t--){
		int n,m,q;read(n),read(m),read(q);
		for(int i=1;i<=q;i++) read(a[i].x),read(a[i].y),read(a[i].r);
		ll ret=0;
		for(int i=0;i<n;i++){
			int w,h;vec.clear();
			for(int j=1;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)));
				vec.pb(MP(max(0,a[j].y-h),min(m-1,a[j].y+h)));
			}
			sort(all(vec),cmp);
			int sz=SZ(vec);
			if(sz) ret+=vec[0].sec-vec[0].fir+1;
			for(int j=1;j<sz;j++) {
				if(vec[j].fir<=vec[j-1].sec) vec[j].fir=vec[j-1].sec+1;
				if(vec[j].sec>=vec[j].fir) ret+=vec[j].sec-vec[j].fir+1;
				vec[j].sec=max(vec[j].sec,vec[j-1].sec);
			}
		}
		cout<<1ll*n*m-ret<<endl;
	}
	return 0;
}
/**
题意:给定n*m网格,初始颜色为白色,对其部分网格进行染色,每次染色区域是以(x,y)为圆点,r为半径,问最后白色格子的个数

时间复杂度:T*n*q*logq;

分析:考虑每一列,对于所有染色的点区域,记录该区域所能到达当前列的最高的位置和最低的位置,最后输出即可

*/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值