CF 1167B - Lost Numbers

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
 */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值