标签:des style c class blog code
Time
Limit: 2000/1000 MS (Java/Others) Memory Limit:
32768/32768 K (Java/Others)
Total Submission(s):
340 Accepted Submission(s):
110
#include <stdio.h> #include <string.h> typedef long long ll; const int O = 1000000; const int maxn = 10005; typedef struct E{ int v, n; }E; typedef struct point{ int x, h; int g[2]; }point; point a[maxn]; E edge[O]; int Adj[maxn], l; int f[maxn]; void addedge(int u, int v){ edge[l].v = v; edge[l].n = Adj[u]; Adj[u] = l++; } void check(int i, int i1, int i2){ if(!i2 || a[i1].h >= a[i2].h) a[i].h = a[i1].h; else if(a[i2].h > a[i1].h) a[i].h = a[i2].h; } int abs(int x){ return x > 0 ? x : -x; } int read(){ char ch = ‘ ‘; while(ch < ‘0‘ || ch > ‘9‘) ch = getchar(); int x = 0; while(ch >= ‘0‘ && ch <= ‘9‘){ x = x * 10 + ch - ‘0‘; ch = getchar(); } return x; } void work(){ int n, q, x, y; char ch[2]; n = read(); memset(Adj, -1, sizeof(Adj[0]) * (n + 1)); memset(a, 0, sizeof(a[0]) * (n + 1)); l = 0; int flag = 0, pre = 0, next = 0; for(int i = 1; i <= n; ++i){ a[i].x = read(); a[i].h = read(); if(a[i].h) flag = 1; } if(flag){ for(int i = 1; i <= n; ++i){ if(!a[i].h){ a[i].g[0] = pre; if(next <= i && next <= n){ next = i + 1; while(next <= n){ if(a[next].h) break; ++next; } } a[i].g[1] = (next <= n ? next : 0); if(!a[i].g[0] || abs(a[i].x - a[a[i].g[0]].x) > abs(a[a[i].g[1]].x - a[i].x)){ a[i].g[0] = a[i].g[1]; a[i].g[1] = 0; } else if(abs(a[i].x - a[a[i].g[0]].x) < abs(a[a[i].g[1]].x - a[i].x)){ a[i].g[1] = 0; } if(a[i].g[0]) addedge(a[i].g[0], i); if(a[i].g[1]) addedge(a[i].g[1], i); } else pre = i; } } for(int i = 1; i <= n; ++i){ if(!a[i].h) check(i, a[i].g[0], a[i].g[1]); } scanf("%d", &q); for(int i = 0; i < q; ++i){ scanf("%s", ch); if(ch[0] == ‘Q‘){ int cnt = 0; scanf("%d", &x); for(int j = 1; j <= n; ++j) if(a[j].h <= x) cnt++; printf("%d\n", cnt); } else{ scanf("%d%d", &x, &y); a[++x].h = y; for(int j = Adj[x]; ~j; j = edge[j].n){ int v = edge[j].v; check(v, a[v].g[0], a[v].g[1]); } } } } int main(){ int t, cas; for(scanf("%d", &t), cas = 1; cas <= t; ++cas){ printf("Case #%d:\n", cas); work(); } return 0; }
HDU 4831 Scenic Popularity 暴力模拟,布布扣,bubuko.com
HDU 4831 Scenic Popularity 暴力模拟
标签:des style c class blog code
原文地址:http://www.cnblogs.com/ac-luna/p/3752970.html