set:
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
struct point
{
int x,y;
point(int _x, int _y):x(_x),y(_y){}
bool operator < (const point &p) const
{
if(x == p.x) return y < p.y;
return x < p.x;
}
};
set<point> s;
bool istrue(int x, int y)
{
if(s.find(point(x,y))!= s.end()) return true;
return false;
}
int n, x, y;
int ans[10];
int main()
{
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> x >> y;
s.insert(point(x,y));
}
set<point>::iterator it;
for(it = s.begin(); it != s.end(); it++)
{
int nx = (*it).x;
int ny = (*it).y;
if(istrue(nx,ny-1) && istrue(nx-1,ny) && istrue(nx + 1,ny) && istrue(nx,ny+1))
{
int cont = 0;
if(istrue(nx-1,ny+1)) cont++;
if(istrue(nx+1,ny+1)) cont++;
if(istrue(nx-1,ny-1)) cont++;
if(istrue(nx+1,ny-1)) cont++;
ans[cont]++;
}
}
for(int i = 0; i <= 4; i++)
{
cout << ans[i] << endl;
}
return 0;
}
pair
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
const int N = 1000;
pair<int,int> p[N];
int ans[10]; // 存放结果
map<pair<int, int>,int> ps;
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
p[i] = make_pair(x,y);
ps[p[i]] = 1;
}
for(int i = 0; i < n; i++)
{
int x = p[i].first;
int y = p[i].second;
if(ps[make_pair(x,y-1)] && ps[make_pair(x,y+1)] && ps[make_pair(x+1,y)] && ps[make_pair(x-1,y)])
{
int cont = 0;
if(ps[make_pair(x-1,y+1)]) cont++;
if(ps[make_pair(x-1,y-1)]) cont++;
if(ps[make_pair(x+1,y+1)]) cont++;
if(ps[make_pair(x+1,y-1)]) cont++;
ans[cont]++;
}
}
for(int i = 0; i <=4; i++)
{
cout << ans[i] << endl;
}
return 0;
}
太欠缺了 stl都吃不透还好意思说自己写算法喜欢用c++ 害 太丢人了