链接: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(随机化+二维前缀和)的更多相关文章

  1. 牛客新年AK场之模拟二维数组

    链接:https://ac.nowcoder.com/acm/contest/3800/D来源:牛客网 题目描述 Rinne 喜欢使用一种奇怪的方法背单词,现在这些单词被放在了一个 n×mn \tim ...

  2. 牛客网第一场E题 Removal

    链接:https://www.nowcoder.com/acm/contest/139/E 来源:牛客网 Bobo has a sequence of integers s1, s2, ..., sn ...

  3. 牛客网第一场 A Monotonic Matrix

    链接:https://www.nowcoder.com/acm/contest/139/A来源:牛客网 Count the number of n x m matrices A satisfying ...

  4. 牛客训练六:海啸(二维树状数组+vector函数的使用)

    题目链接:传送门 思路: 二维树状数组, vector(first,last)函数中assign函数相当于将first中的函数清空,然后将last中的值赋值给first. 参考文章:传送门 #incl ...

  5. 牛客网暑期ACM多校训练营(第二场)J farm (二维树状数组)

    题目链接: https://www.nowcoder.com/acm/contest/140/J 思路: 都写在代码注释里了,非常好懂.. for_each函数可以去看一下,遍历起vector数组比较 ...

  6. 牛客网训练1--------矩阵 (二份+二维矩阵hash)

    不懂hash的话:https://www.cnblogs.com/ALINGMAOMAO/p/10345850.html 思路:对于一个大矩阵的每一个子矩阵都对应着一个hash值k, 当k出现2次以上 ...

  7. 牛客竞赛第二场D Kth Minimum Clique 贪心+bitmap

    Kth Minimum Clique 题意 给出n(n<100)个点的邻接表,和n个点的权值,求第k大的团(完全子图) 分析 n很小,并且好像没有什么算法和这个有关系,所以可以往暴力枚举的方向想 ...

  8. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  9. 牛客网NOIP赛前集训营-普及组(第二场)和 牛客网NOIP赛前集训营-提高组(第二场)解题报告

    目录 牛客网NOIP赛前集训营-普及组(第二场) A 你好诶加币 B 最后一次 C 选择颜色 D 合法括号序列 牛客网NOIP赛前集训营-提高组(第二场) A 方差 B 分糖果 C 集合划分 牛客网N ...

随机推荐

  1. python dict的函数

    1. dict.clear() 删除字典内所有元素 2. dict.copy() 返回一个字典的浅复制 3. dict.fromkeys(seq[, val]) 创建一个新字典,以序列 seq 中元素 ...

  2. cocos2d-x JS 重力感应监听事件

    说明 : 下面监听中的 acc属性 里面有很多可以使用的值 . 添加监听 : cc.inputManager.setAccelerometerEnabled(true); cc.eventManage ...

  3. RAMPS1.4 3d打印控制板接线与测试

    “工欲善其事,必先利其器”,在开始工作之前,你应该准备下面所说的工具(包括软件和硬件). 1.需要下载的软件 1.1 固件上传工具——Arduino IDE 这是上传固件的必备工具,有了这个软件让上传 ...

  4. 压缩图片 Image

    图片压缩 class resizeImg: """缩略图""" def __init__(self,**args): self.args_k ...

  5. 20190402 管道符,分号,单引号,双引号,&&的使用

    :分号叫顺序执行 格式:命令:命令 && :前一条命令执行成功,后面命令继续执行:前面命令执行失败,后者不执行 格式:命令+空格&&空格+命令 || :两管道逻辑执行, ...

  6. JavaScript Dom 查找

    JavaScript Dom 查找 一.直接查找 获取单个元素 document.getElementById('i1') 获取多个元素(列表数组) document.getElementsByTag ...

  7. 03:CDN原理

    1.1 CDN简介 1.CDN作用(缓存静态资源) 1. CDN的全称Content Delivery Network,(缩写:CDN)即内容分发网络. 2. CDN解决由于网络带宽小.用户访问量大. ...

  8. Springboot 上传excel并解析文件内容

    最近在做一个物业的系统,需要通过excel上传业主的信息,解析并入库. 参考:https://www.cnblogs.com/jyyjava/p/8074322.html 话不多说,直接上核心代码 i ...

  9. shiro权限管理入门程序

    最近在学shiro,觉得入门程序还是有用的,记下来防止遗忘,也可供大家参考. package cn.itcast.shiro.authentication; import org.apache.shi ...

  10. 浅析Tomcat、JBOSS、WebSphere、WebLogic、Apache

    做任何web项目,都离不开服务器,有钱的公司用WebSphere.WebLogic,没钱公司用nginx+tomcat,不要小瞧nginx+tomcat麻雀虽小,五脏俱全. 服务器的知识,在笔试.面试 ...