牛客网第二场Jfarm(随机化+二维前缀和)
链接:https://www.nowcoder.com/acm/contest/140/J
来源:牛客网 White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The plant in the j-th column of the i-th row belongs the a[i][j]-th type.
White Cloud wants to help White Rabbit fertilize plants, but the i-th plant can only adapt to the i-th fertilizer. If the j-th fertilizer is applied to the i-th plant (i!=j), the plant will immediately die.
Now White Cloud plans to apply fertilizers T times. In the i-th plan, White Cloud will use k[i]-th fertilizer to fertilize all the plants in a rectangle [x1[i]...x2[i]][y1[i]...y2[i]].
White rabbits wants to know how many plants would eventually die if they were to be fertilized according to the expected schedule of White Cloud. 输入描述:
The first line of input contains integers n,m,T(n*m<=,T<=)
For the next n lines, each line contains m integers in range[,n*m] denoting the type of plant in each grid.
For the next T lines, the i-th line contains integers x1,y1,x2,y2,k(<=x1<=x2<=n,<=y1<=y2<=m,<=k<=n*m)
输出描述:
Print an integer, denoting the number of plants which would die.
示例1
输入 复制 输出 复制
随机化,避免4=1+3=2+2
让他只有2+2;
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<vector>
using namespace std;
#define ll long long
int n,m,t;
int b[];
ll a[],qw;
vector<ll>g[];
int x,y,q,w,z;
int main()
{
srand(time());
scanf("%d%d%d",&n,&m,&t);
for(int i=;i<=n+;i++)
g[i].resize(m+);
for(int i=;i<=n*m;i++)
{
a[i]=(ll)rand()*+(ll)rand();
a[i]=a[i]+(ll)rand()*+(ll)rand();
}
for(int i=;i<=n*m;i++)
scanf("%d",&b[i]);
while(t--)
{ scanf("%d%d%d%d%d",&x,&y,&q,&w,&z);
g[x][y]+=a[z];
g[x][w+]-=a[z];
g[q+][y]-=a[z];
g[q+][w+]+=a[z]; }
int ans=;
for(int i=;i<=n*m;i++)
{
x=i/m+;
y=i%m;
if(y==) y=m,x--;
qw=g[x][y]+=g[x-][y]+g[x][y-]-g[x-][y-];
if(qw%a[b[i]]) ans++;
}
printf("%d",ans); return ;
}
牛客网第二场Jfarm(随机化+二维前缀和)的更多相关文章
- 牛客新年AK场之模拟二维数组
链接:https://ac.nowcoder.com/acm/contest/3800/D来源:牛客网 题目描述 Rinne 喜欢使用一种奇怪的方法背单词,现在这些单词被放在了一个 n×mn \tim ...
- 牛客网第一场E题 Removal
链接:https://www.nowcoder.com/acm/contest/139/E 来源:牛客网 Bobo has a sequence of integers s1, s2, ..., sn ...
- 牛客网第一场 A Monotonic Matrix
链接:https://www.nowcoder.com/acm/contest/139/A来源:牛客网 Count the number of n x m matrices A satisfying ...
- 牛客训练六:海啸(二维树状数组+vector函数的使用)
题目链接:传送门 思路: 二维树状数组, vector(first,last)函数中assign函数相当于将first中的函数清空,然后将last中的值赋值给first. 参考文章:传送门 #incl ...
- 牛客网暑期ACM多校训练营(第二场)J farm (二维树状数组)
题目链接: https://www.nowcoder.com/acm/contest/140/J 思路: 都写在代码注释里了,非常好懂.. for_each函数可以去看一下,遍历起vector数组比较 ...
- 牛客网训练1--------矩阵 (二份+二维矩阵hash)
不懂hash的话:https://www.cnblogs.com/ALINGMAOMAO/p/10345850.html 思路:对于一个大矩阵的每一个子矩阵都对应着一个hash值k, 当k出现2次以上 ...
- 牛客竞赛第二场D Kth Minimum Clique 贪心+bitmap
Kth Minimum Clique 题意 给出n(n<100)个点的邻接表,和n个点的权值,求第k大的团(完全子图) 分析 n很小,并且好像没有什么算法和这个有关系,所以可以往暴力枚举的方向想 ...
- 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
- 牛客网NOIP赛前集训营-普及组(第二场)和 牛客网NOIP赛前集训营-提高组(第二场)解题报告
目录 牛客网NOIP赛前集训营-普及组(第二场) A 你好诶加币 B 最后一次 C 选择颜色 D 合法括号序列 牛客网NOIP赛前集训营-提高组(第二场) A 方差 B 分糖果 C 集合划分 牛客网N ...
随机推荐
- DAX/PowerBI系列 - 参数表(Parameter Table) 度量值模板
DAX/PowerBI系列 - 参数表(Parameter Table) 度量值模板 难度: ★★☆☆☆(2星) 适用范围: ★★★☆☆(3星) 概况: 当你有多个度量值都需要计算YTD,MoM,而又 ...
- 一:window环境,LaTex快速安装(简单易懂)
一. 下载 清华开源软件镜像:点我下载 在线安装很容易失败,所以咱们选择ISO的~ 二. 安装 解压texlive2018.iso文件,并使用管理员权限打开install-tl-windo ...
- 57.搭建Vue环境
nodejs官网http://nodejs.cn/下载安装包,无特殊要求可本地傻瓜式安装,这里选择2017-5-2发布的 v6.10.3 cmd命令行: node -v //显示node版本 v6.1 ...
- input file 上传 判断文件类型、路径是否为空
<html> <body bgcolor="white"> <TABLE cellSpacing=0 cellPadding=0 width=&quo ...
- tensorflow神奇问题
运行tensorflow程序时,遇到了各种奇葩的问题,比如: 1.Import Error: DLL load failed: The specified module could not be fo ...
- Kubernetes应用健康检查
目录贴:Kubernetes学习系列 在实际生产环境中,想要使得开发的应用程序完全没有bug,在任何时候都运行正常,几乎 是不可能的任务.因此,我们需要一套管理系统,来对用户的应用程序执行周期性的健康 ...
- 使用axios优雅的发起网络请求
原文链接:https://www.jianshu.com/p/73585303fdc0 公司项目使用了vue作为技术栈,便理所应当地使用了官方推荐的axios进行网络请求,这里记录下axios的封装方 ...
- 常用模块 time sys os json pickle
# import time # print(time.time()) #秒数 # print('开始下载') # time.sleep(2) # print('下载完成') # print(time. ...
- mysql密码的查看/修改
2.Mysql的Root密码忘记----查看或修改方法 2.1)启动命令行:windows微标键+R 2.2)在命令行输入taskkill /f /im mysqld.exe 回车,暂停Mysql服务 ...
- Python文档记录
Beautiful Soup 4.2.0 文档 Python3网络爬虫开发实战 Python库-requests 文档 Selenium with Python中文翻译文档 http://www.te ...