zoukankan      html  css  js  c++  java
  • Good Bye 2019 D. Strange Device

    链接:

    https://codeforces.com/contest/1270/problem/D

    题意:

    This problem is interactive.

    We have hidden an array a of n pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.

    This device can answer queries of the following form: in response to the positions of k different elements of the array, it will return the position and value of the m-th among them in the ascending order.

    Unfortunately, the instruction for the device was lost during delivery. However, you remember k, but don't remember m. Your task is to find m using queries to this device.

    You can ask not more than n queries.

    Note that the array a and number m are fixed before the start of the interaction and don't depend on your queries. In other words, interactor is not adaptive.

    Note that you don't have to minimize the number of queries, and you don't need to guess array a. You just have to guess m.

    Input
    The first line contains two integers n and k (1≤k<n≤500) — the length of the array and the number of the elements in the query.

    It is guaranteed that number m satisfies 1≤m≤k, elements a1,a2,…,an of the array satisfy 0≤ai≤109, and all of them are different.

    Interaction
    You begin the interaction by reading n and k.

    To ask a question about elements on positions x1,x2,…,xk, in a separate line output

    ? x1 x2 x3 ... xk
    Numbers in the query have to satisfy 1≤xi≤n, and all xi have to be different. Don't forget to 'flush', to get the answer.

    In response, you will receive two integers pos and apos — the position in the array a of the m-th in ascending order element among ax1,ax2,…,axk, and the element on this position.

    In case your query is invalid or you asked more than n queries, the program will print −1 and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

    When you determine m, output

    ! m

    思路:

    枚举前k+1个的k个,发现k+1-m个(b_m),m个(b_{m+1}),计算最大值的次数即可

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MOD = 998244353;
    const int MAXN = 1e6+10;
    
    int main()
    {
        int n, k, p, v;
        cin >> n >> k;
        int maxv = -1, maxcnt = 0;
        for (int i = 1;i <= k+1;i++)
        {
            cout << "?";
            for (int j = 1;j <= k+1;j++) if (i != j)
                cout << " " << j;
            cout << endl;
            cin >> p >> v;
            if (v > maxv)
            {
                maxv = v;
                maxcnt = 1;
                continue;
            }
            if (v == maxv)
                maxcnt++;
        }
        cout << "! " << maxcnt << endl;
    
        return 0;
    }
    
  • 相关阅读:
    主键、外键、复合外键的创建
    DbHelper and OracleHelper
    Oracle 给表添加主键和使ID自增、触发器、创建结构一样的表
    Oracle 参数化更新数据时报错:Oracle ORA-01722: 无效数字
    ASP.NET MVC 基础
    5. CSS新特性之浏览器私有前缀
    JavaScript-----15.简单数据类型和复杂数据类型
    JavaScript-----14.内置对象 Array()和String()
    JavaScript-----13.内置对象 Math()和Date()
    JavaScript-----12.对象
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12122456.html
Copyright © 2011-2022 走看看