题解:P16823 [AFOI 2025] A1.追忆(Easy Version)

· · 题解

这道题提交了好几遍才过气死我了

这道题只需要将1-i的最短路询问出来,再询问出i-n的最短路 相加后取最小值即可AC

切记 交互题不要写endl 要写\n 还要加上cout.flush()

真麻烦

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n==2){
        cout<<"! 1\n";
        cout.flush();
        return 0;
    }
    int ans=1e9;
    for(int i=2;i<n;i++){
        cout<<"? 1 "<<i<<"\n";
        cout.flush();
        int x;
        cin>>x;
        cout<<"? "<<i<<" "<<n<<"\n";
        cout.flush();
        int y;
        cin>>y;
        ans=min(ans,x+y);
    }
    cout<<"! "<<ans-1<<"\n";
    cout.flush();
    return 0;
}

勿copy