woc居然忘了早上有八连测T T 还好明早还有一场...今天的题除了T3都挺NOIP的...

  T1只需要按横坐标第一关键字,纵坐标第二关键字排序一个一个取就好了...

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio> 
#include<algorithm>
#define ll long long 
using namespace std;
const int maxn=500010,inf=1e9;
struct poi{int x, y;}a[maxn];
int T, n, m, k, ans;
bool v1[maxn], v2[maxn];
void read(int &k)
{
    int f=1;k=0;char c=getchar();
    while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
    k*=f;
}
inline bool cmp(poi a, poi b){return a.x==b.x?a.y<b.y:a.x<b.x;}
int main()
{
    read(T);
    while(T--)
    {
        read(n); read(m); read(k); ans=0;
        for(int i=1;i<=k;i++) read(a[i].x), read(a[i].y), v1[a[i].x]=v2[a[i].y]=0;
        sort(a+1, a+1+k, cmp);
        for(int i=1;i<=k;i++)
            if((!v1[a[i].x])&&(!v2[a[i].y])) ans++, v1[a[i].x]=v2[a[i].y]=1;
        printf("%d\n", ans);
    }
    return 0;
}
View Code

相关文章:

  • 2021-05-20
  • 2022-01-08
  • 2021-06-26
  • 2022-12-23
  • 2022-01-05
  • 2021-10-24
  • 2021-10-21
  • 2021-05-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-10-14
  • 2022-02-12
  • 2021-06-16
  • 2022-12-23
相关资源
相似解决方案