牛客网第二场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 ...
随机推荐
- java之动态代理
摘要 相比于静态代理,动态代理避免了开发人员编写各个繁锁的静态代理类,只需简单地指定一组接口及目标类对象就能动态的获得代理对象. 这里说的静态代理可以理解为之前使用的装饰者模式,从之前使用装饰者模式实 ...
- python基础(11)-常用模块
re(正则)模块 常用方法 findall() 以列表返回所有满足条件的结果 import re print(re.findall('\d','a1b2c2abc123'))#['1', '2', ' ...
- C#ImageList和ListView的使用
一.ImageList ImageList组件,又称为图片存储组件,它主要用于存储图片资源,然后在控件上显示出来,这样就简化了对图片的管理.ImageList组件的主要属性是Images,它包含关联 ...
- sql 小技巧
declare @pids varchar(max)='' ),pid)+','+@pids from product where pname like '%red%' select @pids
- dedecms织梦(一)
网站动静态转换 织梦后台--->系统--->系统设置--->SQL命令行工具 1.将网站所有栏目设置成动态页 update dede_arctype set isdefault=-1 ...
- 【转】AI类人工智能产品经理的丛林法则
本文转载自:https://blog.csdn.net/buptgshengod/article/details/77030338 AI是大家都很关注的领域,然而对于大部分想要入行的同学来讲,AI的算 ...
- 表单、框架结构的大概、CSS开头(选择器以及常用属性)
<!--为网页添加图标,写在头部--> <link rel="shortcut icon" href="favicon.ico(路径)" ty ...
- dart字符串处理
1.字符串创建(1)使用单引号,双引号创建字符串(2)使用三个引号或双引号创建多行字符串(3)使用r创建原始raw字符串(转义字符等特殊字符会输出出来,而不会自动被转义) (1)例如:String s ...
- Docker 部署 elk + filebeat
Docker 部署 elk + filebeat kibana 开源的分析与可视化平台logstash 日志收集工具 logstash-forwarder(原名lubmberjack)elastics ...
- ASP.NET MVC:缓存功能的设计及问题
这是非常详尽的asp.net mvc中的outputcache 的使用文章. [原文:陈希章 http://www.cnblogs.com/chenxizhang/archive/2011/12/14 ...