Problem D:Last Will
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 1048576K,其他语言2097152K
64bit IO Format: %lld
题目描述
David is a farmer and has a large farm. The shape of the farm is a square. A square is a quadrilateral that has four equal sides and four equal angles. The length of any side of David’s farm is one kilo meter, so the area of his farm is slightly greater than the total area of 140 standard football fields.
David is old and very ill. He feels that his days are numbered. Worrying that his spouse Dora and their three children, Alice, Bob, and Cliff, will have a dispute over the ownership of the farm after he passes away, he plans to divide the farm into four parts, and then to allocate each part to one of his family members. He decides to write his last will as follows.
1.Assume that the shape of the farm is a square ABCD where A = (0, 0), B = (1, 0),C = (1, 1), D = (0, 1).
2.Let E = (0.5, 0), F = (1, 0.5), G = (0.5, 1), H = (0, 0.5) be the midpoints of ABˉABˉ, BCˉBCˉ,CDˉCDˉ, DAˉDAˉ, respectively.
3.Let area(P RQS) to denote the area of the quadrilateral P QRS.
4.Please find a point X strictly inside the square ABCD such that
area(AEXH) : area(BF XE) : area(CGXF) = p : q : r
Note that X cannot be on the boundary of the square ABCD.
5.Allocate the land in AEXH, BFXE, CGXF, DHXG to Alice, Bob, Cliff and Dora, respectively.
David is still adjusting the numbers. p, q, r, and his lawyer, Reed, has to read David’s last will carefully. Reed finds that it is impossible to find such point X if David gives an improper set of the numbers such as p = 1, q = 2, r = 1. However, there are proper sets of the numbers p, q, r that allow us to find the point X satisfying David’s last will. For instance, let p : q : r = 2 : 3 : 2, the following figure shows a possible position of X.

Figure 2: area(AEXH) : area(BFXE) : area(CGXF) = 2 : 3 : 2
Please write a program to help Reed to determine whether it is possible to find a point X satisfying David’s last will for a given set of numbers p, q, r. If possible, please output one possible position of X to Reed.
输入描述:
The input contains one line only. The line contains three space-separated positive integers p, q, r.
输出描述:
If there does not exist a point X satisfying David’s last will, then output -1.
Otherwise, output two irreducible fractions x and y such that (x, y) can be the point X satisfying David’s last will.
You must output an irreducible fraction t=nddn as n/d with a positive denominator and use exactly one space to separate x and y.
Note: the numerator and the denominator of any irreducible fraction are integers and do not have common divisors other than 1 and −1.
示例1
输入
复制
1 1 1
输出
复制
1/2 1/2
示例2
输入
复制
1 2 1
输出
复制
-1
示例3
输入
复制
2 3 2
输出
复制
1/4 3/4
备注:
• p, q, r ∈ {1, 2, . . . , 106}
/**
*@filename:D
*@author: pursuit
*@created: 2021-08-10 16:24
**/
#include <bits/stdc++.h>
#define debug(a) cout << "debug : " << (#a)<< " = " << a << endl
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int N = 1e5 + 10;
const int P = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int p,q,r;
void solve(){
//x + y = 2p / (p + r),x - y = (p + r - 2q) / (p + r);
pii x,y;
//x = (3p + r - 2q) / 2 * (p + r);
x.first = 3 * p + r - 2 * q;
x.second = 2 * (p + r);
int gcd = __gcd(x.first,x.second);
x.first /= gcd, x.second /= gcd;
if(x.first < 0){
x.first = - x.first;
x.second = -x.second;
}
y.first = p - r + 2 * q;
y.second = 2 * (p + r);
gcd = __gcd(y.first,y.second);
y.first /= gcd,y.second /= gcd;
if(y.first < 0){
y.first = -y.first;
y.second = -y.second;
}
double temp1 = 1.0 * x.first / x.second,temp2 = 1.0 * y.first / y.second;
//cout << temp1 << " " << temp2 << endl;
if(temp1 > 0 && temp1 < 1 && temp2 > 0 && temp2 < 1){
if(x.second == 1){
cout << x.first << " ";
}
else{
cout << x.first << "/" << x.second << " ";
}
if(y.second == 1){
cout << y.first << " ";
}
else{
cout << y.first << "/" << y.second << endl;
}
}
else{
cout << -1 << endl;
}
}
int main(){
cin >> p >> q >> r;
solve();
return 0;
}

这篇博客讨论了一个关于农场遗产分配的问题,农民大卫希望将他的正方形农场分为四个部分,按照特定比例分配给他的家人。他设定了一组条件来确定分割点,但某些数字组合可能导致无法找到合适的分割点。博客中提供了一个C++程序,用于判断并找到满足条件的分割点坐标,如果存在的话。程序考虑了点必须位于正方形内部且坐标为不可约分数的情况。

2586

被折叠的 条评论
为什么被折叠?



