jsc2019_qualE Card Collector
题目大意
给你n个点的坐标和权值
问先在每一行选一个点再在每一列选一个没选过的点
求最大权值和
分析
可以想到将点转化为边,将两个坐标对应两个点
所以问题转化为选H+W个边
使得所有边的度都不为0
则最终这个图就会变为若干联通块
每个个联通块正好有一个环
我们将边权从大到小排序
然后并查集维护一下联通块信息和是否正好包含一个环即可
代码
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<string>
- #include<algorithm>
- #include<cctype>
- #include<cmath>
- #include<cstdlib>
- #include<queue>
- #include<ctime>
- #include<vector>
- #include<set>
- #include<map>
- #include<stack>
- using namespace std;
- #define int long long
- struct node {
- int x,y,w;
- };
- node d[];
- int n,m,H,W,fa[],is[];
- long long Ans;
- inline int sf(int x){return fa[x]==x?x:fa[x]=sf(fa[x]);}
- inline bool cmp(const node a,const node b){return a.w>b.w;}
- signed main(){
- int i,j,k;
- scanf("%lld%lld%lld",&m,&H,&W);
- n=H+W;
- for(i=;i<=n;i++)fa[i]=i;
- for(i=;i<=m;i++){
- scanf("%lld%lld%lld",&d[i].x,&d[i].y,&d[i].w);
- d[i].y+=H;
- }
- sort(d+,d+m+,cmp);
- for(i=;i<=m;i++){
- int x=d[i].x,y=d[i].y;
- if(sf(x)!=sf(y)){
- if(is[sf(x)]&&is[sf(y)])continue;
- is[sf(y)]|=is[sf(x)];
- fa[sf(x)]=sf(y);
- Ans+=d[i].w;
- }else {
- if(!is[sf(x)]){
- is[sf(x)]=;
- Ans+=d[i].w;
- }
- }
- }
- printf("%lld\n",Ans);
- return ;
- }
jsc2019_qualE Card Collector的更多相关文章
- HDOJ 4336 Card Collector
容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 4336:Card Collector(容斥原理)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Special Judge Problem Descriptio ...
- Card Collector(HDU 4336)
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu4336 Card Collector 状态压缩dp
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 4336 Card Collector(动态规划-概率DP)
Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...
- HDU 4336 Card Collector 期望dp+状压
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...
- 【HDU4336】Card Collector(Min-Max容斥)
[HDU4336]Card Collector(Min-Max容斥) 题面 Vjudge 题解 原来似乎写过一种状压的做法,然后空间复杂度很不优秀. 今天来补一种神奇的方法. 给定集合\(S\),设\ ...
- 【HDU4336】Card Collector (动态规划,数学期望)
[HDU4336]Card Collector (动态规划,数学期望) 题面 Vjudge 题解 设\(f[i]\)表示状态\(i\)到达目标状态的期望 \(f[i]=(\sum f[j]*p[j]+ ...
- HDU 4336——Card Collector——————【概率dp】
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- python+selenium文本框对象以及按钮对象操作
文本框对象 from selenium import webdriverfrom time import sleep driver = webdriver.Firefox() # 指定和打开浏览器ur ...
- 排序算法六:计数排序(Counting sort)
前面介绍的几种排序算法,都是基于不同位置的元素比较,算法平均时间复杂度理论最好值是θ(nlgn). 今天介绍一种新的排序算法,计数排序(Counting sort),计数排序是一个非基于比较的线性时间 ...
- javascript实现深浅拷贝
深浅拷贝通常是对于引用数据类型进行的(数据类型为:对象(Object).数组(Array).函数(Function)) 浅拷贝: let obj = {id: 1, name: 2}; let new ...
- oracle--表分区、分区索引
--|/ range分区 create table sale( product_id varchar2(5), sale_count number(10,2) ) partition by range ...
- oracle--约束(主键、非空、检查)
问题1:学号重复了,数据还可以插入成功 使用主键约束:学号是唯一标识一条数据的,所以必须唯一且不能为空 ---(1).在确定为主键的字段后添加 primary key关键字 ---(2).在创建表的后 ...
- 396. Coins in a Line III
刷 July-31-2019 换成只能从左边或者右边拿.这个确实和Coins in a Line II有关系. 和上面思路一致,也是MinMax思路,只不过是从左边和右边选,相应对方也是这样. pub ...
- Git-第一篇认识git,核心对象,常用命令
1.git一般使用流程 4大核心对象:工作区.暂存区.本地库.远端库. 2.常用命令 1>git init:初始化本地仓库 2>git clone:克隆仓库到指定地方 3>git a ...
- java_第一年_JavaWeb(13)
JSTL标签库——核心标签库 为了弥补html标签的不足,为了更加方便地在jsp页面中使用java逻辑代码,JSTL标签库因运而生,而其中的佼佼者,被恩宠最多的就是核心标签库了: 核心标签库从功能上可 ...
- Neo4j 不区分大小写的模糊查询匹配
问题:当图数据库中存储的节点的名字为英文时,就会遇到大小写不匹配问题. 使用不区分大小写的正则表示式可以解决以上问题. Cpyher的where语法里支持正则表达式 ,其语法为 : =~ &quo ...
- Solr的学习使用之(六)获取数据列表-SolrDocumentList
以下是我项目中获取新闻数据列表的写法,包括数据总量.数据列表,接下来会贴出分片查询(facet)等高级查询 基本的注释都有了: private ListPage<News> queryFr ...