hdu 1669 Jamie's Contact Groups

2023-05-16

Jamie's Contact Groups

Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 225    Accepted Submission(s): 63


Problem Description
Jamie is a very popular girl and has quite a lot of friends, so she always keeps a very long contact list in her cell phone. The contact list has become so long that it often takes a long time for her to browse through the whole list to find a friend's number. As Jamie's best friend and a programming genius, you suggest that she group the contact list and minimize the size of the largest group, so that it will be easier for her to search for a friend's number among the groups. Jamie takes your advice and gives you her entire contact list containing her friends' names, the number of groups she wishes to have and what groups every friend could belong to. Your task is to write a program that takes the list and organizes it into groups such that each friend appears in only one of those groups and the size of the largest group is minimized.
 
 
Input
There will be at most 20 test cases. Ease case starts with a line containing two integers N and M. where N is the length of the contact list and M is the number of groups. N lines then follow. Each line contains a friend's name and the groups the friend could belong to. You can assume N is no more than 1000 and M is no more than 500. The names will contain alphabet letters only and will be no longer than 15 characters. No two friends have the same name. The group label is an integer between 0 and M - 1. After the last test case, there is a single line `0 0' that terminates the input.
 
 
Output
For each test case, output a line containing a single integer, the size of the largest contact group.
 
 
Sample Input
3 2
John 0 1
Rose 1
Mary 1
5 4
ACM 1 2 3
ICPC 0 1
Asian 0 2 3
Regional 1 2
ShangHai 0 2 0 0
 
 
Sample Output
2 2
 
 
Source
2004 Asia Regional Shanghai
 
 
Recommend
xhd
题目很容易明白,我这里就不赘述了。区赛了还是刷图论,希望真心能给力点吧。这个题目的想法就是二分+二分图的多重匹配。下面我把自己的渣代码弄上来:
View Code

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>

using namespace std;

const int maxn=1010;
const int maxm=510;

int bmap[maxn][maxm],cy[maxm][maxn],bmask[maxm],vcy[maxm],n,m,limit;
char s[2000];

bool findpath(int u)
{
    for(int i=0;i<m;i++)
    {
        if(bmap[u][i]&&!bmask[i])
        {
            bmask[i]=1;
            if(vcy[i]<limit)
            {
                cy[i][vcy[i]++]=u;
                return true;
            }
            for(int j=0;j<vcy[i];j++)
            {
                if(findpath(cy[i][j]))
                {
                    cy[i][j]=u;
                    return true;
                }
            }
        }
    }
    return false;
}

bool mulmatch()
{
    memset(vcy,0,(m+5)*sizeof(int));
    for(int i=0;i<n;i++)
    {
        memset(bmask,0,sizeof(bmask));
        if(!findpath(i)) return false;
    }
    return true;
}

int main()
{
    while(scanf("%d %d",&n,&m),n+m)
    {
        getchar();
        memset(bmap,0,sizeof(bmap));
        memset(cy,0,sizeof(cy));
        memset(s,0,sizeof(s));
        for(int i=0;i<n;i++)
        {
            gets(s);
            int len=strlen(s);
            int ret=0;
            int t;
            for(t=0;t<len;t++)
            {
                if((s[t]>='a'&&s[t]<='z')||(s[t]>='A'&&s[t]<='Z')) continue;
                else break;
            }
            t++;
            for(;t<len;t++)
            {
                if(s[t]>='0'&&s[t]<='9')
                {
                    ret=ret*10+s[t]-'0';
                    if(t+1==len)
                        bmap[i][ret]=1;
                }
                else if(s[t]==' ')
                {
                    bmap[i][ret]=1;
                    ret=0;
                }
            }
            memset(s,0,sizeof(s));
        }
        int l=1,r=n+1,ans=0;
        while(l<r)
        {
            limit=(l+r)>>1;
            if(mulmatch())
                ans=limit,r=limit;
            else l=limit+1;
        }
        printf("%d\n",ans);
    }
    return 0;
}  

