F. Rudolph and Mimic
原题链接:Problem - 1846F - Codeforces
题目大意:
一开始给你一个n,represent有n个物体,其中有一个外星人,会随机变换形态,你的每个stage可以做两种操作,一是减去指定数量的物体,二是猜出这个外星人的坐标分别对应的是,我直接举例子吧。
- 后跟着的第一个数字是移除的位置个数,后续的就是位置。每次这个操作之后都会再输出所有物品的信息,顺序是打乱的。
!后跟着的是猜中的坐标。
题目做法:
首先先静待这个mimic变化一次先,一定是在stage1或者stage2会发生一次变化,你就能得知,它变成了啥是吧,那你就把除了这个新号码的东西全部删掉,此时stage3,你且再等他两回合,总会变的。stage4或者stage5便可出结果。
AC代码:
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
void solve(){
int n, k, t, record;
vector<int> ar;
int a[2][10];
cin >> n;
for(int i = 0; i < 10; i++) a[0][i] = 0, a[1][i] = 0;
for(int i = 0; i < n ; i++){
cin >> t;
a[1][t] += 1;
}
while(1){
cout << "- 0" << endl;
ar.clear();
for(int i = 0; i < 10 ; i++) a[0][i] = a[1][i], a[1][i] = 0;
for(int i = 0; i < n ; i++){
cin >> t;
ar.pb(t);
a[1][t] += 1;
}
bool f = 1;
for(int i = 0; i < 10 ; i++){
if(a[1][i] == a[0][i] + 1){
record = i;
f = 0;
break;
}
}
if(!f) break;
}
cout << "- " << signed(ar.size() - a[1][record]) << ' ';
for(int i = 0; i < n; i++){
if(ar[i] != record){
cout << i + 1 << ' ';
}
}
n = n - signed(ar.size() - a[1][record]);
cout << endl;
while(1){
ar.clear();
for(int i = 0; i < 10 ; i++){
if(i != record) a[0][i] = 0, a[1][i] = 0;
else a[0][i] = a[1][i], a[1][i] = 0;
}
for(int i = 0; i < n ; i++){
cin >> t;
ar.pb(t);
a[1][t] += 1;
}
for(int i = 0; i < 10 ; i++){
if(a[1][i] == a[0][i] + 1){
for(int j = 0; j < n ; j++){
if(ar[j] == i){
cout << "! " << j + 1 << endl;
return;
}
}
}
}
cout << "- 0" << endl;
}
}
signed main(){
fast int casen = 1;
cin >> casen;
while(casen--) solve();
}
事后ps :tle了贼多发,后来发现交互题的此tle,非彼tle。这里的tle是你超出5此就是tle,应该是这样的,出现的问题就是stage4或5的那个while,a数组的处理想当然复制了,删除的元素在a数组里的影响没有考虑到,真是粗心坏大事,浪费巨多时间,所以一次正确率很重要,把该想的点都整明白点,不要摸棱两可,复制黏贴想当然。