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. ...
随机推荐
- 【HDOJ】1717 小数化分数2
简单字符串处理. #include <cstdio> #include <cstring> #include <cmath> #include <ctype. ...
- Prime邻接表+优先队列
#include <iostream> #include <cmath> #include <cstring> #include <cstdlib> # ...
- 【动态规划】XMU 1032 装配线问题
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1032 题目大意: 一个物品在2条生产线上加工,每条线上n(n<=1000)个节点 ...
- white-space norma nowrap强制同一行内显示所有文本文字,让所有文字内容中一排显示不换行
日常我们为了让文字内容在一行内显示完,哪怕宽度不够也不能换行,我们可以使用white-space样式,但如果遇到了html br强制换行标签,无论是设置white-space与否都会被<br&g ...
- jQuery(二)
jQuery学完了!好用! 1.用定时器做的jquery里面的animate效果 <!DOCTYPE html> <html lang="en"> < ...
- 苹果iOS操作系统整体架构层次讲解
iOS的系统架构分为四个层次:核心操作系统层(Core OS layer).核心服务层(Core Services layer).媒体层(Media layer)和可触摸层(Cocoa Touch ...
- Android ArrayAdapter MultiAutoCompleteTextView
MultiAutoCompleteTextView 继承自AutoCompleteTextView,它和AutoCompleteTextView不同的就是能处理多个输入字段,如发送短信界面的联系人列表 ...
- Oracle Quality --- Setup Collection Element and Collection Plan
Responsibility: Quality, Vision Enterprises 第一步: 创建 Collection Elements setup > collection elemen ...
- Java基础知识强化93:算一下你来到这个世界多少天的案例
1. 分析: (1)键盘录入你的出生年月日 (2)把该字符串转换为一个日期 (3)通过该日期得到一个毫秒值 (4)获取当前时间的毫秒值 (5)用(4)-(3)得到一个毫秒值 (6)把E的毫秒值转换为天 ...
- yii console.php 报错 Property "CConsoleApplication.theme" is not defined.
默认配置的话,是不会出现这个错误的,应该是有人为修改了 yiic.php 这个文件,本来是 $config 载入的应该是 console.php ,人为修改后载入了 main.php 这个配置文件了 ...