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. ...
随机推荐
- 用c语言程序对显存进行操作
一.基础研究 我们之前研究过变量.数组.函数和指针,他们都可以看作是内存中存储的一段数据,当程序需要用到它们时,会通过它们的地址找到它们并进行调用,只是调用的用途不同而已:变量和数组元素是作为常量来处 ...
- UNDO 100%
另外查了下v$undostat,发现begin_time已经很久没有改变, BEGIN_TIME END_TIME MAXQUERYLEN MAXCONCU ...
- 查找最小的K个元素,使用最大堆。
查找最小的K个元素,使用最大堆,具体代码如下: #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace st ...
- 【最短路】Vijos P1046 观光旅游
题目链接: https://vijos.org/p/1046 题目大意: 给n个点(n<=100),m条无向边(m<=10000),问这张图的最小环长度. (注意:无自环,同一个点对之间的 ...
- Delphi——Window 消息 - 转载▼
Delphi是Borland公司的一种面向对象的可视化软件开发工具. Delphi集中了Visual C++和Visual Basic两者的优点:容易上手.功能强大,特别是在界面设计.数据库编程.网络 ...
- 9. memcpy() memccpy() memmove() strcpy() memset()
部分参考: http://www.cppblog.com/kang/archive/2009/04/05/78984.html 表头文件: #include <string.h>定义函数: ...
- 获取git的当前分支名称
git branch | grep \"*\" | awk -F \"_\" '{print $2}'
- 迁移ADT/ANT构建的Android项目至Gradle,a walk through。
LibModule 配置更新 9 months ago app 配置更新 9 months ago gradle/wrapper 配置更新 9 months ago screenshots ...
- 深入理解object C中复制对象的用法(二)
第五.对象的自定义拷贝 对象拥有复制特性,必须实现NSCopying,NSMutableCopying协议,实现该协议的copyWithZone方法和mutableCopyWithZone方法 深拷贝 ...
- java笔记15之this
this:是当前类的对象引用,记为该类的一个对象 注意:谁调用这个方法,在这个方法内部的this就是代表谁 解决场景: 解决局部变量隐藏成员变量 class Student { private Str ...