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,满足这种直角三角形点,但是可以在分数的底和高满足

但其实我们分析,我们要找到整数a,b满足a*b=2*n*m/k,且a<=n,b<=m.

因为已经满足过2*n*m%k==0,所以k至少可以被2或者n的一个因子,或者m的一个因子整除,这个被整除的数也至少是2

也就是说2*n*m/gcd(2,n,m)<=n*m(=当且仅当k==2时), 也就是说肯定可以拆成整数a,b;

    那答案就是a=n/(gcd(2*n,k))  b=m/(k/gcd(2*n,k));或者a=n/(k/gcd(2*m,k))  b=m/(gcd(2*m,k)); 满足a<=n b<=m的那种就是可行方案

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lld long long
 4 long long n,m,k;
 5 lld gcd(lld a,lld b)
 6 {
 7     if (b==0) return a;
 8     return gcd(b,a%b);
 9 }
10 int main()
11 {
12     scanf("%lld%lld%lld",&n,&m,&k);
13     if (n*m*2%k!=0)
14     {
15         printf("NO");
16         return 0;
17     }
18     printf("YES\n0 0\n");
19     lld x=gcd(2*n,k),y;
20     y=k/x;
21     x=2*n/x;
22     y=m/y;
23     if (x<=n && y<=m)
24     {
25         printf("%lld %lld\n",x,0ll);
26         printf("%lld %lld\n",0ll,y);
27     }else
28     {
29         x/=2;
30         y*=2;
31         printf("%lld %lld\n",x,0ll);
32         printf("%lld %lld\n",0ll,y);
33     }
34 }

原文地址:https://www.cnblogs.com/qywhy/p/9695344.html

时间: 2024-10-27 14:52:26

Codeforces Round #512 (Div. 2) D.Vasya and Triangle 数学的相关文章

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

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 #404 (Div. 2) C 二分,水 D 数学,好题 E 分块

Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 题意:仓库容量n,每天运来m粮食,第 i 天被吃 i 粮食,问第几天仓库第一次空掉. tags:==SB题 注:二分边界判断,数据范围爆long long判断. // CF404 C #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000&

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