[2021-4-23]BNUZ套题比赛div3
A - Spy Detected! CodeForces - 1512A
当时没看数据范围,应该可以用map写,那样可以储存很大的数,然后发现不需要,AC代码如下:
#include<iostream>
using namespace std;
#include<cstring>
#include<map>
int main() {
int t;
cin >> t;
while (t--) {
int m[5001], a[5001];
memset(m, 0, sizeof m);
memset(a, 0, sizeof a);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
a[i] = temp;
m[temp]++;
}
for (int i = 0; i < n; i++) {
if (m[a[i]] == 1) {
cout << i+1 << endl; break;
}
}
}
return 0;
}
B - Almost Rectangle CodeForces - 1512B
题意:根据两个点来形成一个矩阵
思路:把a[x1][y2],a[x2][y1]都等于’*’,但是需要判断一下同行和同列的情况,而且要看会不会越界。
AC代码如下:
#include<iostream>
using namespace std;
#include<cstring>
#include<map>
int main() {
int t;
cin >> t;
while (t--) {
int n, x1 = 0, y1 = 0, x2 = 0, y2 = 0, f = 0, flag = 0;
char a[500][500];
memset(a, 0, sizeof a);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == '*') {
if (f == 0) {
x1 = i, y1 = j, f = 1;
}
else
{
x2 = i, y2 = j, f = 0, flag = 1; break;
}
}
}
if (flag)break;
}
if (x1 == x2) {
x1 + 1 >= n ? a[x1 - 1][y1] = a[x2 - 1][y2] = '*' : a[x1 + 1][y1] = a[x2 + 1][y2] = '*'; }
if (y1 == y2) {
y1 + 1 >= n ? a[x1][y1 - 1] = a[x2][y2 - 1] = &