QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#39731#2944. Transporting SpaghettiLangdao_ZhangAC ✓3ms3688kbC++830b2022-07-13 09:20:452022-07-13 09:20:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-13 09:20:47]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3688kb
  • [2022-07-13 09:20:45]
  • 提交

answer

#include<iostream>
#include<algorithm>

#define lint int64_t

#define gcd __gcd

#define inf 998244353

using
		namespace
					std;

lint a,b,c,d;
lint x,y;

/*

ax-by=d
by>=c
by<=ax

*/

bool judge(){
	
	//31 13 50 28
	
	if(a*x-d<0) return false;
	
	if((a*x-d)%b) return false;
	
	y=(a*x-d)/b;
	
	if(b*y>a*x) return false;
	
	return b*y>=c;
}

signed main(){
	
	cin>>a>>b>>c>>d;
	
	for(x=0;x<=200;x++){
		
		if(judge()){
			
			goto print;
		}
	}
	
	x=y=inf;
	
print:
	
	if(x==inf){
		
		printf("No solution.\n");
	}
	else{
		
		printf("We need %lld truck",x);
		if(x!=1) putchar('s');
		printf(" and %lld boat",y);
		if(y!=1) putchar('s');
		printf(".\n");
	}
	
end:
	return EOF+1;
}
/*

31 13 50 28
100 20 30 10
1 1 1 100

100 1 99 1
100 1 23 99
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3572kb

input:

31 13 50 28

output:

We need 3 trucks and 5 boats.

result:

ok single line: 'We need 3 trucks and 5 boats.'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

100 20 30 10

output:

No solution.

result:

ok single line: 'No solution.'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

1 1 1 100

output:

We need 101 trucks and 1 boat.

result:

ok single line: 'We need 101 trucks and 1 boat.'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3680kb

input:

20 5 5 15

output:

We need 1 truck and 1 boat.

result:

ok single line: 'We need 1 truck and 1 boat.'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3684kb

input:

100 20 100 100

output:

We need 2 trucks and 5 boats.

result:

ok single line: 'We need 2 trucks and 5 boats.'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3688kb

input:

1 1 0 0

output:

We need 0 trucks and 0 boats.

result:

ok single line: 'We need 0 trucks and 0 boats.'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3676kb

input:

1 5 10 50

output:

We need 60 trucks and 2 boats.

result:

ok single line: 'We need 60 trucks and 2 boats.'

Test #8:

score: 0
Accepted
time: 3ms
memory: 3544kb

input:

100 1 100 100

output:

We need 2 trucks and 100 boats.

result:

ok single line: 'We need 2 trucks and 100 boats.'

Test #9:

score: 0
Accepted
time: 3ms
memory: 3568kb

input:

1 1 100 100

output:

We need 200 trucks and 100 boats.

result:

ok single line: 'We need 200 trucks and 100 boats.'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3648kb

input:

1 1 97 100

output:

We need 197 trucks and 97 boats.

result:

ok single line: 'We need 197 trucks and 97 boats.'