QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864331#9859. King of GamersNolearnnodo#TL 0ms3840kbC++141017b2025-01-20 14:52:442025-01-20 14:52:50

Judging History

你现在查看的是最新测评结果

  • [2025-01-20 14:52:50]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3840kb
  • [2025-01-20 14:52:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
	cin>>t;
	long long n,ans,a,b,n1,n2,nowa,nowb,left,right,tx,mid;
	while(t--){
		ans=1;
		scanf("%lld %lld %lld",&n,&a,&b);
		if(n==1 || a==0){
			printf("1\n");
			continue;
		}
		if(a==b){
			printf("%lld\n",n);
			continue;
		}
		nowa=1; nowb=1; tx=n-1;
		while(1){
			left=1,right=tx;
			while(left<right){ //先输一些 
				mid=(left+right)>>1;
				if(a*(nowb+mid)>=b*nowa){
					right=mid;
				}
				else{
					left=mid+1;
				}
			}
			n1=right;
			if(a*(nowb+left)<b*nowa){
				break;
			}
			nowb+=left; tx-=left;
			if(tx==0) break;
			
			left=1,right=tx;
			while(left<right){
				mid=(left+right)>>1;
				if(a*(nowb+mid)<b*(nowa+mid)){
					right=mid;
				}
				else{
					left=mid+1;
				}
			}
			n2=left;
			nowa+=left; nowb+=left; tx-=left;
			ans+=left;
			if(tx==0) break;
			if(n1==1&&n2==1){
				ans+=tx/2;
				break;
			}
		}
			printf("%lld\n",ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3840kb

input:

3
4 3 5
8 7 10
1 1 3

output:

2
5
1

result:

ok 3 number(s): "2 5 1"

Test #2:

score: -100
Time Limit Exceeded

input:

100000
666977257 46322301 444651505
775037696 10955843 81788929
943459623 1 500000071
998998627 85 465525978
998969116 949398518 949398594
999995971 172077240 464085681
406334061 103283849 270889374
919331712 241327022 645922817
892656218 7 576716801
999547883 26 713779916
998450133 108731744 108731...

output:


result: