Codeforces-1470C(Chocolate Bunny)

Chocolate Bunny

题目大意:交互题,题意不难理解

解题思路:解这道题首先要知道一个结论 如果 p%py > py %p 则 px < py  具体证明可以看官方题解

接下来就是求解每一个数, 我们可以先假设最大的数再位置1,那么我们从第二个位置开始询问,若这个位置的数要比最大的数大,则那么我们假设最大数的位置就要进行更新,这个值就是p%p然后把最大值所在的位置移动到第二个位置就行,如比他小的话,就可以从py %px的到第二个位置的值则没进行两次询问就可以得到一个位置的值,则总共进行2*n-2次就可以的带除最大位置外的值

官方题解 : https://codeforces.com/blog/entry/82417

 

题目链接:https://vjudge.net/problem/CodeForces-1407C

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e4+10;
int ans[maxn];
inline ll read(){
    ll s=0,w=1;char ch = getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') w=-1;ch = getchar();
    }
    while(ch>=48&&ch<=57) s = (s<<1) + (s<<3) + (ch^48),ch=getchar();
    return s*w;
}
int pos(int x,int y)
{
    cout<<"? "<<x+1<<" "<<y+1<<endl;
    int z;
    cin>>z;
    return z;
 } 
int main()
{
    int n;
    cin>>n;
    int mx=0;
    for(int i=1;i<n;i++)
    {
        int a=pos(mx,i);
        int b=pos(i,mx);
        if(a>b)
        {
            ans[mx]=a;
            mx=i;
        }
        else ans[i]=b;
    }
    ans[mx]=n;
    cout<<"!";
    for(int i=0;i<n;i++) cout<<" "<<ans[i];
    cout<<endl;
    return 0;
}

 

posted @ 2020-09-09 17:57  mcalex  阅读(277)  评论(0编辑  收藏  举报