【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 ...
随机推荐
- 《2017全球人工智能人才白皮书》发布丨解读世界顶级AI牛人的秘密——腾讯研究院
<2017全球人工智能人才白皮书>发布丨解读世界顶级AI牛人的秘密——腾讯研究院:下载链接:http://www.tisi.org/c16 这个报告写的很好,排版布局,表格,色调,内容都值 ...
- 洛谷P2196 && caioj 1415 动态规划6:挖地雷
没看出来动规怎么做,看到n <= 20,直接一波暴搜,过了. #include<cstdio> #include<cstring> #include<algorit ...
- TCP 三次握手,四次挥手
TCP 三次握手,四次挥手 1. TCP 三次握手 建立连接前,客户端和服务端需要通过握手来确认对方: 客户端发送 syn(同步序列编号) 请求,进入 syn_send 状态,等待确认 服务端接收并确 ...
- 二、 HBase核心功能模块。
Hadoop 框架包含两个核心组件: HDFS 和 MapReduce 其中 HDFS 是文件存储系统,负责数据存储: MapReduce 是 ...
- Java接口源码--System和应用程序进程间通信
本文參考<Android系统源代码情景分析>.作者罗升阳 一.架构代码: ~/Android/frameworks/base/core/java/android/os ----IInter ...
- 浏览器下载img标签Base64图片
https://blog.csdn.net/qq_42076140/article/details/82113622 原文地址 <a href="javascript:downl ...
- google浏览器修改网页字符编码
google浏览器修改网页字符编码 直接在google浏览器的应用拓展程序里面搜 Charset,第一个就是 于是就有了
- Snort企业部署实战
Snort企业部署实战 1 背景 我们知道企业网络目前威胁来自两个位置:一个是内部,一个是外部.来自外部的威胁都能被防火墙所阻止,但内部攻击都不好防范.因为公司内部人员对系统了解很深且有合 ...
- 原生js实现多组图片切换
这几天一直在练习原生js写效果,需要理清自己的逻辑,做了一个切换多组图片的效果: css样式: * { margin: 0; padding: 0; } body { background: #303 ...
- 【Django】模板系统
目录 一.变量 二.过滤器 Filters 2. length 3. filesizeformat 4. slice 5. add 6. first.last 7. join 8. truncatec ...