[POJ] [1064] Cable master

Problem Description

Loading...

Problem Analysis

Binary search on the result
For the current mid, calculate how many pieces it can produce
Compare it with k
The check condition is also easy to write

However…

This is a precision-sensitive problem
Note that, because of the problem statement,
the final result cannot be rounded
it needs to be truncated

And base conversion and the bizarre mechanics of double
make the final data handling in this problem quite troublesome

Here I was forced into it…
so I used a rather amusing way to output…

Test data:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
4 2540  
8.02  
7.43  
4.57  
5.39
=>0.01
4 2542  
8.02  
7.43  
4.57  
5.39
=>0.00
cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
long long exgcd(long long a,long long b,long long &x,long long &y) {
	if(b==0) {
		x=1,y=0;
		return a;
	}
	long long d=exgcd(b,a%b,y,x);
	y-=x*(a/b);
	return d;
}
int main() {
	long long x,y,m,n,L;
	while(scanf("%lld %lld %lld %lld %lld",&x,&y,&m,&n,&L)!=EOF) {
		long long t1,t2;
		long long d=exgcd(n-m,L,t1,t2);
		if((y-x)%d!=0)
			printf("Impossible\n");
		else {
			t1=t1*((x-y)/d);
			long long r=L/d;
			t1=(t1%r+r)%r;
			printf("%lld\n",t1);
		}
	}
	return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...