首页 > 代码库 > 2014年百度之星程序设计大赛 - 初赛(第二轮)
2014年百度之星程序设计大赛 - 初赛(第二轮)
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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。