CF 1167B - Lost Numbers
交互题
题意:猜
4
,
8
,
15
,
16
,
23
,
42
{4, 8, 15, 16, 23, 42}
4,8,15,16,23,42 的排列。至多问4次,每次询问
{
i
,
j
}
\{i, j\}
{i,j},可以得到
a
[
i
]
∗
a
[
j
]
a[i] * a[j]
a[i]∗a[j] 的结果。输出排列。
思路:依次询问
{
1
,
2
}
\{1, 2\}
{1,2}
{
2
,
3
}
\{2, 3\}
{2,3}
{
3
,
4
}
\{3, 4\}
{3,4}
{
4
,
5
}
\{4, 5\}
{4,5} 可以依次得到每一位的值,最后
a
[
6
]
a[6]
a[6] 就是排列中剩下的那一个。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) x & (-x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxN = 3e5 + 5;
const int a[6] = {4, 8, 15, 16, 23, 42};
int ans[10];
bool vis[50];
map<int, pair<int, int>>mp;
void init() {
for(int i = 0; i < 6; ++ i ) {
for(int j = i + 1; j < 6; ++ j ) {
mp[a[i] * a[j]] = make_pair(a[i], a[j]);
}
}
memset(vis, false, sizeof(vis));
}
bool Same(int x, int y) {
return x == y;
}
int main()
{
init();
int fis = -1, sec = -1, mul = -1;
for(int i = 1; i < 5; ++ i ) {
cout << "? " << i << ' ' << i + 1 << endl;
fflush(stdout);
cin >> mul;
auto it = mp.find(mul);
if(i == 2) {
if(Same(fis, it->second.first) || Same(fis, it->second.second)) {
ans[i] = fis;
ans[i - 1] = sec;
} else if(Same(sec, it->second.first) || Same(sec, it->second.second)) {
ans[i] = sec;
ans[i - 1] = fis;
}
vis[ans[i]] = true;
vis[ans[i - 1]] = true;
} else if(i > 2) {
if(vis[fis]) {
ans[i] = sec;
} else {
ans[i] = fis;
}
vis[ans[i]] = true;
}
fis = it->second.first;
sec = it->second.second;
}
ans[5] = mul / ans[4];
vis[ans[5]] = true;
for(int i = 0; i < 6; ++ i ) {
if(!vis[a[i]]) {
ans[6] = a[i];
break;
}
}
cout << "! ";
for(int i = 1; i <= 6; ++ i ) {
cout << ans[i] << ' ';
}
cout << endl;
return 0;
}
/*
32
120
240
368
*/