码迷,mamicode.com
首页 > 其他好文 > 详细

cf1270D——交互,思维

时间:2020-01-02 00:05:00      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:个数   pre   def   ret   max   bit   c++   cond   using   

对前k+1个数询问k+1次即可,询问结果只会有两个数:第m个和第m+1个,较大的数出现次数就是m次

#include<bits/stdc++.h>
using namespace std;
#define N 505

map<int,int>mp;
int a[N],n,k,m;

void ask(){
    cout<<"? ";
    for(int i=1;i<=k;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}

int main(){
    cin>>n>>k;
    if(k==1){puts("! 1");return 0;}
    
    for(int i=1;i<=k+1;i++){
        int cnt=0;
        for(int j=1;j<=k+1;j++)
            if(j!=i)a[++cnt]=j;
        ask();
        int pos,val;
        cin>>pos>>val;
        mp[val]++;
    }

    // 一个数出现(较大的)m次,另一个数出现k+1-m次
    int Max=0,ans;
    for(auto p:mp)
        Max=max(Max,p.first);
    for(auto p:mp)
        if(p.first==Max)
            ans=p.second;
    
    cout<<"! "<<ans<<endl;
}

cf1270D——交互,思维

标签:个数   pre   def   ret   max   bit   c++   cond   using   

原文地址:https://www.cnblogs.com/zsben991126/p/12130886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!