CodeForces 835C Star sky
来源:互联网 发布:js判断标签是否隐藏 编辑:程序博客网 时间:2024/05/17 01:49
题目链接:http://codeforces.com/contest/835/problem/C
题意:有一片星空这个星空里有n个星星,每个星星的位置为(xi,yi),初始亮度为si,所有星星的最大亮度为c,没过一个时间,亮度加1,达到最大c,就置为0,现在有q次询问,每此询问t时刻,(x1,y1)(x2,y2)范围里所有星星的总亮度
解析:可以直接二维树状数组来做预处理,也可以用类似一个前缀和的东西来预处理出来,比如dp[i][j][k]表示从(1,1)到(i,j)这个区域亮度为k的星星有多少个,然后查询的时候减一下即可
#include <bits/stdc++.h>using namespace std;int dp[105][105][15];int main(void){ int n,q,c; scanf("%d %d %d",&n,&q,&c); for(int i=0;i<n;i++) { int x,y,c; scanf("%d %d %d",&x,&y,&c); dp[x][y][c]++; } for(int i=1;i<105;i++) { for(int j=1;j<105;j++) { for(int k=0;k<=c;k++) dp[i][j][k] += dp[i-1][j][k]+dp[i][j-1][k]-dp[i-1][j-1][k]; } } while(q--) { int x1,y1,x2,y2,t; scanf("%d %d %d %d %d",&t,&x1,&y1,&x2,&y2); int ans = 0; for(int i=0;i<=c;i++) { int v = (t+i)%(c+1); int tmp = dp[x2][y2][i]+dp[x1-1][y1-1][i]-dp[x1-1][y1][i]-dp[x1][y1-1][i]; ans += v*tmp; } printf("%d\n",ans); } return 0;}
#include <bits/stdc++.h>using namespace std;int a[105][105][20];int lowbit(int x){ return x&(-x);}void update(int x,int y,int s){ for(int i=x;i<105;i+=lowbit(i)) { for(int j=y;j<105;j+=lowbit(j)) a[i][j][s]++; }}int query(int x,int y,int s){ int ans = 0; for(int i=x;i>0;i-=lowbit(i)) { for(int j=y;j>0;j-=lowbit(j)) ans+=a[i][j][s]; } return ans;}int main(){ int n,q,c; cin>>n>>q>>c; while(n--) { int x,y,s; scanf("%d%d%d",&x,&y,&s); update(x,y,s); } while(q--) { int t,x1,y1,x2,y2; scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2); int ans = 0; for(int i=0;i<=c;i++) { int t1 = query(x2,y2,i); int t2 = query(x1-1,y2,i); int t3 = query(x2,y1-1,i); int t4 = query(x1-1,y1-1,i); ans += (i+t)%(c+1)*(t1-t2-t3+t4); } printf("%d\n",ans); } return 0;}
阅读全文
1 0
- Codeforces 835C-Star sky
- codeforces 835 C Star sky
- Codeforces 835 C Star sky
- CodeForces 835C Star sky
- codeforces 835c Star sky
- C. Star sky Codeforces
- Codeforces #835C: Star Sky 题解
- 【Codeforces 835 C. Star sky】+ dp
- CodeForces 835 C.Star sky(水~)
- codeforces 835C Star sky(二维树状数组)
- codeforces 835-C. Star sky(dp+前缀和)
- codeforces 835C Star sky (二维数组前缀和)
- Codeforces 835 C Star sky(前缀和)
- CF -- 835C Star sky 【dp + 预处理】
- CodeFroces 835C. Star sky(构造题)
- C. Star sky(Codeforces Round #427 (Div. 2) C)
- Codeforces 835C Star sky【思维+暴力预处理二维前缀和】
- Codeforces Round #427 (Div. 2)C. Star sky
- es6 javascript对象方法Object.assign()
- notepad++使用指南
- 怎么使用stm32写IAP的bootloader和APP
- JQuery 源码分析
- Hql参数的绑定
- CodeForces 835C Star sky
- 【转】css样式自动换行(强制换行)
- filter拦截修改response
- CSU-ACM2017暑期训练3-递推与递归 Erratic Expansion
- 来自<c primer plus >的随记
- [LeetCode] 529. Minesweeper
- git使用方法
- Git 首次使用心得
- 2017年8月1日,星期二