D. Vasya and Triangle(数论)

https://codeforces.com/problemset/problem/1030/D

题目描述

Vasya has got three integers nn , mm and kk . He'd like to find three integer points (x_1, y_1)(x1​,y1​) , (x_2, y_2)(x2​,y2​) , (x_3, y_3)(x3​,y3​) , such that 0 \le x_1, x_2, x_3 \le n0≤x1​,x2​,x3​≤n , 0 \le y_1, y_2, y_3 \le m0≤y1​,y2​,y3​≤m and the area of the triangle formed by these points is equal to \frac{nm}{k}knm​ .

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

输入格式

The single line contains three integers nn , mm , kk ( 1\le n, m \le 10^91≤n,m≤109 , 2 \le k \le 10^92≤k≤109 ).

输出格式

If there are no such points, print "NO".

Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_ixi​,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).

题意翻译

给定1 \le n,m \le 10^91≤n,m≤109,2 \le k \le 10^92≤k≤109,求出三个点A(x_1,y_1),B(x_2,y_2),C(x_3,y_3)A(x1​,y1​),B(x2​,y2​),C(x3​,y3​),满足:

  1. 0 \le x_1,x_2,x_3 \le n0≤x1​,x2​,x3​≤n,0 \le y_1,y_2,y_3 \le m0≤y1​,y2​,y3​≤m
  2. S_{\Delta}ABC=\frac{nm}{k}SΔ​ABC=knm​

若无解则直接输出NO,否则第一行输出YES,接下来的三行为三个点的坐标。

输入输出样例

输入 #1复制

4 3 3

输出 #1复制

YES
1 0
2 3
4 1

输入 #2复制

4 4 7

输出 #2复制

NO

说明/提示

In the first example area of the triangle should be equal to \frac{nm}{k} = 4knm​=4 . The triangle mentioned in the output is pictured below:

In the second example there is no triangle with area \frac{nm}{k} = \frac{16}{7}knm​=716​ .


解决这道题之前要知道三角形面积的叉积公式:

S=1/2 | (x2-x1)(y3-y1)-(x3-x1)(y2-y1)|。

由于三角形可以平移旋转,所以我们可以把一个点C定到原点,剩下两个点记为A,B。

此时三角形的面积公式是:S=\frac{|x1y2-x2y1|}{2}

因此有了等式 S=\frac{|x1y2-x2y1|}{2}=n*m/k

此时有一个结论:由于是整数点,|x1y2-x2y1|的范围是[0,n*m],而单纯在坐标轴上的两个点A,B的范围[0,n],[0,m]代入也是能等价这个范围的。(这是我大概理解的..如果具体证明应该是可以用线性规划什么的去证明把

所以这时候就可以再次降维,S=1/2*|x1y2|=n*m/k;

进行转化: 2*S=|X1Y2|=2*N*M/K;

可以发现2*n*m/k需要整除时才有解。

问题转化成在0<=x<=n,0<=y<=m,k>=2中构造合理的解使得x*y=2*n*m/k;

这个结论的具体证明我不是很能理解,暂时当一个结论记住了

如果gcd(2*n,k)==1,令x=n,y=2*m/k能满足

如果gcd(2*n,k)>=2,令x=2*n/gcd(2*n,k) [必然x<=n],此时y=2*n*m/k/x(这个成立应该是能证明的..只是我菜不会

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;

int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,m,k;cin>>n>>m>>k;
  if(2*n*m%k!=0)
  {
  	cout<<"NO"<<endl;
  }
  else
  {
  	LL a=__gcd(2*n,k);
  	cout<<"YES"<<endl;
  	cout<<"0 0"<<endl;
  	if(a==1)
  	{
  		cout<<n<<" "<<0<<endl;
  		cout<<0<<" "<<2*m/k<<endl;
	}
	else
	{
		LL x=2*n/a;
		cout<<2*n/a<<" "<<0<<endl;
		cout<<0<<" "<<2*n*m/k/x<<endl;
	}
  }
return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/108325517