我们只要把每头牛开始遮挡视线和结束遮挡视线的时间点都搞出来就好= =
再按照y轴排序。。。然后变成线段覆盖了。。线段树搞一下就好了?
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /************************************************************** 2 Problem: 3888 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:1204 ms 7 Memory:22684 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <algorithm> 12 13 using namespace std; 14 const int N = 1e5 + 5; 15 16 struct data { 17 int x, y, c; 18 int st, ed; 19 20 inline void read() { 21 scanf("%d%d%d", &x, &y, &c); 22 x *= -1, st = c * (x - 1), ed = st + c; 23 } 24 25 inline bool operator < (const data &p) const { 26 return y > p.y; 27 } 28 } a[N]; 29 30 struct seg_node { 31 seg_node *ls, *rs; 32 int v; 33 } *seg_null, *seg_root, mempool[N << 4], *cnt_seg = mempool; 34 35 int n, ans; 36 int v[N]; 37 int t[N << 1], tot; 38 39 #define Ls p -> ls 40 #define Rs p -> rs 41 #define V p -> v 42 #define mid (l + r >> 1) 43 inline void seg_get_null(seg_node *&p) { 44 p = cnt_seg, Ls = Rs = p; 45 } 46 47 inline void seg_new(seg_node *&p) { 48 p = ++cnt_seg, *p = *seg_null; 49 } 50 51 inline void seg_push(seg_node *p) { 52 if (V) { 53 Ls -> v = Rs -> v = V; 54 V = 0; 55 } 56 } 57 58 inline void seg_build(seg_node *&p, int l, int r) { 59 seg_new(p); 60 if (l == r) return; 61 seg_build(Ls, l, mid), seg_build(Rs, mid + 1, r); 62 } 63 64 inline void seg_modify(seg_node *p, int l, int r, int L, int R, int v) { 65 if (L <= l && r <= R) { 66 V = v; 67 return; 68 } 69 seg_push(p); 70 if (L <= mid) seg_modify(Ls, l, mid, L, R, v); 71 if (mid < R) seg_modify(Rs, mid + 1, r, L, R, v); 72 } 73 74 inline int seg_query(seg_node *p, int l, int r, int pos) { 75 if (l == r) return V; 76 seg_push(p); 77 if (pos <= mid) return seg_query(Ls, l, mid, pos); 78 else return seg_query(Rs, mid + 1, r, pos); 79 } 80 #undef Ls 81 #undef Rs 82 #undef V 83 #undef mid 84 85 int main() { 86 int i; 87 scanf("%d", &n); 88 for (i = 1; i <= n; ++i) 89 a[i].read(); 90 sort(a + 1, a + n + 1); 91 for (i = 1; i <= n; ++i) 92 t[i * 2 - 1] = a[i].st, t[i * 2] = a[i].ed; 93 sort(t + 1, t + 2 * n + 1); 94 tot = unique(t + 1, t + 2 * n + 1) - t; 95 for (i = 1; i <= n; ++i) { 96 a[i].st = lower_bound(t + 1, t + tot + 1, a[i].st) - t; 97 a[i].ed = lower_bound(t + 1, t + tot + 1, a[i].ed) - t; 98 a[i].st *= 2, a[i].ed *= 2; 99 } 100 tot *= 2; 101 seg_get_null(seg_null); 102 seg_build(seg_root = seg_null, 1, tot); 103 for (i = 1; i <= n; ++i) 104 seg_modify(seg_root, 1, tot, a[i].st, a[i].ed, i); 105 for (i = 1; i <= tot; ++i) 106 v[seg_query(seg_root, 1, tot, i)] = 1; 107 for (ans = 0, i = 1; i <= n; ++i) 108 ans += v[i]; 109 printf("%d\n", ans); 110 return 0; 111 }
By Xs酱~ 转载请说明
博客地址:http://www.cnblogs.com/rausen