Problem D:Last Will

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

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;
}

-=O=- # ## curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 1 second. 3 retries left. -#O#-# # curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 2 seconds. 2 retries left. #=#=# # curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 4 seconds. 1 retry left. ⚠️ Download failure, retrying 2/3 https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt... ##O#- # curl: (6) Could not resolve host: github.com curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 1 second. 3 retries left. #=#=# curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 2 seconds. 2 retries left. ##O#-# curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 4 seconds. 1 retry left. -=O=- ## curl: (6) Could not resolve host: github.com curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 1 second. 3 retries left. ⚠️ Download failure, retrying 3/3 https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt... #=#=# curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 2 seconds. 2 retries left. ##O#-# curl: (6) Could not resolve host: github.com Warning: Problem : timeout. Will retry in 4 seconds. 1 retry left. ##O=# # curl: (6) Could not resolve host: github.com Traceback (most recent call last): File "D:\anaconda\envs\fruit3model\lib\site-packages\ultralytics\utils\downloads.py", line 312, in safe_download assert r == 0, f'Curl return value {r}' AssertionError: Curl return value 6 The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\Ben\Desktop\fruit\pythonProject1\yolo.py", line 214, in <module> results = detection_classification_pipeline(example_image) File "C:\Users\Ben\Desktop\fruit\pythonProject1\yolo.py", line 139, in detection_classification_pipeline detector = YOLO('yolov8n.pt') # 可替换为自定义训练模型 File "D:\anaconda\envs\fruit3model\lib\site-packages\ultralytics\engine\model.py", line 94, in __init__ self._load(model, task) File "D:\anaconda\envs\fruit3model\lib\site-packages\ultralytics\engine\model.py", line 146, in _load self.model, self.ckpt = attempt_load_one_weight(weights) File "D:\anaconda\envs\fruit3model\lib\site-packages\ultralytics\nn\tasks.py", line 639, in attempt_load_one_weight ckpt, weight = torch_safe_load(weight) # load ckpt File "D:\anaconda\envs\fruit3model\lib\site-packages\ultralytics\nn\tasks.py", line 572, in torch_safe_load file = attempt_download_asset(weight) # search online if missing locally File "D:\anaconda\envs\fruit3model\lib\site-packages\ultralytics\utils\downloads.py", line 428, in attempt_download_asset safe_download(url=f'{download_url}/{release}/{name}', file=file, min_bytes=1E5, **kwargs) File "D:\anaconda\envs\fruit3model\lib\site-packages\ultralytics\utils\downloads.py", line 337, in safe_download raise ConnectionError(emojis(f'❌ Download failure for {url}. Retry limit reached.')) from e ConnectionError: Download failure for https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt. Retry limit reached. Process finished with exit code 1
最新发布
12-17
D:\py\.venv\Scripts\python.exe D:\py\水风光储.py =============================================================================== CVXPY v1.6.5 =============================================================================== (CVXPY) May 14 06:31:42 PM: Your problem has 2 variables, 5 constraints, and 0 parameters. (CVXPY) May 14 06:31:42 PM: It is compliant with the following grammars: DCP, DQCP (CVXPY) May 14 06:31:42 PM: (If you need to solve this problem multiple times, but with different data, consider using parameters.) (CVXPY) May 14 06:31:42 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution. (CVXPY) May 14 06:31:42 PM: Your problem is compiled with the CPP canonicalization backend. Traceback (most recent call last): File "D:\py\水风光储.py", line 23, in <module> prob.solve(solver='GLPK_MI', verbose=True) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 600, in solve return solve_func(self, *args, **kwargs) File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 1170, in _solve data, solving_chain, inverse_data = self.get_problem_data( ~~~~~~~~~~~~~~~~~~~~~^ solver, gp, enforce_dpp, ignore_dpp, verbose, canon_backend, kwargs ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 743, in get_problem_data solving_chain = self._construct_chain( solver=solver, gp=gp, ...<2 lines>... canon_backend=canon_backend, solver_opts=solver_opts) File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 992, in _construct_chain candidate_solvers = self._find_candidate_solvers(solver=solver, gp=gp) File "D:\py\.venv\Lib\site-packages\cvxpy\problems\problem.py", line 855, in _find_candidate_solvers raise error.SolverError("The solver %s is not installed." % solver) cvxpy.error.SolverError: The solver GLPK_MI is not installed. 这个报错应该怎么解决
05-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值