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. COGS 1578. 次小生成树初级练习题

    ☆   输入文件:mst2.in   输出文件:mst2.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 求严格次小生成树 [输入格式] 第一行包含两个整数N 和M,表 ...

  2. 迅为4412开发板Linux设备树的镜像烧写和源码简单优化教程

    1 烧写:   烧写和4412默认镜像的烧写类似,使用fastboot. 先更新uboot,用4412默认uboot更新支持设备树的uboot 用支持设备树的uboot烧写. 进入支持设备树的uboo ...

  3. Luogu P4593 [TJOI2018]教科书般的亵渎

    亵渎终于离开标准了,然而铺场快攻也变少了 给一个大力枚举(无任何性质)+艹出自然数幂和的方法,但是复杂度极限是\(O(k^4)\)的,不过跑的好快233 首先简单数学分析可以得出\(k=m+1\),因 ...

  4. ERROR 14856 --- [reate-882003853] com.alibaba.druid.pool.DruidDataSource : create connection error, url: jdbc:mysql://localhost:3306/xhb?useUnicode=true&characterEncoding=UTF-8, errorCode 1045, sta

    ERROR 14856 --- [reate-882003853] com.alibaba.druid.pool.DruidDataSource : create connection error, ...

  5. 安装VC++6.0实验环境

    安装VC++6.0步骤:(1)下载一个压缩包进行解压(2)点击打开解压后的文件(3)找到文件里的程序进行安装(4)等待安装完成该程序后可以试着运行一下此程序,在此我们需要了解编写程序的步骤和注意事项. ...

  6. grub加密。

    一.介绍 安全无小事  linux系统的安全分为很多方面,什么端口啊,什么网络啊,听着都特么烦,今天谈谈最简单明显的密码安全. 二.单用户模式 单用户模式个人觉得相当有用,可以用来修复系统,修改密码… ...

  7. zabbix:告警、恢复消息次数

    之前zabbix配置告警,存在告警信息发送多次并且恢复信息也跟着发送多次了,导致企业微信流量不够用,没有找到恢复信息单独的设置项 动作中的步骤我个人理解为:1-5的意思是发送5条告警消息      3 ...

  8. 使用selenium和phantomJS浏览器获取网页内容的小演示

    # 使用selenium和phantomJS浏览器获取网页内容的小演示 # 导入包 from selenium import webdriver # 使用selenium库里的webdriver方法调 ...

  9. Django REST framework 五种增删改查方法

    Django-DRF-视图的演变   版本一(基于类视图APIView类) views.py: APIView是继承的Django View视图的. 1 from .serializers impor ...

  10. LeetCode(8)String to Integer (atoi)

    题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ca ...