Warm up 2

hdu4619:http://acm.hdu.edu.cn/showproblem.php?pid=4619

题意:题目大意:给你两种纸牌 ,一种水平放置共有n张 ,一种竖直放置共有m张。水平放置的纸牌占据点(x, y)和(x + 1 , y) , 竖直放置的纸牌占据点(x , y) 和 (x , y + 1)。水平放置的牌之间不会重叠,竖直放置的牌之间也不会重叠,但是水平放置的牌和竖直放置的牌之间可能会重叠。让你拿走一些牌,使剩下的牌之间不会重叠并且数量最多,输出剩余的最大牌数。

题解:对于这一题,我的解法是,首先观察知道,相加的线段只会是横着的和竖着的交替进行,对于这样的相交来说,要删除的点就是要么啥删除全部的横着的要么删除竖着的,所以删除的总数就是总数的1/2.所以,对于相交的线段,把他们看成点,然后对形成的图,统计每个连通子图点的个数就可。这一题也可以用匹配来做,就相当于求最大独立集。

 1 #pragma comment(linker,"/STACK:100000000,100000000")//阔栈的语句
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <vector>
 5 #define pb push_back
 6 using namespace std;
 7 const int maxn = 4002;
 8 const int maxm = 3000002;
 9 struct EDGE{
10     int next, to;
11 }edge[maxm*2];
12 struct Point{
13    int x;
14    int y;
15 }num1[maxn],num2[maxn];
16 int n,m,cnt,counts,ans;
17 int head[maxn];
18 bool vis[maxn];
19 void init(){
20         cnt=0;
21     memset(head,-1,sizeof(head));
22     memset(vis,0,sizeof(vis));
23 }
24 void add(int u,int v){
25    edge[cnt].to=v;
26    edge[cnt].next=head[u];
27    head[u]=cnt++;
28 }
29 void DFS(int u){
30     if(vis[u])return;
31     counts++;
32     vis[u]=1;
33     for(int i=head[u];i!=-1;i=edge[i].next)
34         DFS(edge[i].to);
35 }
36 bool judge(int a,int b){
37   if(num1[a].x==num2[b].x&&num1[a].y==num2[b].y)return true;
38   if(num1[a].x==num2[b].x&&num1[a].y==num2[b].y+1)return true;
39   if(num1[a].x+1==num2[b].x&&num1[a].y==num2[b].y)return true;
40   if(num1[a].x+1==num2[b].x&&num1[a].y==num2[b].y+1)return true;
41   return false;
42 }
43 int main(){
44      while(~scanf("%d%d",&n,&m)&&n){
45          init();
46          for(int i=1;i<=n;i++){
47             scanf("%d %d",&num1[i].x,&num1[i].y);
48          }
49          for(int i=1;i<=m;i++){
50             scanf("%d%d",&num2[i].x,&num2[i].y);
51          }
52          for(int i=1;i<=n;i++){
53             for(int j=1;j<=m;j++){
54                 if(judge(i,j)){
55                   add(i,j+n);
56                   add(j+n,i);
57                 }
58             }
59          }
60          ans=0;
61          for(int i=1;i<=n+m;i++){
62               counts=0;
63               DFS(i);
64               ans+=(counts+1)/2;
65          }
66          printf("%d\n",ans);
67      }
68 }

Warm up 2,布布扣,bubuko.com

时间: 2024-10-10 10:02:57

Warm up 2的相关文章

HDU 4612——Warm up——————【边双连通分量、树的直径】

Warm up Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4612 Description N planets are connected by M bidirectional channels that allow instant transportation. It's always possible to travel bet

Warm up

hdu4612:http://acm.hdu.edu.cn/showproblem.php?pid=4612 题意:给你一个无向连通图,问加上一条边后得到的图的最少的割边数; 题解:首先对原图求割边数,然后缩点之后建树,然后求树的直径.因为加上一条边,能消耗最大的割边就是树的直径.一道很好的模板题目. 1 #pragma comment(linker,"/STACK:100000000,100000000")//阔栈的语句 2 #include <stdio.h> 3 #i

Hdu 4612 Warm up (双连通分支+数的直径)

题目链接: Hdu 4612 Warm up 题目描述: 给一个无向连通图,问加上一条边后,桥的数目最少会有几个? 解题思路: 题目描述很清楚,题目也很裸,就是一眼看穿怎么做的,先求出来双连通分量,然后缩点重新建图,用bfs求树的直径,直径的长度就是减去桥的数目. 这个题目需要手动扩展,而且手动扩展的话要用C++提交,G++re哭了. 1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #inclu

hdu 4612 Warm up 双连通缩点+树的直径

首先双连通缩点建立新图(顺带求原图的总的桥数,其实由于原图是一个强连通图,所以桥就等于缩点后的边) 此时得到的图类似树结构,对于新图求一次直径,也就是最长链. 我们新建的边就一定是连接这条最长链的首尾,这样就将原图的桥减少了直径个. #include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<algorithm> #include<map&g

hdu 4612 Warm up (带有重边的无向图Tarjan+树的直径)

Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 3947    Accepted Submission(s): 892 Problem Description N planets are connected by M bidirectional channels that allow instant transport

hdu 4619 Warm up 2 (二分图)

Warm up 2 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1754    Accepted Submission(s): 781 Problem Description Some 1×2 dominoes are placed on a plane. Each dominoe is placed either horizont

hdoj 4612 Warm up【双连通分量求桥&amp;&amp;缩点建新图求树的直径】

Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 5093    Accepted Submission(s): 1131 Problem Description N planets are connected by M bidirectional channels that allow instant transport

Warm neutral wind , GIU GIU 2014 autumn and winter clothing style atlas released

2013 for the evolution of men's is without a doubt a year of magnificent significance , not just by dark lines derived stamp out religious lines got a huge response , followed by neutralization of the garments out of the boom has also been an influx

HDU 4619 Warm up 2(最大流或二分匹配)

Warm up 2 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1895    Accepted Submission(s): 862 Problem Description Some 1×2 dominoes are placed on a plane. Each dominoe is placed either horizont