Atcoder Grand 036 - A 叉积

<Atcoder Grand 036 - A> 叉积

https://atcoder.jp/contests/agc036/tasks/agc036_a

题意:

已知面积S,在第一象限内构造3个坐标,使得三点连线围成的三角形面积为S/2,打印坐标。

思路:

S = ad - bc,先将一点定在原点(0,0),另外两点坐标是(a, b)和(c,d)。ad必然不小于S,初始化a = d = sqrt(S),不断放大a和d当ad>=S时停止。然后就在ad - S内找因子构造出bc即可。

AC代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
ll s;
int a, b, c, d;

int main() {
	scanf("%lld", &s);
	// 定一顶点在(0, 0), 构造向量(a, b)和(c, d)
	// 叉积求面积: s = ad - bc
	a = d = (int)sqrt(s);
	while(s > 1ll * a * d) {
		if(a < d) a++;
		else d++;
	}
	ll chk = 1ll * a * d - s;
	for(int i = 1; i <= sqrt(chk); i++) {
		if(!(chk % i)) {
			if(i <= 1e9 && chk / i <= 1e9) {
				b = i;
				c = chk / i;
				break;
			}
		}
	}
	printf("0 0 %d %d %d %d\n", a, b, c, d);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值