ural1628 White Streaks

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

inputoutput
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+10;
const int dis[][2]={0,1,-1,0,0,-1,1,0};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}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,1,k)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        a[x].pb(y),b[y].pb(x);
    }
    rep(i,1,n)
    {
        a[i].pb(m+1);
        sort(a[i].begin(),a[i].end());
        now=0;
        for(int x:a[i])
        {
            if(x-now>2)ans++;
            now=x;
        }
    }
    rep(i,1,m)
    {
        b[i].pb(n+1);
        sort(b[i].begin(),b[i].end());
        now=0;
        for(int x:b[i])
        {
            if(x-now>2)ans++;
            else if(x-now==2)
            {
                int y=x-1,pre=0;
                for(int r:a[y])
                {
                    if(r>i)
                    {
                        if(r-pre==2)ans++;
                        break;
                    }
                    pre=r;
                }
            }
            now=x;
        }
    }
    printf("%d\n",ans);
    //system("Pause");
    return 0;
}

转载于:https://www.cnblogs.com/dyzll/p/5831867.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值