链接: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. Oracle 11g R2创建数据库之手工建库方式

    在之前的博文当中梳理了关于DBCA静默方式创建数据库的过程,本文就手工通过SQL*PLUS客户端采用CREATE DATABASE语句创建数据库.这种建库方式就是完全使用手工SQL语句创建数据库,通常 ...

  2. 家庭记账本之微信小程序(五)

    wxml的学习 WXML(WeiXin Markup Language)是框架设计的一套标签语言,结合基础组件.事件系统,可以构建出页面的结构. 用以下一些简单的例子来看看WXML具有什么能力: 数据 ...

  3. fiddler学习总结--Web端抓包

    步骤一: Fiddler的基本配置:Tools-->option-->Connections: 就可以进行抓包了 步骤二: 可以通过一些设置过滤: 步骤三: 抓取HTTPS的请求:1.安装 ...

  4. 下拉选择插件select2赋值、创建、清空

    在select2中,设置指定值为选中状态 $("#select2_Id").val("XXXXX").select2()或者$("#latnId&qu ...

  5. Android -- 从源码带你从EventBus2.0飚到EventBus3.0

    1,最近看了不少的面试题,不管是百度.网易.阿里的面试题,都会问到EventBus源码和RxJava源码,而自己只是在项目中使用过,却没有去用心的了解它底层是怎么实现的,所以今天就和大家一起来学习学习 ...

  6. Django框架详细介绍---ORM---图书信息系统专题训练

    from django.db import models # Create your models here. # 书 class Book(models.Model): title = models ...

  7. 01-python3.5-模块导入-while-for-range-break-continue

    一.输入用户名和密码----导入getpass模块 #!/usr/bin/env python # -*- coding:utf-8 -*- #Author:XZ """ ...

  8. oracle 死锁

    oracle 死锁 --查用户名,查客户端机器 SELECT distinct s.username,s.MACHINE, s.sid||','||s.serial# FROM gv$session ...

  9. web api使用JObject接收时,报“无法创建抽象类”错误

    https://bbs.csdn.net/topics/391952288 在下列函数中增加  ModelBinders.Binders.Add(typeof(JObject), new JObjec ...

  10. kubernetes1.4新特性(一):支持sysctl命令

    sysctl是一个允许改变正在运行中的Linux系统内核参数的接口.可以通过sysctl修改Linux系统内核中的TCP/IP 堆栈和虚拟内存系统的高级选项,而且不需要重新启动Linux系统,就可以实 ...