CodeForces - 1058D D. Vasya and Triangle

    xiaoxiao2022-07-14  137

    D. Vasya and Triangle time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output 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 Note In the first example area of the triangle should be equal to nmk=4. The triangle mentioned in the output is pictured below:

    In the second example there is no triangle with area n*m/k=16/7.

    不要被他给的图迷惑,这就是个水题。

    include<iostream> using namespace std; int main() { long long int n,m,k,i; cin>>n>>m>>k; if((n*m)%(2*k)!=0) { cout<<"NO"; return 0; } for(i=1;i<=m;i++) { if((n*i)==(2*n*m)/k) { cout<<"YES"<<endl; cout<<0<<' '<<0<<endl; cout<<0<<' '<<n<<endl; cout<<n<<' '<<i<<endl; return 0; } } for(i=1;i<=n;i++) { if((m*i)==(2*n*m)/k) { cout<<"YES"<<endl; cout<<0<<' '<<0<<endl; cout<<0<<' '<<m<<endl; cout<<0<<' '<<i<<endl; return 0; } } } 风骨散人Chiam 认证博客专家 拖更专业户???? 大学僧,考研狗,没上岸,ACM退役选手。名字的含义:希望可以通过努力,能力让家人拥有富足的生活而不是为了生计而到处奔波。“世人慌慌张张,不过是图碎银几两。偏偏这碎银几两,能解世间惆怅,可让父母安康,可护幼子成长 …”Chiam是 -am爱 China中国文章主要内容:Python,C++,C语言,JAVA,C#等语言的教程,ACM题解、模板、算法等,主要是数据结构,数学和图论设计模式,数据库,计算机网络,操作系统,计算机组成原理,Python爬虫、深度学习、机器学学习,计算机系408考研的所有专业课内容。目前还在更新中,博客园,微信公众号同名“风骨散人”,关注公众号可获软件大礼包
    最新回复(0)