Warm up 2
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 602 Accepted Submission(s): 306

Problem Description
  Some 1×2 dominoes are placed on a plane. Each dominoe is placed either horizontally or vertically. It's guaranteed the dominoes in the same direction are not overlapped, but horizontal and vertical dominoes may overlap with each other. You task is to remove some dominoes, so that the remaining dominoes do not overlap with each other. Now, tell me the maximum number of dominoes left on the board.

Input
  There are multiple input cases.
  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.

Output
  For each test case, output the maximum number of remaining dominoes in a line.

Sample Input
2 3
0 0
0 3
0 1
1 1
1 3
4 5
0 1
0 2
3 1
2 2
0 0
1 0
2 0
4 1
3 2
0 0

Sample Output
4
6

求不交叉最大的数量,求最大独立集合=N+M-最大匹配。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7
 8 int g[1001][1001];
 9 int link[1001][1001];
10 int cx[1001];
11 int cy[1001];
12 int mk[1001];
13 int n,m;
14
15 void init()
16 {
17     memset(cx,0xff,sizeof(cx));
18     memset(cy,0xff,sizeof(cy));
19     memset(link,0,sizeof(link));
20     memset(g,0,sizeof(g));
21 }
22
23 int path(int u)
24 {
25     int v;
26     for(v=0;v<=m;v++)
27     {
28         if(!mk[v]&&link[u][v])
29         {
30             mk[v]=1;
31             if(cy[v]==-1||path(cy[v]))
32             {
33                 cx[u]=v;
34                 cy[v]=u;
35                 return 1;
36             }
37         }
38     }
39     return 0;
40 }
41
42 int maxmatch()
43 {
44     int i;
45     int sum=0;
46     for(i=0;i<=n;i++)
47     {
48         if(cx[i]==-1)
49         {
50             memset(mk,0,sizeof(mk));
51             sum+=path(i);
52         }
53     }
54     return sum;
55 }
56
57 int main()
58 {
59     while(scanf("%d%d",&n,&m)!=EOF)
60     {
61         init();
62         if(!n&&!m)break;
63         int i;
64         for(i=1;i<=n;i++)
65         {
66             int s,e;
67             scanf("%d%d",&s,&e);
68             g[s][e]=-i;
69             g[s+1][e]=-i;
70         }
71         for(i=1;i<=m;i++)
72         {
73             int s,e;
74             scanf("%d%d",&s,&e);
75             if(g[s][e]<0)
76             {
77                 g[s][e]=-g[s][e];
78                 link[g[s][e]][i]=1;
79             }
80             if(g[s][e+1]<0)
81             {
82                 g[s][e+1]=-g[s][e+1];
83                 link[g[s][e+1]][i]=1;
84             }
85             g[s][e]=i;
86             g[s][e+1]=i;
87         }
88         int ans=maxmatch();
89         printf("%d\n",n+m-ans);
90     }
91     return 0;
92 }

View Code

转载于:https://www.cnblogs.com/zafuacm/p/3217997.html

HDU4619--Warm up 2相关推荐

  1. HDU 4619 Warm up 2 最大独立集

    Warm up 2 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4619 Description Some 1×2 dominoes are pla ...

  2. HDU4612 Warm up

    Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s ...

  3. HDU4612 Warm up —— 边双联通分量 + 重边 + 缩点 + 树上最长路

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4612 Warm up Time Limit: 10000/5000 MS (Java/Ot ...

  4. 【学习率预热】Warm up

    1.什么是warm up   Warmup是在ResNet论文中提到的一种学习率预热的方法,它在训练开始的时候先选择使用一个较小的学习率,训练了一些epoches或者steps(比如4个epoches ...

  5. Resnet-18-训练实验-warm up操作

    实验数据:cat-dog 二分类,训练集:19871 验证集:3975 实验模型:resnet-18 batchsize:128*2 (一个K80吃128张图片) 存在的问题: 对训练集 accura ...

  6. Agent with Warm Start and Active Termination for Plane Localization in 3DUltrasound基于强化学习的超声标准切面

    目录 摘要 方法 平面定位的深度强化学习框架 动作Action 状态State 奖励Reward 智能体Agent 回放缓存Replay Buffer 损失Loss 热启动的特征点感知平面对准 过程 ...

  7. Ultra Light Waterproof Jacket 2014 Warm down Coats Cheap

    Regardless, thе arroyo covering is beautiful and will endure a continued time. Most of thе time, Ult ...

  8. Sentinel流控效果—Warm Up

    流控效果Warm Up有什么作用? 比如有一个系统平常没人访问,突然某个时刻系统访问量达到最大:这样的话系统容易崩掉,所以需要预热,让请求慢慢的升高: 比如:秒杀系统在开启的瞬间,会有很多流量上来,很 ...

  9. 【warm up】热身训练 的学习率设置

    warm up 策略 一.介绍 二.使用场景 三.有效原因 一.介绍 warmup 顾名思义就是热身,在刚刚开始训练时以很小的学习率进行训练,使得网络熟悉数据,随着训练的进行学习率慢慢变大,到了一定程 ...

  10. SONiC Warm Reboot

    原文:https://github.com/jipanyang/SONiC/blob/69d76c5fd2d870e2c53cbe367fd09927bb4836ba/doc/warm-reboot/ ...

最新文章

  1. html input不可编辑
  2. 活动预告丨SMP十周年系列论坛第一期:社交机器人论坛开幕
  3. hao123电脑版主页_生活小技巧003:电脑主页被恶意篡改怎么办?
  4. c matlab 混合编程 调试,64位MATLAB和C混合编程以及联合调试
  5. 【职场】遇到了个失业开滴滴的程序员
  6. 程序员的数学全三册密码_阿波罗50年前成功登月,少不了这位硬核女程序员
  7. 软件项目风险评估报告00
  8. iphone主屏幕动态壁纸_iPhone8怎么设置动态壁纸?iPhone8动态壁纸设置教程
  9. Matplotlib 中文用户指南 3.5 密致布局指南
  10. 微博回应裁员;罗永浩股权被冻结;“隐形贫困”人群最爱苹果 | 极客头条
  11. PAT 1066. 图像过滤(15)-乙级
  12. Java垃圾回收jconsole分析
  13. django 轮播图上传_拼多多规则更新:关于【商品轮播图】你所不知道的秘密!...
  14. Linux下mysql5.7.18登录报错“Access denied for user 'root'@'localhost' (using password: YES”)
  15. wpsppt放映时间_wps ppt如何制作时间倒计时
  16. uniapp折叠框二级循环
  17. 文件和文件之间的 相对路径 绝对路径的访问(之前总是容易忘记)
  18. 解决Adobe Reader 打开PDF文件10秒左右自动关闭问题
  19. UI设计中线性图标设计总结
  20. RITnet: Real-time Semantic Segmentation of the Eye for Gaze Tracking

热门文章

  1. 对自我价值的高估,源自于对他人价值的否定
  2. 我们说的目标导向不是 “唯结果论”
  3. 初创公司要严控会议时长,日会5-15分钟,周会不超30分钟
  4. OpenStack 的诞生
  5. 为什么电脑能随便重装系统,而手机刷机可能刷成砖?
  6. XBOX Series X规格如此强悍,如果被破解安装了win10,将对PC行业带来什么影响?
  7. 部分公务员已领数字货币工资,数字货币或年内扩大试点,支付宝、微信支付还会有优势吗?
  8. 30年前的中专相当于现在什么学历?比现在一本厉害吗?
  9. 快速理解MapReduce
  10. sql server分页_SQL Server中的分页