JOISC 2016 神经衰弱
考虑弱化版,当写有同样整数的卡片只有
可以发现性质。
最大的 在询问 时必然不返回 。 第二大的 在询问 时必然只有一种情况返回 。 最小的 在询问 时必然返回 。
考虑打擂台。动态维护
-
若
不是 中 最大或第二大,则询问 均返回 ,可以确定 的值。 -
若
是 中 最大或第二大,则必然有 均返回 ,或者 均返回 ,可以确定 或 的值。
这样,没有被确定的值就是当前的最大和第二大值。若卡片有
现在考虑整道题如何做。
发现上述做法唯一的问题在于,当
为了使返回的值不均相等,可以再记录第三大
卡片有
#include<bits/stdc++.h>
#include "Memory2_lib.h"
#define pb emplace_back
#define mp make_pair
#define pob pop_back
using namespace std;
typedef long long ll;
typedef double db;
const ll maxn=1007,ee=1e18;
ll vis[maxn][maxn],cur[4],tmp[4],ans[maxn];
vector<ll> res[maxn];
ll ask(ll x,ll y){
if(vis[x][y]!=-1) return vis[x][y];
return vis[x][y]=vis[y][x]=Flip(x,y);
}
void Solve(int T,int N){
memset(vis,-1,sizeof(vis));
for(int i=0;i<=2;i++) cur[i]=i;
for(int i=3,tar;i<2*N;i++){
cur[3]=i,tar=3;
for(int a=0,flg;a<4;a++){
flg=1;
for(int b=0,c=-1;b<4;b++)if(a!=b){
tmp[++c]=ask(cur[a],cur[b]);
if(c&&tmp[c]!=tmp[c-1]) flg=0;
}
if(flg){tar=a; break;}
}
ans[cur[tar]]=tmp[0];
for(int a=tar+1;a<4;a++) cur[a-1]=cur[a];
}
tmp[0]=ask(cur[0],cur[1]),tmp[1]=ask(cur[1],cur[2]),tmp[2]=ask(cur[0],cur[2]);
if(tmp[0]==tmp[1]) ans[cur[1]]=tmp[0],ans[cur[0]]=ans[cur[2]]=tmp[2];
else if(tmp[0]==tmp[2]) ans[cur[0]]=tmp[0],ans[cur[1]]=ans[cur[2]]=tmp[1];
else ans[cur[2]]=tmp[1],ans[cur[0]]=ans[cur[1]]=tmp[0];
for(int i=0;i<2*N;i++) res[ans[i]].pb(i);
for(int i=0;i<N;i++) Answer(res[i][0],res[i][1],i);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步