YbtOj NOIP2020 模拟赛 B 组 Day8 T1 机房惨案

R e s u l t Result Result

...


H y p e r l i n k Hyperlink Hyperlink

https://www.ybtoj.com.cn/contest/62/problem/1


D e s c r i p t i o n Description Description

n n n个点,打掉一个点可以把它右边和它上边的所有点打掉,问打掉所有点至少需要打多少次

数据范围: n ≤ 1 0 5 n\leq 10^5 n105


S o l u t i o n Solution Solution

排序之后依次打即可,可以证明这是最优的

复杂度 O ( T q log ⁡ q ) O(Tq\log q) O(Tqlogq) q q q就是上文中的 n n n


C o d e Code Code
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;int n,m,q,T,ans;
struct node{int x,y;}p[100010];
bool bjx[100010],bjy[100010];
inline bool cmp(node x,node y){return x.x<y.x||x.x==y.x&&x.y<y.y;}
inline bool cnp(node x,node y){return x.y<y.y||x.y==y.y&&x.x<y.x;}
inline LL read()
{
	char c;LL d=1,f=0;
	while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
	while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
	return d*f;
}
signed main()
{
	freopen("iakioi.in","r",stdin);
	freopen("iakioi.out","w",stdout);
	T=read();
	while(T--)
	{
		memset(bjx,0,sizeof(bjx));memset(bjy,0,sizeof(bjy));
		n=read();m=read();q=read();
		for(register int i=1;i<=q;i++) p[i].x=read(),p[i].y=read();
		ans=0;
		sort(p+1,p+1+q,cmp);
		for(register int i=1;i<=q;i++)
		{
			if(bjx[p[i].x]||bjy[p[i].y]) continue;
			bjx[p[i].x]=bjy[p[i].y]=true;
			ans++;
		}
		sort(p+1,p+1+q,cnp);
		for(register int i=1;i<=q;i++)
		{
			if(bjx[p[i].x]||bjy[p[i].y]) continue;
			bjx[p[i].x]=bjy[p[i].y]=true;
			ans++;
		}
		printf("%d\n",ans);
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值