P2956 [USACO09OCT]机器人犁田The Robot Plow
题目描述
Farmer John has purchased a new robotic plow in order to relieve him from the drudgery of plowing field after field after field. It achieves this goal but at a slight disadvantage: the robotic plow can only plow in a perfect rectangle with sides of integer length.
Because FJ's field has trees and other obstacles, FJ sets up the plow to plow many different rectangles, which might end up overlapping. He's curious as to just how many squares in his field are actually plowed after he programs the plow with various plow instructions, each of which describes a rectangle by giving its lower left and upper right x,y coordinates.
As usual, the field is partitioned into squares whose sides are parallel to the x and y axes. The field is X squares wide and Y squares high (1 <= X <= 240; 1 <= Y <= 240). Each of the I (1 <= I <= 200) plow instructions comprises four integers: Xll, Yll, Xur, and Yur (1 <= Xll <= Xur; Xll <= Xur <= X; 1 <= Yll <= Yur; Yll <= Yur <= Y) which are the lower left and upper right coordinates of the rectangle to be plowed. The plow will plow all the field's squares in the range (Xll..Xur, Yll..Yur) which might be one more row and column than would initially be assumed (depending on how you go about your assumptions, of course).
Consider a field that is 6 squares wide and 4 squares high. As FJ issues a pair of plowing instructions (shown), the field gets plowed as shown by '*' and '#' (normally plowed field all looks the same, but '#' shows which were most recently plowed):
...... **.... #####.
...... (1,1)(2,4) **.... (1,3)(5,4) #####.
...... **.... **....
...... **.... **....
A total of 14 squares are plowed.
POINTS: 25
Farmer John为了让自己从无穷无尽的犁田工作中解放出来,于是买了个新机器人帮助他犁田。这个机器人可以完成犁田的任务,可惜有一个小小的缺点:这个犁田机器人一次只能犁一个边的长度是整数的长方形的田地。
因为FJ的田地有树和其它障碍物,所以FJ设定机器人去犁很多不同的长方形。这些长方形允许重叠。他给机器人下了P个指令,每个指令包含一个要犁长方形的地。这片田地由长方形的左下角和右上角坐标决定。他很好奇最后到底有多少个方格的地被犁过了。
一般来说,田地被分割为很多小方格。这些方格的边和x轴或y轴平行。田地的宽度为X个方格,高度为Y个方格 (1 <= X <= 240; 1 <= Y <= 240). FJ执行了I (1 <= I <= 200)个指令,每个指令包含4个整数:Xll, Yll, Xur, Yur (1 <= Xll <= Xur; Xll <= Xur <=X; 1 <= Yll <= Yur; Yll <= Yur <= Y), 分别是要犁的长方形的左下角坐标和右上角坐标。机器人会犁所有的横坐标在Xll..Xur并且纵坐标在Yll..Yur范围内的所有方格的地。可能这个长方形会比你想象的多一行一列(就是说从第Xll列到第Xur列一共有Xur - Xll + 1列而不是Xur - Xll列)。
考虑一个6方格宽4方格高的田地。FJ进行了2个操作(如下),田地就被犁成"*"和"#"了。虽然一般被犁过的地看起来都是一样的。但是标成"#"可以更清晰地看出最近一次被犁的长方形。
一共14个方格的地被犁过了。
输入输出格式
输入格式:
Line 1: Three space-separated integers: X, Y, and I
- Lines 2..I+1: Line i+1 contains plowing instruction i which is described by four integers: Xll, Yll, Xur, and Yur
输出格式:
- Line 1: A single integer that is the total number of squares plowed
输入输出样例
6 4 2
1 1 2 4
1 3 5 4
14
说明
As in the task's example.
用差分维护区间和,最后统计。这样就避免了重复。
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<cmath>
using namespace std;
int n,m,q;
int a[][],ans;
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=,x,y,xx,yy;i<=q;i++)
{
scanf("%d%d%d%d",&x,&y,&xx,&yy);
for(int i=y;i<=yy;i++)
a[x][i]++,a[xx+][i]--;
}
for(int j=;j<=m;j++)
{
int tot=;
for(int i=;i<=n;i++)
{
tot+=a[i][j];
if(tot>) ans++;
}
}
cout<<ans;
return ;
}
P2956 [USACO09OCT]机器人犁田The Robot Plow的更多相关文章
- TYVJ P1026 犁田机器人 Label:水
背景 USACO OCT 09 2ND 描述 Farmer John為了让自己从无穷无尽的犁田工作中解放出来,於是买了个新机器人帮助他犁田.这个机器人可以完成犁田的任务,可惜有一个小小的缺点:这个犁田 ...
- P1026 犁田机器人
P1026 犁田机器人 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 USACO OCT 09 2ND 描述 Farmer John為了让自己从无穷无尽的犁 ...
- [TYVJ] P1026 犁田机器人
犁田机器人 背景 Background USACO OCT 09 2ND 描述 Description Farmer John為了让自己从无穷无尽的犁田工作中解放出来,於是买了个新机器人帮助他犁田 ...
- [Swift]LeetCode657. 机器人能否返回原点 | Robot Return to Origin
There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its mov ...
- 机器人操作系统——ROS,Robot Operating System
Note:偶然看到的滴滴研究院的无人驾驶竞赛,了解一下. ROS:专为机器人软件开发所设计出来的一套电脑操作系统架构.是一个开源的元级操作系统(后操作系统),提供类似操作系统的服务,包括硬件抽象描述. ...
- webots自学笔记(二)节点与机器人建模
原创文章,出自"博客园, _阿龙clliu" :http://www.cnblogs.com/clliu/ 上一次介绍了界面和一个简单的自由落体,然而在实际运用中,机器人的结构都是 ...
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(十七)
现在玩家选择机器人后,可以在屏幕上或手臂上点击来移动robot's arm了. 但是玩家选择一个机器人后没有视觉效果来表明哪个机器人被选中.玩家做了一个操作后没有视觉反馈会惹恼强迫症用户滴 ;) 这篇 ...
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(七)
因为到目前为止我都是在iOS模拟器中测试,但即便如此,也觉得按住手臂旋转时,手臂转动起来比较费劲,很难停止在玩家期望的位置上.因为手臂完全通过物理引擎的计算来移动,它有自身的惯性影响,所以很难控制. ...
- <ROS> 机器人描述--URDF和XACRO
文章转自 https://blog.csdn.net/sunbibei/article/details/52297524 特此鸣谢原创作者的辛勤付出 1 URDF 文件 1.1 link和joint ...
随机推荐
- Linux 进程等待队列【转】
本文转载自:http://blog.csdn.net/dlutbrucezhang/article/details/9212067 Linux内核的等待队列是以双循环链表为基础数据结构,与进程调度机制 ...
- POJ3685 Matrix —— 二分
题目链接:http://poj.org/problem?id=3685 Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissio ...
- JQuery验证成功之后,使用ajax提交数据
function checkForm(){ validator = $("#commentForm").validate({// #formId为需要进行验证的表单ID error ...
- maven实战(2)-- m2eclipse插件配置
使用eclipse进行maven项目的开发,需要安装m2eclipse插件.下面介绍该插件的配置,插件的安装在此不作介绍. 配置m2eclipse 先决条件:已安装maven,m2eclipse 以上 ...
- codeforces 672C C. Recycling Bottles(计算几何)
题目链接: C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Linux下使用pip安装keras
Keras是一个底层使用Theano或TensorFlow的深度学习框架,它的设计参考了Torch,用Python语言编写,也很方便使用Python调用,是一个高度模块化的神经网络库,支持使用GPU和 ...
- close() was never explicitly called on database
在用SQLiteDatabase的时候如果碰到说database或者cursor没有关闭,可以在使用完之后加上: if (!cursor.isClosed()) { cursor.close(); } ...
- linux下Postgresql-9.2安装及数据库的创建过程
公司写部署手册需要,现总结一些linux下postgresql的安装及数据库创建的详细步骤吧! 1.1.1 软件安装 1.设置用户组和用户级别 Postgresql不能以root身份运行,要以其 ...
- HDU-5538 House Building
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submissio ...
- UVa 1644 Prime Gap (水题,暴力)
题意:给定一个数 n,求它后一个素数和前一个素数差. 析:先打表,再二分查找. 代码如下: #pragma comment(linker, "/STACK:1024000000,102400 ...