結果
問題 | No.461 三角形はいくつ? |
ユーザー |
![]() |
提出日時 | 2016-12-12 02:53:06 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 96 ms / 5,000 ms |
コード長 | 2,897 bytes |
コンパイル時間 | 590 ms |
コンパイル使用メモリ | 50,640 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-29 13:33:18 |
合計ジャッジ時間 | 3,443 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:51:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 51 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:52:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 52 | inc(i, n) { scanf("%d%d%d", &p[i], &a[i], &b[i]); } | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>#include <cmath>#include <vector>#include <utility>#include <algorithm>typedef long long signed int LL;typedef long long unsigned int LU;#define incID(i, l, r) for(int i = (l) ; i < (r); i++)#define incII(i, l, r) for(int i = (l) ; i <= (r); i++)#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)#define decII(i, l, r) for(int i = (r) ; i >= (l); i--)#define inc( i, n) incID(i, 0, n)#define inc1(i, n) incII(i, 1, n)#define dec( i, n) decID(i, 0, n)#define dec1(i, n) decII(i, 1, n)#define inII(v, l, r) ((l) <= (v) && (v) <= (r))#define inID(v, l, r) ((l) <= (v) && (v) < (r))// template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }template<typename T> T abs(T x) { return (0 <= x ? x : -x); }template<typename T> T max(T a, T b) { return (b <= a ? a : b); }template<typename T> T min(T a, T b) { return (a <= b ? a : b); }template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }// ---- ----struct Frac {LL p, q;Frac(LL pp, LL qq) { p = pp; q = qq; }bool operator<(const Frac & obj) const {return (this -> p) * (obj.q) < (obj.p) * (this -> q);}bool operator==(const Frac & obj) const {return (this -> p) * (obj.q) == (obj.p) * (this -> q);}double val() { return static_cast<double>(p) / q; }};int n, p[4000], a[4000], b[4000];LL ans;std::vector<Frac> vec[3];int main() {scanf("%d", &n);inc(i, n) { scanf("%d%d%d", &p[i], &a[i], &b[i]); }inc(i, n) { Frac f(a[i], a[i] + b[i]); vec[ p[i] ].push_back(f); }inc(i, 3) { Frac f(1, 1); vec[ i ].push_back(f); }inc(i, 3) { std::sort(vec[i].begin(), vec[i].end()); }/*inc(i, 3) {for(auto && e: vec[i]) { printf("%2d/%2d = %.2f\n", e.p, e.q, e.val()); }printf("\n");}*/for(auto && e1: vec[1]) {for(auto && e2: vec[2]) {// printf("e1: <%2d,%4d>, e2: <%2d,%4d>, ", e1.p, e1.q, e2.p, e2.q);Frac x(e1.q - e1.p, e1.q);Frac y(e2.q - e2.p, e2.q);Frac z((e1.q - e1.p) * e2.q + (e2.q - e2.p) * e1.q, e1.q * e2.q);Frac u(1, 1);if(u < z) { continue; }if(y < x) { std::swap(x, y); }auto lby = std::lower_bound(vec[0].begin(), vec[0].end(), y);auto lbz = std::lower_bound(vec[0].begin(), vec[0].end(), z);int v = vec[0].end() - lby, w = (lbz != vec[0].end() && *(lbz) == z);ans += v - w;/*// printf("x: <%2d,%2d>, y: <%2d,%2d>, z: <%2d,%2d>, ", x.p, x.q, y.p, y.q, z.p, z.q );printf("x: [%.2f], y: [%.2f], z: [%.2f], ", x.val(), y.val(), z.val());printf("ans += %d - %d\n", v, w);*/}}printf("%lld\n", ans);return 0;}