<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; }