【Codeforces Round #427 (Div. 2) C】Star sky
【Link】:http://codeforces.com/contest/835/problem/C
【Description】
给你n个星星的坐标(xi,yi);
第i个星星在第t秒,闪烁值变为(si+t)%(c+1);
给你q个询问,每个询问由时间t和一个矩形的左下角和右上角组成;
问这个矩形区域内的星星闪烁值的总和;
【Solution】
朴素的做法;
a[j][k][l]表示(j,k)这个点一开始闪烁值为l的星星有多少个;
for (int i = 1;i <= q;i++){
int temp = 0;
for (int j = 1;j <= 100;j++)
for (int k = 1;k <= 100;k++)
for (int l = 0;l <= c;l++)
temp += a[j][k][l]*((t[i]+l)%(c+1));
out(temp);
}
这里可以把两层1..100的for循环,用一个前缀和省掉.
【NumberOf WA】
0
【Reviw】
【Code】
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100;
const int C = 10;
int a[N+10][N+10][C+10];
int n,q,c;
int getsum(int x1,int y1,int x2,int y2,int k){
int temp1 = a[x2][y2][k];
int temp2 = a[x2][y1-1][k];
int temp3 = a[x1-1][y2][k];
int temp4 = a[x1-1][y1-1][k];
return temp1-temp2-temp3+temp4;
}
main(){
scanf("%lld%lld%lld",&n,&q,&c);
for (int i = 1;i <= n;i++){
int x,y,s;
scanf("%lld%lld%lld",&x,&y,&s);
a[x][y][s]++;
}
for (int i = 1;i <= N;i++)
for (int j = 1;j <= N;j++)
for (int k = 0;k <= c;k++)
a[i][j][k] += a[i][j-1][k]+a[i-1][j][k]-a[i-1][j-1][k];
for (int i = 1;i <= q;i++){
int t,x1,y1,x2,y2;
scanf("%lld%lld%lld%lld%lld",&t,&x1,&y1,&x2,&y2);
int temp = 0;
for (int j = 0;j <= c;j++){
temp += getsum(x1,y1,x2,y2,j)*((j+t)%(c+1));
}
printf("%lld\n",temp);
}
}
【Codeforces Round #427 (Div. 2) C】Star sky的更多相关文章
- 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics
[Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...
- 【Codeforces Round #427 (Div. 2) A】Key races
[Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...
- 【Codeforces Round #427 (Div. 2) B】The number on the board
[Link]:http://codeforces.com/contest/835 [Description] 原本有一个数字x,它的各个数码的和原本是>=k的; 现在这个数字x,在不改变位数的情 ...
- Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
随机推荐
- Windows7 安装ubuntu双系统
家里的老笔记本是MBR分区,不支持EFI , 一开始是用U盘安装的,还对着ubuntu官网的教程,下载了官方推荐的那个u盘引导工具,安装依然会报错, 网上查询也有很多种说法,也有说是bug的,无论如何 ...
- POJ2104 K-th Number(线段树,二分,vector)
题意 不带修改区间第k小.(n<=100000) 题解 建立线段数和vector数组(vector为当前区间排列之后的序列)(归并) 然后对于每一个询问二分答案. 问题就转化为区间有多少数小于等 ...
- 前端之CSS选择器
基本选择器 元素选择器 p {color: "red";} ID选择器 #i1 { background-color: red; } 类选择器 .c1 { font-size: 1 ...
- 今日SGU 5.26
#include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl ...
- Android 查看CPU及内存
借助getprop.dumpsys来了解一些系统相关信息. 一.getprop adb shell cat /system/build.prop 文件中存放的是用于启动系统时需要的配置文件,通常可以通 ...
- hbase启动报错
前一段时间vmware上的ubuntu的hbase用不了了,而hadoop能正常的操作,非常的奇怪. 错误信息好像是connect fail, RPC什么的,看来跟网路有关. 想起以前曾经解决过hba ...
- ant安装配置问题:ANT_HOME is set incorrectly or ant could not be located. Please set ANT_HOME.
项目用到ant 1.去官网下载:http://ant.apache.org/bindownload.cgi 2.解压至安装C盘 3.设置ANT_HOME.PATh.CLASSPATH ANT_HOME ...
- Hadoop的多节点集群详细启动步骤(3或5节点)
版本1 利用自己写的脚本来启动,见如下博客 hadoop-2.6.0-cdh5.4.5.tar.gz(CDH)的3节点集群搭建 hadoop-2.6.0.tar.gz的集群搭建(3节点) hadoop ...
- Python(六) Python 函数
一.认识函数 help(方法名字) help(round) 1.功能性 2.隐藏细节 3.避免编写重复的代码 4.组织代码 自定义函数 二.函数的定义及运行特点 # 递归 def sum_num(n ...
- msiexec
msiexec: runCmd = new String[]{ "msiexec", "/i", exeName, "/quiet", &q ...