Codeforces 325D
#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的更多相关文章
- Codeforces Round #325D (Div. 2) (DP)
题目链接: D. Phillip and Trains 分析:dp 我们先初始化,dp[i]表示当前列第i行是否可达,r[i]表示上一个dp值,接下来从头搜到尾 如果该位置满足s[i+1]=='.'且 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 为什么我们需要性能测试,需要loadrunner
什么是功能: 功能按我理解就是软件实现需求,提供服务,那么功能测试就是实现的需求是否与客户给定需求一致,也就是符合预期结果 什么是性能: 功能是实现需求,提供服务,那么性能就可以理解为服务的好坏.比如 ...
- 中国大学MOOC-翁恺-C语言程序设计习题集
今年网易出了“中国大学MOOC”,于是选了浙大翁恺老师的“C语言程序设计”学习,近期打算把自己在该课程中的PAT习题解答做一个记录,等自己编程能力提高后再来看现在写的代码哪里还有写的不好,可以改进的地 ...
- Nginx Upload Module 上传模块
传统站点在处理文件上传请求时,普遍使用后端编程语言处理,如:Java.PHP.Python.Ruby等.今天给大家介绍Nginx的一个模块,Upload Module上传模块,此模块的原理是先把用户上 ...
- XML的DTD约束
DTD约束:DTD的声明和引用 1.内部DTD文档 <!DOCTYPE 根元素 [定义内容]> 2.外部DTD文档 <!DOCTYPE 根元素 SYSTEM "DTD文件路 ...
- openssl 加密
OpenSSL是一个强大的安全套接字层密码库,Apache使用它加密HTTPS,OpenSSH使用它加密SSH, 但是,你不应该只将其作为一个库来使用,它还是一个多用途的.跨平台的密码工具.
- Chapter 4. Button, Checkbutton, and Radiobutton Widgets 按钮,复选按钮,单选按钮
Chapter 4. Button, Checkbutton, and Radiobutton Widgets 按钮,复选按钮,单选按钮 几乎所有的Perl/Tk 应用使用按钮以这样或者那样的方式 ...
- boost库的安装,使用,介绍,库分类
1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...
- CreateThread线程函数
之前在一篇 基于TCP套接字实现的简单Demo 一文中用到了线程函数CreateThread()函数来 创建新的线程.下面以一个最简单的多线程例子来说明. C-代码如下: //最简单的创建多线程实 ...
- centos Ddos防范开源软件使用及apache ab压测 测试
1,检索特定字符的相同行,用于过滤点一些命令行的头说明
- STL集合容器set按照由小到大或者由大到小的顺序存放元素
(1)由小到大 set<int,less<int>> M; M.insert(1960); M.insert(1952); M.insert(1771); M.insert(1 ...