2013多校联合2 I Warm up 2(hdu 4619)
Warm up 2
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 243 Accepted Submission(s): 108
The first line of each case are 2 integers: n(1 <= n <= 1000), m(1 <= m <= 1000), indicating the number of horizontal and vertical dominoes.
Then n lines follow, each line contains 2 integers x (0 <= x <= 100) and y (0 <= y <= 100), indicating the position of a horizontal dominoe. The dominoe occupies the grids of (x, y) and (x + 1, y).
Then m lines follow, each line contains 2 integers x (0 <= x <= 100) and y (0 <= y <= 100), indicating the position of a horizontal dominoe. The dominoe occupies the grids of (x, y) and (x, y + 1).
Input ends with n = 0 and m = 0.
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#define maxn 110
using namespace std;
int map[maxn][maxn];
int vis[2010];
struct edge
{
int to;
int next;
}e[20010];
int box[2010],cnt;
void init()
{
cnt=0;
memset(box,-1,sizeof(box));
}
void add(int from,int to)
{
e[cnt].to=to;
e[cnt].next=box[from];
box[from]=cnt++;
}
int dfs(int now)
{
vis[now]=1;
int num=1;
for(int t=box[now];t+1;t=e[t].next)
{
int v=e[t].to;
if(!vis[v])
num+=dfs(v);
}
return num;
}
int main()
{
//freopen("dd.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m)&&(m+n))
{
int i,x,y;
init();
memset(map,0,sizeof(map));
for(i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=map[x+1][y]=i;
}
for(i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
if(map[x][y])
{
add(map[x][y],i+n);
add(i+n,map[x][y]);
}
if(map[x][y+1])
{
add(map[x][y+1],i+n);
add(i+n,map[x][y+1]);
}
}
int ans=0;
memset(vis,0,sizeof(vis));
for(i=1;i<=n+m;i++)
{
if(!vis[i])
{
int tmp=dfs(i);
ans+=(tmp+1)/2;
}
}
printf("%d\n",ans);
}
return 0;
}
2013多校联合2 I Warm up 2(hdu 4619)的更多相关文章
- 2013 多校联合 F Magic Ball Game (hdu 4605)
http://acm.hdu.edu.cn/showproblem.php?pid=4605 Magic Ball Game Time Limit: 10000/5000 MS (Java/Other ...
- HDU 多校联合练习赛2 Warm up 2 二分图匹配
Warm up 2 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
- 2013 多校联合2 D Vases and Flowers (hdu 4614)
Vases and Flowers Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others ...
- 2013 多校联合 2 A Balls Rearrangement (hdu 4611)
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- 2013多校联合3 G The Unsolvable Problem(hdu 4627)
2013-07-30 20:35 388人阅读 评论(0) 收藏 举报 http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Pr ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- 2016暑假多校联合---Substring(后缀数组)
2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...
- 2016暑假多校联合---To My Girlfriend
2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...
随机推荐
- 符合altium designer操作习惯的cadence快捷键设置
本人开始学习画PCB的时候,用的都是protel,后来转投altium desinger,因为这两个软件上手快且大学里教的也就是这两种.但由于工作需要换成cadence,这就给我造成了很大的困扰,尤其 ...
- 转一篇:Hyper-V和VMware的高可用实时迁移技术详解
ESX里以集群的ha.drs.dpm功能实现 HYPER-V里以集群+共享存储实现. ~~~~~~~~~~ 微软公司的Hyper-V虚拟化管理程序一经面世就引发了业界的普遍关注.本文意在对Hyper- ...
- LeetCode——Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- C语言中for循环的使用
for循环的作用: 注意:要主要满足条件一和二后是先执行语句,后再执行条件三. 简单重复的输出 for(int i=0:i<10;i++){ printf("对一句话简单重复输出输出1 ...
- Android Studio开发环境部署
Step0:背景,那些年-- Step1:安装JDK Step2:安装Android Studio 其他问题1:安装Android Studio之前没有先安装JDK 其他问题2:No JVM inst ...
- 火狐解决 OCSP 回应包含过期信息的问题_firefox吧_百度贴吧
火狐解决 OCSP 回应包含过期信息的问题_firefox吧_百度贴吧 火狐解决 OCSP 回应包含过期信息的问题
- 同时安装Xcode6和Xcode7导致出现N多UUID 模拟器解决办法
[摘要:1.完整退出Xcode 和 摹拟器 2.末端中输进以下两居指令 $ sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService$ ...
- 让Barebox正确引导Tiny6410的linux内核
本文专属tiny6410吐槽系列~如有得罪,请多包涵~在此也留个联系方式~291222536@qq.com,欢迎大家一起交流吐槽心得~ 上节各位搞得如何~这次怎么修改barebox的一些小细节,并且配 ...
- lesson4:使用锁Lock来解决重复下单的问题
demo源码:https://github.com/mantuliu/javaAdvance 中的类Lesson4IndependentLock 在上一节中,我们分析了Lock的源代码并一起实践了粗粒 ...
- 微设计(www.weidesigner.com)介绍系列文章(二)
微设计(www.weidesigner.com)是一个专门针对微信公众账号提供营销推广服务而打造的第三方平台. 2.1 怎样注冊微信公众号? 登录mp.weixin.qq.com,点击注冊填写相关信息 ...