Codeforces Round #764 (Div. 3) F. Interacdive Problem

Codeforces Round #764 (Div. 3) F. Interacdive Problem,第1张

Codeforces Round #764 (Div. 3) F. Interacdive Problem

F题已经给了范围了,因此直接二分就行了,但是本题二分的值一直会变,因此只需要记录一个累加值,然后每次二分n-x,最后得到最终答案加上累加值就行了

int n,last=0,sum=0;
int ans[11];

int read(){
	int n;
	cin >> n;
	return n;
}

void print(int x,int k){
	if(k) cout << "+ " << x << endl;
	else cout << "! " << x << endl;  
}

void solve(){
	n=read();
	int l=1,r=n-1,sum=0;
	while(l>1;
		int y=(mid+n-(sum%n))%n;
		if(y==0) y+=n; 
		print(y,1);
		sum += y;
		int a=read();
		
		if(a>y/n+last){
			r=mid;
		}
		else l=mid+1;
		last = a;
//		debug(n-l);debug(n-r);
	}
	print(sum+n-l,0);
}
//=================================
int main(){
	solve();
	return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5702596.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存