明天晚上就要出发了。听人说是传说中的死亡赛区,所以心态也很好,基本上是去玩的,因为深知自己水平。谢谢!欢迎转载,提问,留言。

转载于:https://www.cnblogs.com/RainingDays/archive/2012/10/11/2719320.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

hdu 1669 Jamie's Contact Groups 的相关文章

  • HDU 2246 考研路茫茫——考试大纲

    HDU 2246 考研路茫茫 考试大纲 聽說這題要打表999 43 就傻傻的從0 N一個個地貼在代碼上了 打了幾個文件 xff0c 一同學就說我錯了 xff0c 杯具 因為提交上去的代碼長度不能超64K 白打了 xff0c 不過提示我測試數
  • HDU 1275

    两车追及或相遇问题 Time Limit 2000 1000 MS Java Others Memory Limit 65536 32768 K Java Others Total Submission s 598 Accepted Sub
  • [HDU 6330]2019 HDU多校test5 permutation 2

    permutation 2 题目链接 Problem Description You are given three positive integers N x y Please calculate how many permutation
  • HDU 3700 Cat

    Cat Time Limit 2000 1000 MS Java Others Memory Limit 32768 32768 K Java Others Total Submission s 451 Accepted Submissio
  • hdu 1358 Period KMP

    题目大意 xff1a 对于一个字符串 xff0c 找由循环字符串组成的位置 xff0c 并输出最多循环了几次 xff0c 比如两个样例 xff0c 第一个是 aaa xff0c 所以在第二个位置由子串a循环两次得到 xff0c 第三个位置由
  • HDU 1085

    题意 xff1a 有1 2 5三数 xff0c 你赋予他们各自的数量 xff0c 求他们所不能组成的最小数 分析 xff1a 首先想到暴力 xff0c 两层循环 暴力超时 xff0c 再寻他法 O n 2 include 34 cstdio
  • hdu 1669 Jamie's Contact Groups

    Jamie 39 s Contact Groups Time Limit 15000 7000 MS Java Others Memory Limit 65535 65535 K Java Others Total Submission s
  • Pytorch RuntimeERROR: Given groups=1 weights of size [256,64,1,1] expected input[1,16,256,256] to

    错误 Pytorch RuntimeERROR span class token punctuation span Given groups span class token operator 61 span span class toke
  • HDU 1085 Holding Bin-Laden Captive!(母函数)

    HDU 1085 Holding Bin Laden Captive xff08 母函数 xff09 题目地址 题意 xff1a 给你cnt1个一元硬币 xff0c cnt2个两元硬币 xff0c cnt3个五元硬币 xff0c 问不能凑出
  • HDOJ/HDU 1085 母函数 Holding Bin-Laden Captive!

    Holding Bin Laden Captive Time Limit 2000 1000 MS Java Others Memory Limit 65536 32768 K Java Others Total Submission s
  • the selected library block “Contact_forces_lib/3D/sphere to plane force“ no longer exists

    问题 在matlab的simulink里面进行simscape仿真的时候 xff0c 由于添加了接触力 xff0c 因此实现装了 Simscape Multibody Contact Forces Library 这个库 xff0c 装完之
  • 错误:Failed to contact master

    在ros运行时 xff0c 可能出现一下错误 xff1a ERROR registerPublisher Failed to contact master at localhost 11311 Retrying 原因很简单 xff0c 忘记
  • [JAVA][2013蓝桥杯预赛 JAVA本科B组][世纪末的星期]

    标题 世纪末的星期 曾有邪教称1999年12月31日是世界末日 当然该谣言已经不攻自破 还有人称今后的某个世纪末的12月31日 如果是星期一则会 有趣的是 任何一个世纪末的年份的12月31日都不可能是星期一 于是 谣言制造商 又修改为星期日
  • hdu1799(用递推公式求组合的个数)

    题目意思 我们知道 在编程中 我们时常需要考虑到时间复杂度 特别是对于循环的部分 例如 如果代码中出现 for i 1 i lt n i OP 那么做了n次OP运算 如果代码中出现 fori 1 i lt n i for j i 1 j l
  • hdu 6127 Hard challenge

    Problem acm hdu edu cn showproblem php pid 6127 Meaning 平面上有 n 个不重合的点 任意三点不共线 任意两点所在直线不经原点 每个点有个 value 任意两个点连出的线段的 value
  • hdu 1024 Max Sum Plus Plus

    Problem acm hdu edu cn showproblem php pid 1024 题意 给一个长为 n 的序列 有从中挑 m 个相互不重合的子序列求总和 让总和最大 分析 没能看懂百度的前几份题解 好像都跟 kuangbin
  • hdu 4405 Aeroplane chess

    Problem acm hdu edu cn showproblem php pid 4405 vjudge net contest 151678 problem R Reference bbs csdn net topics 380193
  • hdu 1069 Monkey and Banana

    Problem acm hdu edu cn showproblem php pid 1069 Reference www cnblogs com kuangbin archive 2011 08 04 2127291 html 题意 给
  • hdu 5792 World is Exploding 2016 Multi-University 5

    Problem acm hdu edu cn showproblem php pid 5792 题意 给一个序列 V 问有多少个由下标组成的四元组 a b c d 满足 a b c d a lt b c lt d Va lt Vb Vc g
  • hdu 2043 密码

    密码 Time Limit 2000 1000 MS Java Others Memory Limit 65536 32768 K Java Others Total Submission s 22640 Accepted Submissi

