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中,当然这个“一部分”可以是0

例子:2*3*5%15 == 0   k的质因子分别来自n和m

当k和2*n含有相同的质因子时

令t=gcd(2*n,k)   t一定大于等于2

令a = 2n/t     a一定小于n

b = (2*m*n)/(a*k)

b=m*t/k     b一定小于等于m(因为t一定大于等于k)

当k和2*n不含相同质因子时

那么质因子就全部包含在m里面

直接令a = n   b = 2*m/k 即可   因为k >= 2  所以不会超范围

ac:代码

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

  

原文地址:https://www.cnblogs.com/mltang/p/9700167.html

时间: 2024-10-13 18:00:08

Codeforces Round #512 (Div. 2) 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 #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

Codeforces Round #319 (Div. 2) C Vasya and Petya&#39;s Game

因为所有整数都能被唯一分解,p1^a1*p2^a2*...*pi^ai,而一次询问的数可以分解为p1^a1k*p2^a2k*...*pi^aik,这次询问会把所有a1>=a1k && a2 >= a2k &&... a3 >= a3k的数从原来的集合中分开.ai表示pi的幂. 那么只有当这个数的素因子的最大幂都被询问过一次,这个数才能确定.因此答案是所有的不大于n的只有一个素因子的数. #include<bits/stdc++.h> using

Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket

C. Vasya and Golden Ticket time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Recently Vasya found a golden ticket - a sequence which consists of nn digits a1a2-ana1a2-an. Vasya considers a ti

codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)

题目链接:http://www.codeforces.com/problemset/problem/460/A题意:Vasya每天用掉一双袜子,她妈妈每m天给他送一双袜子,Vasya一开始有n双袜子,请问第几天的时候Vasya会没有袜子穿?C++代码: #include <iostream> using namespace std; int n, m; int main() { cin >> n >> m; int d = 0; while (n) { d ++; if

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

Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序

C. Vasya and Basketball Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from does

Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题

B. Vasya and Wrestling Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, th

Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈

D. Vasya and Chess Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is