a_set.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <set>
#include <cstdio>
#define maxn 1000100
using namespace std;

int n,ans = 0;
set<int> a[maxn];

int main(){
int x,y;
cin >> n;
for (int i=1;i<=n;i++){
scanf("%d%d",&x,&y);
if(a[y].find(x)==a[y].end() && a[y].find(x+1)==a[y].end()){
a[y].insert(x);
a[y].insert(x+1);
ans++;
}
}
cout << ans;
}

a_map.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
struct node{
int x,y;
bool operator<(const node &b)const
{
if(x==b.x)
return y<b.y;
else
return x<b.x;
}
}a[maxn],b[maxn];
int n;
map <node,int> s;
int main(){
cin>>n;
int num = 0;
for (int q=1;q<=n;q++){
int x,y;
cin>>x>>y;
if (s[(node){x,y}]!=1&&s[(node){x-1,y}]!=1&&s[(node){x+1,y}]!=1){
num++;
s[(node){x,y}]=1;
}
}
cout<<num<<endl;
return 0;
}