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. Openjudge 1.13-21:最大质因子序列

    总时间限制:  1000ms 内存限制:  65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...

  2. ABAP,Java, nodejs和go语言的web server编程

    ABAP and Java see my blog. nodejs 用nodejs现成的express module,几行代码就能写个server出来: var express = require(' ...

  3. URAL 2047 Maths (数学)

    对于一个数来说,它的除数是确定的,那么它的前驱也是确定的,而起点只能是1或2,所以只要类似筛法先预处理出每个数的除数个数 ,然后递推出每个数往前的延伸的链长,更新最大长度,记录对应数字.找到maxn以 ...

  4. Data truncation: Data too long for column 'id' at row 1

    Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'titleimg' at ro ...

  5. 如何在Ubuntu 16.04上安装Apache Web服务器

    转载自:https://www.howtoing.com/how-to-install-the-apache-web-server-on-ubuntu-16-04 介绍 Apache HTTP服务器是 ...

  6. Java数据结构和算法(五)--希尔排序和快速排序

    在前面复习了三个简单排序Java数据结构和算法(三)--三大排序--冒泡.选择.插入排序,属于算法的基础,但是效率是偏低的,所以现在 学习高级排序 插入排序存在的问题: 插入排序在逻辑把数据分为两部分 ...

  7. 安装vc++6.0的步骤

    我们学习计算机,就必须要先将编程的c语言学好,打好基础,学习c语言最好的方法就是多上机联系,对于联系我们需要在自己的电脑上安装vc++6.0来进行平日里的联系.1.打开电脑进行联网,打开浏览器搜索vc ...

  8. Js图片缩放代码 鼠标滚轮放大缩小 图片向右旋转

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 【动态规划】luoguP1941 飞扬的小鸟

    细节总是打挂选手:) 题目描述 Flappy Bird是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面右方的管道缝隙.如果小鸟一不小心撞到了水管 ...

  10. 微信小程序 wx.request POST请求------中文乱码问题

    问题: 一个简单的表单,提交后台返回数据“提交成功”. 以为没问题了,但是没过多久后台小哥就问为啥那么多乱码,找了很久原因,发现在提交的时候就已经乱码了. 嗯,前端问题,然后测试GET/POST方法. ...