跳到正文

题解

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

Ykb135约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年6月6日
收录
2026年9月6日
更新
2026年11月16日
篇幅
约 1 分钟
题目
P16823

版本

  1. v1当前

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

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

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

真麻烦

C++
#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

原文