zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    PBN飞越转弯Flyover衔接DF航段保护区组图
    子群
    点集拓扑
    近世代数总结
    windows目标进程注入dll
    api文档方法参数
    windows制作动态链接库和使用二
    windows制作动态链接库和使用一
    拷贝构造函数
    c++内联函数
  • 原文地址:https://www.cnblogs.com/tombraider-shadow/p/13640343.html
Copyright © 2011-2022 走看看