1001
暴力
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn = 100100; int ll[maxn], rr[maxn]; struct node { int x, y, bj; }e[maxn]; int main() { int cas = 1; int T; scanf("%d", &T); int n; while(T--) { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d %d", &e[i].x, &e[i].y); if(e[i].y == 0) e[i].bj = 0; else e[i].bj = 1; //c[i] = e[i].y; } int now = -1; for(int i = 1; i <= n; i++) { if(e[i].y != 0) now = i; ll[i] = now; } now = -1; for(int i = n; i >= 1; i--) { if(e[i].y != 0) now = i; rr[i] = now; } for(int i = 1; i <= n; i++) { if(e[i].bj == 0) { if(ll[i] != -1 && rr[i] != -1) { int s1 = abs(e[i].x - e[ll[i]].x); int s2 = abs(e[i].x - e[rr[i]].x); if(s1 > s2) e[i].y = e[rr[i]].y; else if(s1 < s2) e[i].y = e[ll[i]].y; else { if(e[ll[i]].y > e[rr[i]].y) e[i].y = e[ll[i]].y; else e[i].y = e[rr[i]].y; } } else if(ll[i] != -1) { e[i].y = e[ll[i]].y; } else { e[i].y = e[rr[i]].y; } } } int m; scanf("%d", &m); printf("Case #%d:\n", cas++); while(m--) { char str[10]; scanf("%s", str); if(str[0] == ‘Q‘) { for(int i = 1; i <= n; i++) { if(e[i].bj == 0) { if(ll[i] != -1 && rr[i] != -1) { int s1 = abs(e[i].x - e[ll[i]].x); int s2 = abs(e[i].x - e[rr[i]].x); if(s1 > s2) e[i].y = e[rr[i]].y; else if(s1 < s2) e[i].y = e[ll[i]].y; else { if(e[ll[i]].y > e[rr[i]].y) e[i].y = e[ll[i]].y; else e[i].y = e[rr[i]].y; } } else if(ll[i] != -1) { e[i].y = e[ll[i]].y; } else { e[i].y = e[rr[i]].y; } } } int x, sum = 0; scanf("%d", &x); for(int i = 1; i <= n; i++) if(e[i].y <= x) sum++; printf("%d\n", sum); } else { int x, y; scanf("%d %d", &x, &y); e[x+1].y = y; } } } return 0; }
2014年百度之星程序设计大赛 - 初赛(第二轮),布布扣,bubuko.com
原文:http://www.cnblogs.com/hrhguanli/p/3781767.html