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 ...
随机推荐
- oc中protocol、category和继承的区别
OC中protocol.category和继承的区别以前还是有点迷糊,面试的时候说的有点混乱,现在结合一些资料总结一下. 利用继承,多态是一个很好的保持"对扩展开放.对更改封闭"( ...
- 去掉xcode编译warning:ld: warning: directory not found for option '-L
选择工程, 编译的 (targets) 选择 Build Settings 菜单 查找 Library Search Paths 和 Framework Search Paths, 删掉编译报warn ...
- IDEA之Jrebel插件激活
问题: 码农日常中,热部署是必不可少的,而jrebel插件很好的实现热部署功能. IDEA下载jrebel插件,可以免费试用15天,但之后就无法使用.因为Jrebel是收费的. 解决方法: 楼主也是百 ...
- EasyUI内容页Tabs。
html: <div data-options="region:'center'"> <div id="tabs" class="e ...
- 算法题丨Two Sum
描述 Given an array of integers, return indices of the two numbers such that they add up to a specific ...
- python 判断变量是否是 None 的三种写法
代码中经常会有变量是否为None的判断,有三种主要的写法:第一种是`if x is None`:第二种是 `if not x:`:第三种是`if not x is None`(这句这样理解更清晰`if ...
- python subprocess模块使用总结
一.subprocess以及常用的封装函数运行python的时候,我们都是在创建并运行一个进程.像Linux进程那样,一个进程可以fork一个子进程,并让这个子进程exec另外一个程序.在Python ...
- Spring Security 入门(1-3-5)Spring Security - remember me!
Remember-Me 功能 概述 Remember-Me 是指网站能够在 Session 之间记住登录用户的身份,具体来说就是我成功认证一次之后在一定的时间内我可以不用再输入用户名和密码进行登录了, ...
- Spring Security 入门(1-3-3)Spring Security - logout 退出登录
要实现退出登录的功能我们需要在 http 元素下定义 logout 元素,这样 Spring Security 将自动为我们添加用于处理退出登录的过滤器 LogoutFilter 到 FilterCh ...
- tk mybatis通用mapper,复杂and or条件查询
需求:where查询,需要支持(a or b or c) and d 也就是a.b.c三个条件是或的关系,然后再与d相与. 尝试后,可以通过以下方式处理: 方式1:Weekend语法 Weekend& ...