面对这道题,要保持自信。不用STL也可以解决,估量一下循环的代价是大还是小,不大的话就大胆做,这道题最多也就1000个点,不能怂。
满分代码(十分易懂):
#define _CRT_SECURE_NO_WARNINGS //如果scanf问题没处理好就加上
#include <bits/stdc++.h>
typedef struct {
long x;
long y;
int count;
int score;
}locate;
locate trash[1010];
int n;
void isUp(int j, long x,long y)
{
if (x==0||y==0)
return ;
for (int i = 0; i < n; i++)
{
if (i != j)
{
if (trash[i].x == x)
{
if (trash[i].y == y + 1)
{
trash[j].count += 1;
return;
}
}
}
}
return ;
}
void isDown(int j, long x, long y)
{
if (x == 0 || y == 0)
return;
for (int i = 0; i < n; i++)
{
if (i != j)
{
if (trash[i].x == x)
{
if (trash[i].y == y - 1)
{
trash[j].count += 1;
return;
}
}
}
}
return;
}
void isLeft(int j, long x, long y)
{
if (x == 0 || y == 0)
return;
for (int i = 0; i < n; i++)
{
if (i != j)
{
if (trash[i].y == y)
{
if (trash[i].x == x - 1)
{
trash[j].count += 1;
return;
}
}
}
}
return;
}
void isRight(int j, long x, long y)
{
if (x == 0 || y == 0)
return;
for (int i = 0; i < n; i++)
{
if (i != j)
{
if (trash[i].y == y)
{
if (trash[i].x == x + 1)
{
trash[j].count += 1;
return;
}
}
}
}
return;
}
void is1(int j, long x, long y)
{
if (x == 0 || y == 0)
return;
for (int i = 0; i < n; i++)
{
if (i != j)
{
if (trash[i].y == y + 1)
{
if (trash[i].x == x + 1)
{
trash[j].score += 1;
return;
}
}
}
}
return;
}
void is2(int j, long x, long y)
{
if (x == 0 || y == 0)
return;
for (int i = 0; i < n; i++)
{
if (i != j)
{
if (trash[i].y == y + 1)
{
if (trash[i].x == x - 1)
{
trash[j].score += 1;
return;
}
}
}
}
return;
}
void is3(int j, long x, long y)
{
if (x == 0 || y == 0)
return;
for (int i = 0; i < n; i++)
{
if (i != j)
{
if (trash[i].y == y - 1)
{
if (trash[i].x == x - 1)
{
trash[j].score += 1;
return;
}
}
}
}
return;
}
void is4(int j, long x, long y)
{
if (x == 0 || y == 0)
return;
for (int i = 0; i < n; i++)
{
if (i != j)
{
if (trash[i].y == y - 1)
{
if (trash[i].x == x + 1)
{
trash[j].score += 1;
return;
}
}
}
}
return;
}
int main()
{
int score[5];
for (int i = 0; i < 5; i++)
{
score[i] = 0;
}
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
long x, y;
scanf("%ld %ld", &x, &y);
trash[i].x = x;
trash[i].y = y;
trash[i].count = 0;
trash[i].score = 0;
}
for (int i = 0; i < n; i++)
{
long x = trash[i].x;
long y = trash[i].y;
isUp(i, x, y);
isDown(i, x, y);
isLeft(i, x, y);
isRight(i, x, y);
if (trash[i].count == 4)
{
is1(i, x, y);
is2(i, x, y);
is3(i, x, y);
is4(i, x, y);
score[trash[i].score]++;
}
}
for (int i = 0; i < 5; i++)
{
printf("%d\n", score[i]);
}
return 0;
}