其他分享
首页 > 其他分享> > CF-SGU-P551-Preparing Problem

CF-SGU-P551-Preparing Problem

作者:互联网

二分答案+细节处理
二分时间 t ,使得在 t 时刻就已经达到任务数。再判断两人任务是否都完成。
代码:

#include<bits/stdc++.h>
using namespace std;
int n, a, b, l, r, mid, d;
bool work(int t){
	int res = t / a + t / b;
	if(res >= n)
	  return true;
	else
	  return false;
}
int main(){
	scanf("%d%d%d", &n, &a, &b);
	l = 0, r = 25000001; 
	while(l < r){
	  mid = (l + r) >> 1;
	  if(work(mid))
	    r = mid;
	  else
	    l = mid + 1;
	}
	if(l%a == 0 && l%b == 0)
	  cout<<l/a+l/b<<" "<<l;
	else
	  if(l%a == 0)
	    cout<<l/a+l/b+1<<" "<<(l/b+1)*b;
	  else
	    cout<<l/a+l/b+1<<" "<<(l/a+1)*a;
}

标签:return,int,res,d%,SGU,mid,else,Problem,P551
来源: https://blog.csdn.net/weixin_44618487/article/details/98472725