随机推荐

  • 用英语用计算机造句,英语造句用It’s adj (for sb) to do sth 造句10个

    来源 xff1a 学生作业帮 编辑 xff1a 作业帮 分类 xff1a 英语作业 时间 xff1a 2021 06 27 06 48 36 英语造句 用It s adj for sb to do sth 造句10个 希望以下诸多句子中 有
  • 【GTA5线上CyberBox小助手】 - 完全免费

    重要声明 CyberBox完全免费 xff0c 请勿转发盈利 xff0c 请勿上当受骗 简单描述 任务设置 外置辅助 刷钱刷级 xff0c 安全稳定 xff0c 完全免费 xff0c 打开即用 CyberBox的设计初衷是为了方便玩家过任务
  • 服务器c盘显示0字节可用,c盘0字节可用怎么解决 c盘0字节可用处理方法

    1 用户不需要的文件被删除后不会直接从磁盘上清除 xff0c 实际上是放到了回收站中 xff0c 回收站使用的就是系统C盘上的容量 xff0c 如果回收站里有很多大文件就会导致C盘容量被占用 xff0c 清空回收站会腾出C盘容量 2 用户在
  • 服务器维护经验分享,医院IT运维经验分享.pdf

    智慧医院之 IT运维管理经验分享 汇报人 xff1a 周月香 长沙市第一医院 信息科 PART01 医院信息化建设现状 目录 PART02 医院信息化运营管理 CO N TEN T PART03 信息工单及项目管理 医院概况 我院建于192
  • ajax表单图片,js中使用ajax上传一个带有图片的表单数据

    function save var formData 61 new FormData if 39 file 39 0 files length gt 0 formData append 39 pic 39 39 file 39 0 file
  • 服务器对操作系统有什么要求,服务器对操作系统有什么要求

    服务器对操作系统有什么要求 内容精选 换一换 查看用户的镜像类型 xff0c 如果是公共镜像则排除私有镜像的源镜像问题 镜像类型单击 申请服务器 xff0c 查看能否创建出此镜像的弹性云服务器 xff0c 申请完成后未出现此镜像对应的弹性云
  • 解决 martian source

    解决 martian source 第一步 xff1a etc sysctl conf 最后面添加 xff1a net ipv4 conf default log martians 61 0 net ipv4 conf all log ma
  • 如何划分地址段?

    今天一位网友问我该如何划分地址段以便进行网络流量限制 下面我就这个方法简单的说一说希望有所帮助 我们该如何划分地址段呢 xff1f ip地址段常用的有三类 xff1a xff21 类的默认子网掩码 255 0 0 0 xff0c 一个子网最
  • ONOS预热篇之ONOS简介

    为什么80 的码农都做不了架构师 xff1f gt gt gt ONOS问世后引起广泛关注 xff0c 关于 ONOS 与 ODL 的纷争不绝于耳 xff0c 最近小编拜读了一下 ONOS 白皮书 xff0c 并做了一点粗浅总结 xff0c
  • warning LNK4099: PDB 'vc100.pdb' was not found... 解决方案

    使用VS2010在编译得代码工程的时候 xff0c 原本在debug下是没有问题 xff0c 但是在release下编译始终会报 xff1a warning LNK4099 PDB 39 vc100 pdb 39 was not found
  • win7无法识别U盘,驱动信息:该设备的驱动程序未被安装。 (代码 28)

    台式机的win7 64位系统可以识别u盘 xff0c 但笔记本的win7 64位却识别不了 xff0c 说明U盘是可以用的 查看笔记本的设备管理器 xff0c 发现驱动安装失败 xff0c 提示信息为 该设备的驱动程序未被安装 代码 28
  • 微信小程序——navigator无法跳转

    今天在做小程序的时候 xff0c 发现用navigator无法进行跳转 url 路径也是对的 后面发现是因为我需要跳转的页面定义在了tabBar里面的 如下图 xff1a 如果需要跳转到tabBar里面定义的这些页面 xff0c 需要用到w
  • java中调用父类方法之super关键字的疑惑?

    在java中有super和this这2个关键字 xff0c 我有时候对super有一些疑惑 xff0c 我甚至认为我对super和this这2个关键字还没理解 xff01 大家请看下面的代码 xff0c 帮我解惑一些呗 xff01 谢谢 p
  • Docker修改daemon.json后无法启动的问题

    本文的运行环境为Centos 7 3 xff0c Docker与Kubernetes的安装方式见kubeadm安装kubernetes V1 11 1 集群 最近在整理Docker和Kubernetes中的日志与相关配置 xff0c 在尝试
  • android点击全屏预览照片第三方库使用

    android点击全屏预览照片第三方库使用 imgepreviewlibrary 移动端我们经常会遇到放大预览照片 xff0c 如果是一张照片 xff0c 那就全屏展示图片就好了 xff0c 但是如果是一个列表 xff0c 滑动查看 xff
  • R语言绘图-legend()添加图例

    legend x y 61 NULL legend fill 61 NULL col 61 par 34 col 34 border 61 34 black 34 lty lwd pch angle 61 45 density 61 NUL
  • MySQL数据库 资源

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 面试题 xff1a Linux运维必会的MySQL企业面试题大全 推荐 xff1a http blog 51cto com xiaogongju 2068526 mysql
  • LM358 电路 10倍放大

    如何用LM358将0 3V电压放大10倍 放大倍数 61 1 43 R2 R1 xff0c 放大10倍 xff0c 选择R1 61 2K xff0c R2 61 18K 转载于 https blog 51cto com 990487026
  • Java自定义异常处理——最佳实践[译]

    我们几乎已经在我们的每个行业标准应用的代码中处理java自定义异常了 常见的手段是创建一个语义性的继承基础exception类的自定义异常类 1 Java自定义异常处理 新的方法 1 1 传统异常处理 我们的新方法使用静态内部类来处理每个新
  • hdu 1669 Jamie's Contact Groups

    Jamie 39 s Contact Groups Time Limit 15000 7000 MS Java Others Memory Limit 65535 65535 K Java Others Total Submission s