首页 > 其他 > 详细

codeforces-835C. Star sky(维护二维前缀和,dp)

时间:2018-02-04 10:22:25      阅读:239      评论:0      收藏:0      [点我收藏+]

 

 传送门

在不大于100*100的地图上有星星,每个星星的亮度随时间变化,它们初始亮度不同,但能达到的最高亮度相同,为C。初始亮度为p,t时刻亮度为(p+t)%(C+1)

输入

n q c(为别代表星星数目,查询次数,最高亮度)

n行

x y s(星星的横纵坐标和初始亮度)

q行

t x1 y1 x2 y2(查询t时刻矩阵内及边界上星星的总亮度,其中(x1,y1)是矩阵左上角, (x2,y2)是矩阵右下角)

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 #define INF 0x3f3f3f3f
 6 #define MOD 1000000007
 7 using namespace std;
 8 typedef long long LL;
 9 
10 const int maxc = 15;
11 const int maxn = 110;
12 int cnt[maxc][maxn][maxn];
13 
14 int N, Q, C;
15 
16 void init() {
17     for (int k = 0; k <= C; k++) {
18         for (int i = 1; i <= 100; i++) {
19             for (int j = 1; j <= 100; j++) {
20                 cnt[k][i][j] += cnt[k][i - 1][j] + cnt[k][i][j - 1] - cnt[k][i - 1][j - 1];
21             }
22         }
23     }
24 }
25 
26 int solve(int t, int x1, int y1, int x2, int y2) {
27     int res = 0;
28     for (int k = 0; k <= C; k++) {
29         int tmp = cnt[k][x2][y2] + cnt[k][x1 - 1][y1 - 1] - cnt[k][x1 - 1][y2] - cnt[k][x2][y1 - 1];
30         res = res + ((k + t) % (C + 1)) * tmp;
31     }
32     return res;
33 }
34 
35 int main() {
36     scanf("%d%d%d", &N, &Q, &C);
37     int x, y, s;
38     for (int i = 1; i <= N; i++) {
39         scanf("%d%d%d", &x, &y, &s);
40         cnt[s][x][y]++;
41     }
42     init();
43     int t, x1, x2, y1, y2;
44     for (int i = 1; i <= Q; i++) {
45         scanf("%d%d%d%d%d", &t, &x1, &y1, &x2, &y2);
46         printf("%d\n", solve(t, x1, y1, x2, y2));
47     }
48     return 0;
49 }

 

codeforces-835C. Star sky(维护二维前缀和,dp)

原文:https://www.cnblogs.com/xFANx/p/8411356.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!