Codeforces Contest 1030 problem D Vasya and Triangle——画三角形

Vasya has got three integers n, m and k. He’d like to find three integer points (x1,y1), (x2,y2), (x3,y3), such that 0≤x1,x2,x3≤n, 0≤y1,y2,y3≤m and the area of the triangle formed by these points is equal to nmk.

Help Vasya! Find such points (if it’s possible). If there are multiple solutions, print any of them.

Input
The single line contains three integers n, m, k (1≤n,m≤109, 2≤k≤109).

Output
If there are no such points, print “NO”.

Otherwise print “YES” in the first line. The next three lines should contain integers xi,yi — coordinates of the points, one point per line. If there are multiple solutions, print any of them.

You can print each letter in any case (upper or lower).
Examples
inputCopy
4 3 3
outputCopy
YES
1 0
2 3
4 1
inputCopy
4 4 7
outputCopy
NO

题意:

给你n,m,k,让你输出三个点,使得这三个点构成的三角形面积为nm/k,这三个点不能超过nm组成的长方形。

题解:

为了简化问题,我们可以将这个三角形2,变成一个长方形,那么问题就变成了让你构造一个长方形,使得这个长方形的面积是nm2/k。那么我们就先对m,k取个gcd,之后又对n2和k取个gcd,看看这个的gcd是不是k,不是的话就说明不能构造。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,k;
    scanf("%lld%lld%lld",&n,&m,&k);
    ll g=__gcd(m,k);
    ll m1=m/g,n1;
    k/=g;
    if(__gcd(n*2,k)!=k)
        return 0*printf("NO\n");
    printf("YES\n");
    if((n*2)/k<=n)
        n1=(n*2)/k;
    else
        m1=m1*2,n1=n/k;
    printf("0 0\n");
    printf("%lld 0\n",n1);
    printf("%lld %lld\n",n1,m1);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值