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. Java 环境搭建的一些问题

    1.http://www.eclipse.org/webtools/  eclipse 官网,SE.EE方向是两个不同eclipse 2.tomcat 对eclipse来说是一个插件,需要额外下载 T ...

  2. MySQL 视图 总结

    什么是视图 视图是从一个或多个表中导出来的表,是一种虚拟存在的表. 视图就像一个窗口,通过这个窗口可以看到系统专门提供的数据. 这样,用户可以不用看到整个数据库中的数据,而之关心对自己有用的数据. 数 ...

  3. centos6.5安装docker

    (一) 查看系统的版本和内核: $cat /etc/issue $uname -r 因为docker要求服务CentOS6以上,kernel 版本必须2.6.32-431或更高 要将Docker安装到 ...

  4. MySQL出现Errcode:28错误提示解决办法

    mysql出现Error writing file \'xxx\'( Errcode:28)的原因有很多种,下面我来总结一些常用的关于引起Errcode:28错误原因与解决方法.   问题一,是log ...

  5. Spring AOP面向切面编程的实现

    1.涉及到的几个概念 切面类.被切对象.切入点.切入时间.切入内容:(自己命的名,好理解点) 2.看配置文件 <?xml version="1.0" encoding=&qu ...

  6. HDU 5455 Fang Fang 水题,但题意描述有问题

    题目大意:f[1]=f,f[2]=ff,f[3]=ffc,以后f[n]每增加1,字符串增加一个c.给出一个字符串,求最少有多少个f[]组成.(字符串首尾相连,比如:ffcf可看做cfff) 题目思路: ...

  7. php des 加密类

    <?php/** *@see Yii CSecurityManager; */class Des{ public static function encrypt($data,$key){ $mo ...

  8. 网络获取数据的Xml的Pull解析

    网络获取的XML的Pull解析 <?xml version="1.0" encoding="utf-8" ?> - <students> ...

  9. 指针--摘自C++技术网 作者dx

    “指针是什么?”“指针就是一种数据类型.”“你确定?”“那数据类型是什么?额,这个???类型就是类型,还能怎么解释嘛.”“指针有多少种?”“指针有好多种,比如整型指针,字符指针等等.”“指针是怎么确定 ...

  10. Python基础学习6---存储器

    Python提供一个标准的模块,称为 pickle .使用它你可以在一个文件中储存任何Python对象,之后你又可以把它完整无缺地取出来.这被称为 持久地 储存对象.还有另一个模块称为 cPickle ...