Problem - A - Codeforces
题目大意:给你一个数组,只由两个数字组成,其中一个数字只出现了一次,求该数字出现的下标位置.
思路:直接模拟
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define rep(x,y,z) for(int x=y; x<=z; ++x)
#define dec(x,y,z) for(int x=y; x>=z; --x)
int t, n;
set<int>s;
int a[105];
int main(){
cin>>t;
int cur;
while(t--){
s.clear();
cin>>n;
rep(i,1,n){
cin>>a[i];
if(s.count(a[i]))cur = a[i];
else s.insert(a[i]);
}
rep(i,1,n){
if (a[i] != cur){
cout << i << endl;
}
}
}
return 0;
}
Problem - B - Codeforces
题目大意:在一张地图上给定两个"*",添加两个’’*“来使得所有的”*"凑成最小的矩形.
思路:直接模拟,如果两个"*"的不在一条直线上,那么另外两点只需要组合一下当前点的x,y.如果两点处在同一直线上,那么直接枚举一下移动一步的情况.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define rep(x,y,z) for(int x=y; x<=z; ++x)
#define dec(x,y,z) for(int x=y; x>=z; --x)
char m[405][405];
int t, n;
int x[2], y[2];
int main(){
cin>>t;
while(t--){
cin>>n;
rep(i,1,n){
rep(j,1,n){
cin>>m[i][j];
}
}
int index= 0;
rep(i,1,n){
rep(j,1,n){
if (m[i][j] == '*'){
x[index] = i;
y[index] = j