zoukankan      html  css  js  c++  java
  • 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
    ",ans);
        //system("Pause");
        return 0;
    }
  • 相关阅读:
    React路由基本的使用(一)
    Codeforces Round #627 (Div. 3) C
    Codeforces Round #627 (Div. 3) B
    Codeforces Round #627 (Div. 3) A
    hdu2049 不容易系列之(4)——考新郎(组合,错排)
    Codeforces Round #626 (Div. 2) E. Instant Noodles(二分图,最大公因数)
    Codeforces Round #626 (Div. 2) D. Present(位运算)
    逆元的计算方法
    Educational Codeforces Round 83 D. Count the Arrays(组合,逆元,快速幂)
    hdu4460 Friend Chains(记忆化广度优先搜索)
  • 原文地址:https://www.cnblogs.com/dyzll/p/5831867.html
Copyright © 2011-2022 走看看