Codeforces Round #427 (Div. 2)-C. Star sky
来源:互联网 发布:网络哪个国家强 编辑:程序博客网 时间:2024/06/09 18:48
题目: C. Star sky
The Cartesian coordinate system is set in the sky. There you can seen stars, the i-th has coordinates (xi,yi), a maximum brightnessc, equal for all stars, and an initial brightnesssi (0 ≤ si ≤ c).
Over time the stars twinkle. At moment 0 the i-th star has brightness si. Let at moment t some star has brightness x. Then at moment(t + 1) this star will have brightness x + 1, if x + 1 ≤ c, and0, otherwise.
You want to look at the sky q times. In the i-th time you will look at the momentti and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1i,y1i) and the upper right — (x2i,y2i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.
A star lies in a rectangle if it lies on its border or lies strictly inside it.
The first line contains three integers n, q, c (1 ≤ n, q ≤ 105,1 ≤ c ≤ 10) — the number of the stars, the number of the views and the maximum brightness of the stars.
The next n lines contain the stars description. Thei-th from these lines contains three integersxi,yi,si (1 ≤ xi, yi ≤ 100,0 ≤ si ≤ c ≤ 10) — the coordinates ofi-th star and its initial brightness.
The next q lines contain the views description. Thei-th from these lines contains five integersti,x1i,y1i,x2i,y2i (0 ≤ ti ≤ 109,1 ≤ x1i < x2i ≤ 100,1 ≤ y1i < y2i ≤ 100) — the moment of thei-th view and the coordinates of the viewed rectangle.
For each view print the total brightness of the viewed stars.
2 3 31 1 13 2 02 1 1 2 20 2 1 4 55 1 1 5 5
303
3 4 51 1 22 3 03 3 10 1 1 100 1001 2 2 4 42 2 1 4 71 50 50 51 51
3350
Let's consider the first example.
At the first view, you can see only the first star. At moment2 its brightness is 3, so the answer is3.
At the second view, you can see only the second star. At moment0 its brightness is 0, so the answer is0.
At the third view, you can see both stars. At moment5 brightness of the first is 2, and brightness of the second is 1, so the answer is3.
题意:给出n个星星的坐标(x_i,y_i)和初始亮度s_i。星星在t秒时的亮度为(s_i+t)%(c+1)。求在t秒时以(x1,y1)为左下角、(x2,y2)为右上角的矩形内星星的总亮度。
思路:比赛时用暴力做,总是在第八组数据超时,郁闷。早上醒来就去搜索大神博客看题解,才明白我有多笨。。。用一个三维数组a[i][j][k]记录以(i,j)为右上角的矩形内星星亮度为k的数量,然后答案就是a[x2][y2][k]-a[x1-1][y2][k]-a[x2][y1-1][k]+a[x1-1][y1-1][k]。一切玄妙尽在代码中......
Code:
#include<bits/stdc++.h>using namespace std;int a[105][105][15];int get(int x1,int y1,int x2,int y2,int k){ return a[x2][y2][k]-a[x1-1][y2][k]-a[x2][y1-1][k]+a[x1-1][y1-1][k];}int main(){ int n,q,c,x,y,s,i,j,k,t,x1,y1,x2,y2,sum; while(~scanf("%d%d%d",&n,&q,&c)){ memset(a,0,sizeof(a)); for(i=0;i<n;i++){ scanf("%d%d%d",&x,&y,&s); a[x][y][s]++; } c++; for(i=1;i<101;i++){ //求以(i,j)为右上角的矩形内星星亮度为k的数量 for(j=1;j<101;j++){ for(k=0;k<c;k++) a[i][j][k]+=a[i-1][j][k]+a[i][j-1][k]-a[i-1][j-1][k]; } } while(q--){ scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2); sum=0; for(i=0;i<c;i++) sum+=get(x1,y1,x2,y2,i)*((i+t)%c); printf("%d\n",sum); } } return 0;}
- C. Star sky(Codeforces Round #427 (Div. 2) C)
- Codeforces Round #427 (Div. 2)C. Star sky
- Codeforces Round #427 (Div. 2) C. Star sky
- Codeforces Round #427 (Div. 2)-C. Star sky
- Codeforces Round #427 (Div. 2)C. Star sky(dp)
- Codeforces Round #427 (Div. 2) C. Star sky
- 动态规划:Codeforces Round #427 (Div. 2) C Star sky
- Codeforces Round #427 (Div. 2) C. Star sky
- Codeforces Round #427 (Div. 2) C. Star sky
- Codeforces Round #427 (Div. 2)-C. Star sky(二维前缀和)
- Codeforces Round #427 (Div. 2)C. Star sky 暴力D. Palindromic characteristics
- Codeforces Round #427 (Div. 2) C. Star sky 二维前缀和
- Codeforces Round #427 (Div. 2) C. Star sky(前缀和)
- Codeforces Round #427 (Div. 2) C. Star sky(前缀和)
- Codeforces Round #427 (Div. 2) C.Star sky【模拟、二维前缀和】
- Codeforces Round #427 (Div. 2) A. Key races B. The number on the board C. Star sky
- (状态方程, 数学)Codeforces Round #427 C. Star sky
- C. Star sky Codeforces
- JAVA自动拆装箱详细说明
- How to Install Python 2.7.13 on Ubuntu & LinuxMint
- Android的gradle中compile和provided的区别
- cookie
- Java的native方法
- Codeforces Round #427 (Div. 2)-C. Star sky
- Codeforces-834D The Bakery(线段树+dp)
- struts2--拦截器,拦截器栈interceptor struts2类型转换,struts2初级视频
- timestamp与datatime的坑
- Java
- JavaSctipt语句for循环的思考
- MediaPlayer+SurfaceView基本实现+Service+分段式无缝播放
- 【转】u3d中刚体与碰撞体的理解以及is Trigger属性的意义
- Java学习第十三天