CFS–20191202–回收站选址
本题思路:用一个2行N列的二维数组存放X,Y让后操作
#includeusing namespace std;int main()
{int n;cin >> n;int **a &#61; (int**)malloc(sizeof(int *)*n); int i &#61; 0,j &#61; 0;bool flag1, flag2, flag3, flag4;int score[5] &#61; { 0,0,0,0,0 };for (i &#61; 0; i < n; i&#43;&#43;){a[i] &#61; (int *)malloc(sizeof(int) * 2);}for (i &#61; 0; i < n; i&#43;&#43;){for (j &#61; 0; j < 2; j&#43;&#43;){a[i][j] &#61; 0;}}for (i &#61; 0; i < n; i&#43;&#43;){cin >> a[i][0] >> a[i][1];}int count;for (i &#61; 0; i < n; i&#43;&#43;){flag1 &#61; flag2 &#61; flag3 &#61; flag4 &#61; false;count &#61; 0;for (j &#61; 0; j < n; j&#43;&#43;){if (a[j][0] &#61;&#61; a[i][0] && a[j][1] &#61;&#61; a[i][1] &#43; 1) flag1 &#61; true;if (a[j][0] &#61;&#61; a[i][0] && a[j][1] &#61;&#61; a[i][1] - 1) flag2 &#61; true;if (a[j][0] &#61;&#61; a[i][0]&#43;1 && a[j][1] &#61;&#61; a[i][1]) flag3 &#61; true;if (a[j][0] &#61;&#61; a[i][0]-1 && a[j][1] &#61;&#61; a[i][1]) flag4 &#61; true;if (a[j][0] &#61;&#61; a[i][0] &#43; 1 && a[j][1] &#61;&#61; a[i][1] &#43; 1) count&#43;&#43;;if (a[j][0] &#61;&#61; a[i][0] &#43; 1 && a[j][1] &#61;&#61; a[i][1] - 1) count&#43;&#43;;if (a[j][0] &#61;&#61; a[i][0] - 1 && a[j][1] &#61;&#61; a[i][1] &#43; 1) count&#43;&#43;;if (a[j][0] &#61;&#61; a[i][0] - 1 && a[j][1] &#61;&#61; a[i][1] - 1) count&#43;&#43;;}if (flag1&&flag2&&flag3&&flag4){score[count]&#43;&#43;;}}for (i &#61; 0; i < 5; i&#43;&#43;){cout << score[i] << endl;}return 0;
}
如有差错请私信。