White Streaks

Time limit: 1.0 second
Memory limit: 64 MB
The life of every unlucky person has not only black but also white streaks. The Martian Vas-Vas has a calendar in the form of an m × n table; he marks in this calendar days when he had bad luck. If Vas-Vas had bad luck in the jth day of the ith week, he paints the cell (ij) black. Initially, all cells are white.
Let rectangles of the form 1 × l or l × 1 be called segments of life. Maximal with respect to inclusion white segments are called white streaks. Can you determine how many white streaks there were in the life of Vas-Vas?

Input

The first line contains integers mn, and k, which are the size of the calendar and the number of unlucky days in it (1 ≤ mn ≤ 30000; 0 ≤ k ≤ 60000). In the following k lines, unlucky days are given in the form of pairs (xiyi), where xi is the number of the week to which the unlucky day belongs and yi is the number of the day within this week (1 ≤ xi ≤ m; 1 ≤ yi ≤ n). Every unlucky day is given in the input only once.

Output

Output the number of white streaks in the life of Vas-Vas.

Samples

input output
3 5 4
1 1
1 5
2 2
3 3
8
5 1 2
2 1
3 1
2

分析:模拟,注意周围只有自己一个白格子时算一个;

   参照http://www.cnblogs.com/shangyu/archive/2013/10/01/3348500.html;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <hash_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=3e4+;
const int dis[][]={,,-,,,-,,};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,now,ans;
vi a[maxn],b[maxn];
int main()
{
int i,j;
scanf("%d%d%d",&n,&m,&k);
rep(i,,k)
{
int x,y;
scanf("%d%d",&x,&y);
a[x].pb(y),b[y].pb(x);
}
rep(i,,n)
{
a[i].pb(m+);
sort(a[i].begin(),a[i].end());
now=;
for(int x:a[i])
{
if(x-now>)ans++;
now=x;
}
}
rep(i,,m)
{
b[i].pb(n+);
sort(b[i].begin(),b[i].end());
now=;
for(int x:b[i])
{
if(x-now>)ans++;
else if(x-now==)
{
int y=x-,pre=;
for(int r:a[y])
{
if(r>i)
{
if(r-pre==)ans++;
break;
}
pre=r;
}
}
now=x;
}
}
printf("%d\n",ans);
//system("Pause");
return ;
}

ural1628 White Streaks的更多相关文章

  1. 1628. White Streaks(STL)

    1628 题意不太好理解 求横黑条 和竖黑条共有多少个 注意1*1的情况 如果横向纵向都是1*1 算为一个 否则不算 用了下vector  枚举找下 #include <iostream> ...

  2. imshow() displays a white image for a grey image

    Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 ...

  3. ural 2063. Black and White

    2063. Black and White Time limit: 1.0 secondMemory limit: 64 MB Let’s play a game. You are given a r ...

  4. 彩色照片转换为黑白照片(Color image converted to black and white picture)

    This blog will be talking about the color image converted to black and white picture. The project st ...

  5. HDU 5113 Black And White 回溯+剪枝

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5113 Black And White Time Limit: 2000/2000 MS (Java/ ...

  6. SCU3185 Black and white(二分图最大点权独立集)

    题目大概说有几个黑色.白色矩阵,问能选出黑白不相交的矩形面积和的最大值. 建二分图,黑色矩阵为X部的点,白色为Y部,XY的点权都为其矩阵面积,如果有个黑白矩阵相交则它们之间有一条边,那样问题就是要从这 ...

  7. White Rectangles[HDU1510]

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

  8. nVIDIA SDK White Paper ----Vertex Texture Fetch Water

    http://blog.csdn.net/soilwork/article/details/713842 nVIDIA SDK White Paper ----Vertex Texture Fetch ...

  9. Magento white screen or how XML can break your site?

    Magento white screen or how XML can break your site? by SANDO on 02. OCT, 2012 in MAGENTO, SMALL TIP ...

随机推荐

  1. js获取url传递参数,js获取url?号后面的参数

    方法一.正则表达式 function getQueryString(name) { var reg = new RegExp("(^|&)" + name + " ...

  2. 【重大bug】viewpager使用的时候加载数据应该在setOnPageChangeListener里加载

    [重大bug]viewpager使用的时候加载数据应该在setOnPageChangeListener里的onPageSelected里加载,我说怎么首页有数据,第二页就是空白,就是加载了但是数据不显 ...

  3. js实现td排序及分组分类

    如题 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...

  4. 模拟。。。 Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C

    题目大意:给你一个n*m的矩阵,再给你一个小球,从(0,0)以sqrt(2)/s的速度向右上角出发,遇到边框会反弹,遇到角落就直接停止,给你一些点,问小球第一次经过这些点所需要的时间. 思路:模拟一下 ...

  5. CREATE SCHEMA

    CREATE SCHEMA 创建一个架构,即命名空间,在这个空间中可以进一步定义包含表.视图和权限定义等对象. 语法 CREATE SCHEMA AUTHORIZATION owner    [ &l ...

  6. 直接用request.setAttribute()会报错,在这之前应该先让request获取ServletActionContext.getRequest();方法 // request.getAttribute同理

    正确流程应该是 import javax.servlet.http.HttpServletRequest; HttpServletRequst request = ServletActionConte ...

  7. 使用dom4j解析XML例子

    包括三个文件:studentInfo.xml(待解析的xml文件), Dom4jReadExmple.java(解析的主要类), TestDom4jReadExmple.java(测试解析的结果) 代 ...

  8. php 四种基础算法 ---- 插入排序法

    3.插入排序法 插入排序法思路:将要排序的元素插入到已经 假定排序号的数组的指定位置. 代码: function insert_sort($arr) {    //区分 哪部分是已经排序好的    / ...

  9. iOS进阶推荐的书目

    <Effective Objective-C 2.0:编写高质量iOS与OS X代码的52个有效方法>([英]Matt Galloway) 很多面试题有涉及 <IOS数据库应用高级编 ...

  10. sonar tomacat配置

    最近在学习Sonar,配置了好几天,才搭建起来环境,为自己的学习能力感到汗颜,赶紧在此记录一下,所谓好记性不如烂笔头. 1.Sonar介绍 Sonar是一个用于代码质量管理的开源平台,用于管理Java ...