#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
using namespace std; const int maxn=**+;
const int dx[]={-, -, -, , , , , };
const int dy[]={-, , , -, , -, , }; int n, r, c, ti;
int ans;
int fa[maxn];
bool vis[][];
int mark[maxn]; int find(int cur)
{
if (fa[cur]<) return cur;
else return (find(fa[cur]));
}
void Union(int u, int v)
{
u=find(u);
v=find(v);
if (u==v) return;
if (fa[u]>fa[v]) swap(u, v);
fa[u]+=fa[v];
fa[v]=u;
}
bool check(int &x1, int &y1)
{
if (x1< || x1>r) return false;
if (y1==) y1=c;
else if (y1>c) y1=;
if (!vis[x1][y1]) return false;
return true;
}
void merge(int x, int y)
{
int nid=(x-)*c+y;
for (int i=; i<; ++i)
{
int x1=x+dx[i];
int y1=y+dy[i];
if (check(x1, y1)) Union(nid, (x1-)*c+y1);
}
}
bool get_list(int x, int y, int id)
{
for (int i=; i<; ++i)
{
int x1=x+dx[i];
int y1=y+dy[i];
if (!check(x1, y1)) continue;
int tmp=find((x1-)*c+y1);
if (id && mark[tmp]==ti-) return false;
mark[tmp]=ti;
}
return true;
}
void solve()
{
if (c==) return;
c*=; for (int i=; i<=r; ++i)
for (int j=; j<=c; ++j)
fa[(i-)*c+j]=-; for (int i=; i<=n; ++i)
{
int x, y;
scanf("%d%d", &x, &y);
++ti;
get_list(x, y, );
++ti;
bool flag=get_list(x, y+c/, );
if (!flag) continue;
++ans;
merge(x, y);
merge(x, y+c/);
vis[x][y]=true;
vis[x][y+c/]=true;
}
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d%d%d", &r, &c, &n);
solve();
printf("%d\n", ans);
return ;
}

Codeforces 325D的更多相关文章

  1. Codeforces Round #325D (Div. 2) (DP)

    题目链接: D. Phillip and Trains 分析:dp 我们先初始化,dp[i]表示当前列第i行是否可达,r[i]表示上一个dp值,接下来从头搜到尾 如果该位置满足s[i+1]=='.'且 ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. Seafile 推出 “分布式文件同步技术” 打造的私有云服务

    近两年来 Dropbox 等云储存服务迅速窜红,各大巨头纷纷推出自家的云储存服务(苹果的 iCloud, 微软的 SkyDrive, Google 即将推出的 GDrive),国内也有类似的服务(金山 ...

  2. Inno Setup 安装前卸载原程序(转)

    很多時候我們需要在安裝文件之前卸載原有的程序而不是覆盖安装,本文的code就是实现了这样的功能. 实现原理是:從注冊表'UninstallString'項中读取卸载信息,用Exec进行静默卸载. 下面 ...

  3. Android实现ListView或GridView首行/尾行距离屏幕边缘距离

    直接上关键属性: 设置ListView或GridView的android:clipToPadding = true, 然后通过paddingTop和paddingBottom设置距离就好了.

  4. Java常见序列化与反序列方法总结

    很多商业项目用到数据库.内存映射文件和普通文件来完成项目中的序列化处理的需求,但是这些方法很少会依靠于Java序列化.本文也不是用来解释序列化的,而是一起来看看面试中有关序列化的问题,这些问题你很有可 ...

  5. Noip2013之路

    当我回望过去的一年,我想,我对自己没有任何的愧疚,因为我每一个脚印,都踩的很坚实. 第一次参加模拟赛,第一次接触NOIP的规则,虽然考得不是特别好,但是还是很有收获的,首先,数组一定要开得足够大,不然 ...

  6. centos curl web站点监控实践

    1,监控给定web站点的状态--站点请求返回代码,下载整个web站点页面文本到-o 指定的文本 curl -o /dev/null -s-silent -w--wirte-out "%{ht ...

  7. linux下如何产生core,调试core

    linux下如何产生core,调试core 摘自:http://blog.163.com/redhumor@126/blog/static/19554784201131791239753/ 在程序不寻 ...

  8. lucas模板

    ll PowMod(ll a,ll b,ll MOD){ ll ret=; while(b){ ) ret=(ret*a)%MOD; a=(a*a)%MOD; b>>=; } return ...

  9. ListView嵌套ListView时发生:View too large to fit into drawing cache的问题

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXkxMzg3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...

  10. Android 解析内存泄漏

    1.引用没释放造成的内存泄露 1.1.注册没取消造成的内存泄露        这种Android的内存泄露比纯Java的内存泄露还要严重,因为其他一些Android程序可能引用我们的Anroid程序的 ...