HDU 5506(GT and set)
题意:
表示看了很久,然而发现还是没看懂题.
正解:给你a个集合,让你把他们合并成k个,当两个集合有公共数字时可以合并。
(一直以为是合并后,每个集合至少有两个数字相同- -,这英语也是醉了)
思路:
所以我们应该选择k个覆盖集合尽可能大的数,所以进行k次查找,每次找出没合并集合中最大的一个。
然后再判断是否所有集合都被覆盖了。
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <functional>
#include <algorithm>
#include <memory> using namespace std;
int tmax;
int a;
int vis[305];
int n,k,m; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
tmax = 0;
vector<int>q[305];
for(int i = 0; i <= n; i++)
q[i].clear();
for(int i = 0; i < n; i++)
{
scanf("%d",&m);
memset(vis,0,sizeof(vis));
for(int j = 0; j < m; j++)
{
scanf("%d",&a);
tmax= max(tmax,a);
q[a].push_back(i); //每个数所占的集合
}
} int c = 0;
while(c < k)
{
int num = -1;
int position = -1;
for(int j = 0; j <= tmax; j++)
{
int tt = 0;
for(int i = 0; i < q[j].size(); i++)
{
if(!vis[q[j][i]])
{
tt++;
}
}
if(tt > num) //找出覆盖最大的J
{
num = tt;
position = j;
}
}
for(int i = 0; i < q[position].size(); i++) //把J覆盖的除去
vis[q[position][i]] = 1;
c++;
}
int flag = 0;
for(int i = 0; i < n; i++)
{
if(!vis[i])
{
flag = 1;
break;
}
}
if(flag )
printf("No\n");
else
printf("Yes\n");
}
}
HDU 5506(GT and set)的更多相关文章
- HDU 5506 - BestCoder Round #60 - GT and set
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1003 题意 : 给N集 ...
- hdu 5506 GT and set dfs+bitset优化
GT and set Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Probl ...
- hdu 5506 GT and set(dfs爆搜)
Problem Description You are given N sets.The i−th set has Ai numbers.You should divide the sets into ...
- HDU 5506:GT and set bitset+暴力
GT and set Accepts: 35 Submissions: 194 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 655 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- DES MEI号码加密
对于加密来说,使用DES加密解密很好,但是为了使不同设备的密文不一样,可以使用 固定字符串 + 设备IMEI号码 加密的方式,这样可以分辨不同手机,限制手机的使用(若是注册,一个手机只有一个IMEI号 ...
- Python基础学习篇章二
一. Python如何运行程序 1. 在交互模式下编写代码 最简单的运行Python程序的方法是在Python交互命令行中输入程序.当然有很多方法可以开始这样的命令行,比如IDE,系统终端.如果你已经 ...
- 微信号的openid的深入理解
header('Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$this->appid.'&r ...
- Linq 集合操作符 Except,Intersect,Union
IList<string> s1 = new List<string>() { "One", "Two", "Three&qu ...
- 微信小程序tab(swiper)切换
<- wxml -> <view class="youhui"> <view ' bindtap='toggle'> 未使用 </view ...
- 微信小程序如何动态增删class类名
简述 由于微信小程序开发不同于以往的普通web开发, 因此无法通过js获取wxml文件的dom结构, 因此从js上直接添加一个类名应该不可能了. 可是我们可以通过微信小程序数据绑定以及view标签的& ...
- python 字符串的方法
capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 center(width) 将字符串居中,并使用空格填充至长度 width 的新字符串 c ...
- httpClient解决post请求重定向的问题
import com.dadi.saas.util.HTTPUtils; import org.apache.commons.httpclient.Header; import org.apache. ...
- emqtt 试用(七)追踪
追踪 EMQ 消息服务器支持追踪来自某个客户端(Client)的全部报文,或者发布到某个主题(Topic)的全部消息. 追踪客户端(Client): ./bin/emqttd_ctl trace cl ...
- SpringCloud的Bus(一)消息中间件的概念和用途
一.概念与定义 1.Message Broker Message Broker是一种消息验证.消息转换.消息路由的架构模式,用于如: 消息路由到一个或多个目的地 消息转化为其他的表现方式 执行消息的聚 ...