题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
using namespace std;
const int N = 1010;
struct Node
{
int x;
int y;
int flag;
int count;
}node[N];
int cnt[5];
int n;
bool fl(int x1,int y1,int x2,int y2)
{
if((x2 == x1 && y2 == y1 - 1) || (x2 == x1 && y2 == y1 + 1) || (x2 == x1 + 1 && y2 == y1) || (x2 == x1 - 1 && y2 == y1))
{
return true;
}
else
{
return false;
}
}
bool f(int x1,int y1,int x2, int y2)
{
if((x2 == x1 - 1 && y2 == y1 - 1) || (x2 == x1 - 1 && y2 == y1 + 1) || (x2 == x1 + 1 && y2 == y1 + 1) || (x2 == x1 + 1 && y2 == y1 - 1))
{
return true;
}
else
{
return false;
}
}
int main()
{
cin>>n;
for(int i = 1;i <= n;i++)
{
int x,y;
cin>>x>>y;
node[i].x = x;
node[i].y = y;
node[i].count = 0;
}
for(int i = 1;i <= n;i++)
{
int re = 0;
for(int j = 1;j <= n;j++)
{
if(fl(node[i].x, node[i].y, node[j].x, node[j].y))
{
if(re == 4)
{
break;
}
re++;
}
}
if(re == 4)
{
node[i].flag = 1;
}
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
if(node[i].flag)
{
if(f(node[i].x, node[i].y, node[j].x, node[j].y))
{
node[i].count++;
}
}
}
}
for(int i = 1;i <= n;i++)
{
if(node[i].flag)
{
cnt[node[i].count]++;
}
}
for(int i = 0;i < 5;i++)
{
cout<<cnt[i]<<endl;
}
}