farm

时间限制:C/C++ 4秒,其他语言8秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

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 3 integers n,m,T(n*m<=1000000,T<=1000000)
For the next n lines, each line contains m integers in range[1,n*m] denoting the type of plant in each grid.
For the next T lines, the i-th line contains 5 integers x1,y1,x2,y2,k(1<=x1<=x2<=n,1<=y1<=y2<=m,1<=k<=n*m)

输出描述:

Print an integer, denoting the number of plants which would die.

输入

2 2 2
1 2
2 3
1 1 2 2 2
2 1 2 1 1

输出

3

题意:n*m的矩阵里,每个格子都有一个数,有t次操作,每次都会选一个小矩形区域并且选择一个数x,这个小矩形区域里的数要是不等于x,这个数就会消失,问最后有多少个数会消失。
反过来想,这个数要是不消失,那么一旦这个数被选中,x肯定是等于这个数的。若把每一次的操作变成给矩形区域里都加上数x,那么最后若一个格子里的总和可以整除格子里的数,这个数则会有很大概率不消失。
于是考虑给矩阵里的数重新分配权值,且每次操作的x值也变为新的权值,这样就会很大概率避免错误情况。
#include<bits/stdc++.h>
#define N 1000100
using namespace std; vector<int>Map[N];
vector<long long>dis[N];
int Rand[N]; int main()
{
int n,m,t;
scanf("%d %d %d",&n,&m,&t); for(int i=;i<=n;i++)
{
Map[i].push_back();
dis[i].push_back();
for(int j=;j<=m;j++)
{
int a;
scanf("%d",&a);
Map[i].push_back(a);
dis[i].push_back();
}
}
srand(time());
for(int i=;i<=n*m;i++)Rand[i]=rand()*rand()%+rand(); while(t--)
{
int a,b,c,d,k;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&k); dis[a][b]+=Rand[k];
if(c+<=n) dis[c+][b]-=Rand[k];
if(d+<=m)dis[a][d+]-=Rand[k];
if(c+<=n&&d+<=m) dis[c+][d+]+=Rand[k]; } for(int i=;i<=n;i++)
{
long long now=;
for(int j=;j<=m;j++)
{
now+=dis[i][j];
if(i->=)
dis[i][j]=dis[i-][j]+now;
else
dis[i][j]=now;
}
} int ans=;
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(dis[i][j]%Rand[Map[i][j]]!=)ans++; printf("%d",ans);
return ; }

farm的更多相关文章

  1. SharePoint 2013: A feature with ID has already been installed in this farm

    使用Visual Studio 2013创建一个可视web 部件,当右击项目选择"部署"时报错: "Error occurred in deployment step ' ...

  2. How To Collect ULS Log from SharePoint Farm

    We can use below command to collect SharePoint ULS log from all servers in the Farm in PowerShell. M ...

  3. How To Restart timer service on all servers in farm

    [array]$servers= Get-SPServer | ? {$_.Role -eq "Application"} $farm = Get-SPFarm foreach ( ...

  4. ZOJ 2412 Farm Irrigation

    Farm Irrigation Time Limit: 2 Seconds      Memory Limit: 65536 KB Benny has a spacious farm land to ...

  5. nginx+iis、NLB、Web Farm、Web Garden、ARR

    nginx+iis实现负载均衡 在win2008R2上使用(NLB)网络负载均衡 NLB网路负载均衡管理器详解 [译文]Web Farm和Web Garden的区别? IIS负载均衡-Applicat ...

  6. 续并查集学习笔记——Closing the farm题解

    在很多时候,并查集并不是一个完整的解题方法,而是一种思路. 通过以下题目来体会并查集逆向运用的思想. Description Farmer John and his cows are planning ...

  7. SharePoint Error - The current user is not an SharePoint Server farm administrator

    错误截图 错误日志 位置:C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\LOGS 主要错误 The c ...

  8. hdu.1198.Farm Irrigation(dfs +放大建图)

    Farm Irrigation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu Farm Irrigation

    这题第一感觉是用搜索做,暴力就可以解决,这里将水管转换成一个个3*3的矩阵,然后搜素就可以了.写完之后确实一遍过掉了,31ms.附上代码: #include"iostream" # ...

  10. Web Fram 2 for IIS7.X(Microsoft Web Farm Framework)

    Microsoft Web Farm Framework (WFF) 2.0 是微软开发的.基于IIS 7.x的小插件,能够帮助我们轻松实现Web网站的高性能.高可用性,用来在Web服务器群上提供和管 ...

随机推荐

  1. COFF文件格式

    链接器 目录 一 COFF-Common Object File Format-通用对象文件格式... 3 COFF的文件格式与结构体... 4 文件头... 5 numberOfSections(区 ...

  2. org.springframework.beans.factory.BeanCreationException: Could not autowire

    由于我在项目中引用了如下代码,增加了 @Configurationpublic class Connection {    public @Bean HttpClientConfig httpClie ...

  3. JAVA 配置

    JAVA 版本为jdk-7u25-windows-x64 Java 下载地址为: .CLASSPATH .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.j ...

  4. MIPS汇编程序设计——四则运算计算器

    实验目的 运用简单的MIPS实现一个能够整数加减乘除的计算器,同时使自己更加熟悉这些指令吧 MIPS代码 #sample example 'a small calculater’ # data sec ...

  5. Java多线程编程核心(1)

    Java多线程编程核心(1) 停止线程 本节主要讨论如何更好停止一个线程.停止线程意味着在线程处理完成任务之前放弃当前操作. 1.停不了的线程 可能大多数同学会使用interrupt()来停止线程,但 ...

  6. shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。

    [root@localhost wyb]# cat test10.sh #!/bin/bash #使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个htm ...

  7. 什么是无符号段整数,什么又是有符号数,(c++与java语言里边的不同)

    c++中:整型数分为有符号数和无符号数两种 unsigned int a;无符号整型变量a,意思是这个数最小值为0,最大值为2的32次方-1,因为一个整型数占四个字节,一个字节8位,共32位 int ...

  8. 用函数式编程思维解析anagrams函数

    //函数式编程思维分析 这个排列函数 const anagrams = str => { if (str.length <= 2) return str.length === 2 ? [s ...

  9. JavaScript调试技巧之console.log()详解--2015-08-07

    对于JavaScript程序的调试,相比于alert(),使用console.log()是一种更好的方式,原因在于:alert()函数会阻断 JavaScript程序的执行,从而造成副作用:而cons ...

  10. webAssmebly实现js数组排序 使用custom elements和Shadow DOM自定义组件

    直接上码了……………… .wat源码 (module (type $t0 (func (param i32 i32))) (type $t1 (func (result i32))) (type $t ...