D. Vasya and Triangle

传送门

[http://codeforces.com/contest/1030/problem/D]

题意

在第一象限,x,y得坐标上限是n,m,再给你个k,让你找3个整数点,使得围成面积德语(n*m)/k,没有输出NO

分析

有解析几何,由3个点坐标求面积公式S=(1/2)|(x2-x1)(y3-y1)-(x3-x1)(y2-y1)|=(nm)/k

所以2(nm)/k为整数时必有解,不然没有。

假设分别为(0,0),(a,0),(0,b)

2(nm)/k为整数时,gcd(2n,k)==1,或者gcd(2n,k)>=2,如果前者,则gcd(2m,k)>=2,且b=2m/gcd(2m,k),a就等于2(nm)/k/b,由于k>=2,可知a,b,都不超过上限

后者同理

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,m,k;
    while(cin>>n>>m>>k){
     if((n*m*2)%k!=0){
        cout<<"NO\n";
        return 0;
     }
     else{
        cout<<"YES\n0 0\n";
        ll h=__gcd(2*n,k);
        if(h==1){
            cout<<n<<‘ ‘<<0<<endl;
            cout<<0<<‘ ‘<<2*m/k<<endl;
         }
         else{
            cout<<2*n/h<<‘ ‘<<0<<endl;
            cout<<0<<‘ ‘<<m*h/k<<endl;
         }
     }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/mch5201314/p/9721550.html

时间: 2024-10-21 19:40:01

D. Vasya and Triangle的相关文章

Codeforces Round #512 (Div. 2) D.Vasya and Triangle 数学

题面 题意:给你n,m,k,在你在(0,0)到(n,m)的矩形内,选3个格点(x,y都是整数),使得三角形面积为n*m/k,不能找到则输出-1 题解:由毕克定理知道,格点多边形的面积必为1/2的整数倍,所以首先n*m/k必须是1/2的整数倍,也就是2*n*m%k要等于0,不等于就输出-1 然后对于面积,我们知道底?高*1/2=面积,a*b*1/2=n*m/k,我们很显然想到一种构造方法,(0,0),(0,a),(b,0); 有人就要问,会不会有一种,使得无法找到整数a,b,满足这种直角三角形点,

Codeforces Round #512 (Div. 2) D. Vasya and Triangle

参考了别人的思路:https://blog.csdn.net/qq_41608020/article/details/82827632 http://www.cnblogs.com/qywhy/p/9695344.html 首先根据皮克定理,2*m*n/k一定要是一个整数,也就是说2*m*n%k !=0 的都可以不用算了 最简单的构造方法肯定是 (a,0),(0,b) 2*n*m%k ==0,把2*n*m看成2*n和m两部分,k中的质因子,一部分在2*n中,一部分在m中,当然这个"一部分&quo

(leetcode题解)Pascal&#39;s Triangle

Pascal's Triangle  Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 题意实现一个杨辉三角. 这道题只要注意了边界条件应该很好实现出来,C++实现如下 vector<vector<int>> generate(int

Lab 1: Write a java program for the triangle problem and test the program with Junit.

Tasks: 1. Install Junit(4.12), Hamcrest(1.3) with Eclipse 将两个jar包添加到工程中 2. Install Eclemma with Eclipse 3. Write a java program for the triangle problem and test the program with Junit. [Description of triangle problem]Function triangle takes three i

Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

A. Vasya and Football Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red

Solution to Triangle by Codility

question: https://codility.com/programmers/lessons/4 we need two parts to prove our solution. on one hand, there is no false triangular. Given the array has been sorted, if A[i]+A[i+1]>A[i+2], we can prove the existence of the triangle. for array A i

LeetCode (13) Pascal&#39;s Triangle (杨辉三角 )

题目描述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return 从第三行开始,每行除了最左边和最右边两个数为1,其他数字都是上一行中相邻两个数字之和.根据上述规则可以写出下面的代码: class Solution { public: vector<vector<int> > generateRow1() { vector<in

UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437 Triangle Fun Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem A Triangle Fun Input: Standard Input Output: Standard Output In the picture below you can see a triangle ABC. Point D, E

POJ 1163 The Triangle

题目链接:http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39022   Accepted: 23430 Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculat