标签:
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+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; }
标签:
原文地址:http://www.cnblogs.com/dyzll/p/5831867.html