【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的更多相关文章

  1. 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics

    [Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...

  2. 【Codeforces Round #427 (Div. 2) A】Key races

    [Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...

  3. 【Codeforces Round #427 (Div. 2) B】The number on the board

    [Link]:http://codeforces.com/contest/835 [Description] 原本有一个数字x,它的各个数码的和原本是>=k的; 现在这个数字x,在不改变位数的情 ...

  4. 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 ...

  5. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  6. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  7. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  8. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  9. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

随机推荐

  1. redis 扩展 windows

    下载地址:http://windows.php.net/downloads/pecl/releases/redis/

  2. Centos安装masscan

    1.yum install git gcc make libpcap-devel2.git clone https://github.com/robertdavidgraham/masscan3.cd ...

  3. Html Input disabled属性

    input的disabled: <input type="text" name="name" placeholder="请输入名称" ...

  4. JS触发按钮事件

    前台代码: <asp:Button ID="btnSaveBattery" runat="server" Text="保存" OnCl ...

  5. 一个Web报表项目的性能分析和优化实践(一):小试牛刀,统一显示SQL语句执行时间

    最近,在开发和优化一个报表型的Web项目,底层是Hibernate和MySQL. 当报表数据量大的时候,一个图表要花4秒以上的时间. 以下是我的分析和体会.  1.我首先需要知道哪些函数执行了多少时间 ...

  6. unity 美术注意事项

    有时候美术的一个不小心,就会给程序徒增极大的工作量,所以在项目开始之前是有必要和美术沟通一下,来规范一些东西, 1.将单体模型的轴心置中. 2.模型有父物体时,子物体应相对于父物体的(0,0,0)位置 ...

  7. centos7 nginx搭建及其反向代理

    摘要:nginx反向代理的原理:外部通过ip加端口访问nginx,nginx接收到外部请求,通过ip解析访问内部服务器,内部服务器再将数据传回Nginx服务器,而Nginx再把数据传回给外部客户机. ...

  8. jquery基本Dom操作

    1 html()获取所有的html内容 2 html(value) 设置html内容,有html自动解析 3 text() 获取文本内容 4 text(value) 设置文本内容,有html自动转义 ...

  9. vue.js原生组件化开发(一)——组件开发基础

    前言 vue作为一个轻量级前端框架,其核心就是组件化开发.我们一般常用的是用脚手架vue-cli来进行开发和管理,一个个组件即为一个个vue页面,这种叫单文件组件.我们在引用组件之时只需将组件页面引入 ...

  10. Fedora27 源配置

    一.添加阿里源,阿里源我感觉是现在国内比较好用的源,支持的发行版比较全.配置方法1.备份系统自带的源mv /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/f ...