HOJ 13813 Blood groups

Blood groups
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:131072KB
Total submit users: 2, Accepted users: 2
Problem 13813 : No special judgement
Problem description
There are four possible blood groups for humans: AB, A, B and O, meaning that the red blood cells have antigens of types, respectively, A and B, only A, only B, and no antigen at all. Our blood group is determined by two alleles in our DNA. Each allele is of type either A, B or O. The following table lists the possible allele combinations someone may have for each blood group:


We inherit exactly one allele from each of our two parents. So, given the blood groups of the two parents, we can say for sure if some blood group is possible, or not, in their offspring. For example, if the blood groups of the two parents are AB and B, then the possible allele combinations for them are, respectively, {AB} and {OB,BB}. Since the order of the alleles does not matter, the possible allele combinations for the offspring are {OA,AB,OB,BB}. That means the blood groups AB, A and B are possible in their offspring, but the blood group O is not. Very nice indeed! But what if life on Earth had evolved so that a person had three parents, three alleles, and three different antigen types? The allele combinations would look like this: 

If the blood groups of the three parents are A, BC and O, then all blood groups are possible in their offspring, except groups BC and ABC.
The universe is vast! There may be, out there in space, some form of life whose individuals have N parents, N alleles, and N different antigen types. Given the blood groups for the N parents, and a list of Q blood groups to test, your program has to determine which ones are possible, and which ones are not, in the offspring of the given parents.

Input
The first line contains two integers N and Q, representing respectively the number of parents (and alleles, and antigen types) and the number of queries (1 ≤ N ≤ 100 and 1 ≤ Q ≤ 40). Each of the next N lines describes the blood group of a parent. After that, each of the next Q lines describes a blood group to test. Antigen types are identified with distinct integers from 1 to N, not letters. Each line describing a blood group contains an integer B indicating the number of antigen types in the blood group (0 ≤ B ≤ N), followed by B different integers C1,C2,...,CB representing the antigen types present in the blood group (1 ≤ Ci ≤ N for i = 1,2,...,B).

Output
For each of the Q queries, output a line with the uppercase letter "Y" if the corresponding blood group is possible in the offspring of the given parents; otherwise output the uppercase letter "N". Write the results in the same order that the queries appear in the input.

Sample Input
Sample input 1
2 1
2 2 1
1 2
0

Sample input 2
3 4
1 1
2 2 3
0
1 3
3 2 1 3
2 1 2
2 3 2

Sample input 3
4 3
4 2 1 3 4
4 2 1 3 4
1 1
1 2
1 3
2 2 1
0
Sample Output
Sample output 1
N

Sample output 2
Y
N
Y
N

Sample output 3
Y
Y
N

题意:某星球n个父母亲可以携带有某些基因,有显性基因和隐性基因,可以遗传给子女。每个父母亲每个可以遗传给子女一个基因,并且也只能遗传一个基因给子女。题目给出n个父母的基因和q次询问,如果给出的子女的基因是合法的(可以由给出的父母遗传给子女)输出Y,否则输出N。

题解:没想到的匹配,二分图的最大匹配。给出了父母的基因,每个父母可以提供显性和隐性基因,并且基因的长度是n(每个父母当且仅当提供一个)。因此用到二分图的最大匹配,父母的基因构成一个点集,子女的构成一个点集。这样就会考虑子女的需要的基因,需要的基因与父母可以给的基因连边(注意是n个基因),建图。然后进行二分匹配(匈牙利算法)就可以搞定了,如果得到的最大匹配等于n,则是每个子女的基因都被匹配,则输出Y。

详见代码:

#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
using namespace std;
#define ll long long
const int maxn=110;
int n;
int g[maxn][maxn];
int mach[maxn],ch[maxn];
bool dfs(int u)
{
    for(int i=0;i<=n;i++)
        if(!ch[i]&&g[u][i])
        {
            ch[i]=1;
            if(mach[i]==-1||dfs(mach[i]))
            {
                mach[i]=u;
                return true;
            }
        }
    return false;
}
int maxmach()
{
    int ans=0;
    memset(mach,-1,sizeof(mach));
    for(int i=1;i<=n;i++)
    {
        memset(ch,0,sizeof(ch));
        if(dfs(i))
            ans++;
    }
    return ans;
}
int mmp[maxn][maxn];
int  main()
{
    //freopen("C:\\Users\\Administrator\\Desktop\\a.txt","r",stdin);
    //ios::sync_with_stdio(false);
    //freopen("C:\\Users\\Administrator\\Desktop\\b.txt","w",stdout);
    int q;
    while(scanf("%d%d",&n,&q)!=EOF)
    {
        memset(mmp,0,sizeof(mmp));
        for(int i=1;i<=n;i++)
        {
            int t,t1;
            scanf("%d",&t);
            if(t<n) mmp[i][0]=1;
            while(t--)
            {
                scanf("%d",&t1);
                mmp[i][t1]=1;
            }
        }
//        cout<<"mmp"<<endl;
//        for(int i=0;i<=n;i++)
//        {
//            for(int j=0;j<=n;j++)
//            printf("%d ",mmp[i][j]);
//            cout<<endl;
//        }
        int Ans=0;
        for(int j=0;j<q;j++)
        {
            memset(g,0,sizeof g);
            int t,t1;
            scanf("%d",&t);
            if(t==0)
            {
                for(int i=1;i<=n;i++)
                {
                    if(mmp[i][0])
                    {
                        int kk=1;
                        while(kk<=n)
                        {
                            g[i][kk]=1;
                            kk++;
                        }
                    }
                }
            }
            for(int k=1;k<=t;k++)
            {
                scanf("%d",&t1);
                for(int i=1;i<=n;i++)
                {
                    if(mmp[i][t1])
                    {
                        g[i][k]=1;
                        for(int kk=t+1;kk<=n;kk++)
                            g[i][kk]=1;
                    }
                    if(t<n&&mmp[i][0])
                    {
                        for(int kk=t+1;kk<=n;kk++)
                         g[i][kk]=1;
                    }
                }
            }
//            cout<<"j "<<j<<endl;
//            for(int i=0;i<=n;i++)
//            {
//                for(int j=0;j<=n;j++)
//                printf("%d ",g[i][j]);
//                cout<<endl;
//            }
//            for(int i=0;i<=n;i++)
//                printf("vis %d ",vis[i]);
           //cout<<"t  "<<t<<endl;
           int Ans=maxmach();
           //printf("%d\n",Ans);
           if(Ans==n) printf("Y\n");
           else printf("N\n");
        }
    }
    return 0;
}
时间: 2024-10-12 23:37:48

HOJ 13813 Blood groups的相关文章

屏姨讶们是h25vhc4y6ece5

说到这里,玄老的声音中明显多了几分悲怆的味道"他们都是好孩子,尽管他们未能真正毕业,但在学院的名册上,始终有着他们的名字.他们以学院的理想为理想,他们并不是没有毕业的实力,而是为了学院的理想战死了."-----------------------------------------------------------------------------周漪忍不住道:"有什么是学院不能帮你解决的?非要自己一个人去面对?难道你说出来我们会不帮你么?"可是--,聚能魂导炮

僦檬哨招瓤kdqg84x5hodqk1

台上,天煞斗罗黄津绪并没有催促双方进行下一场比赛,因为比赛台在刚才一战中被破坏的实在是太厉害了,马小桃的黑色凤凰火焰足足灼烧了一分多钟才消失.如果不进行修补,已经没法再继续比赛了.此时正由几位实力不俗的土系魂师快速修复着.自从进入史莱克学院之后,他们一直都在紧张的学习和修炼,哪有什么放松的时间.凌落宸的疑问则只是落在霍雨浩一个人身上,"极致之冰?"贝贝心中早有定计,低声道:"第一场我们赢了,我们就已经处于主动之中.我们现在最希望出现的.是第二场他们在冲动之下派出两名魂王,或者

滦谇淋坌招r6un44y803l1xog9y18

求收藏.求推荐票.求会员点击.刺入他额头的青色噬灵刻刀轻微震颤,奇异的是,那破入的创口并没有鲜血流出,反而是那噬灵刻刀竟然缓缓软化,化为青碧色的液体顺着那创口流入霍雨浩头部之中.霍雨浩呵呵一笑,道:"发现就发现呗,王冬,你现在是不是觉得特别虚弱,一点力气都用不出来啊?""战争最后虽然胜利了,但我们唐门暗器的作用也受到了极大的质疑.从那以后,各国开始大幅度削减对我们制作暗器的采购.而我们唐门赚钱虽然不少,但按照第一代门主的意思,大部分收入全都捐赠了出去.用来改善穷苦地区的平民生

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

使用Search查询Office 365 Groups

原文地址 我已经使用新的Office 365 Groups 功能有一段时间了,我想看看我在普通的SharePoint Online site怎么使用它们.我今天的例子里,我创建了两个 public groups 和三个private groups. 我第一个想法是使用Search. 因为我知道,group在后台,是由site collection来存储的.我只是要查找到,它使用的是哪一个WebTemplate .你可以在search中,通过查看一个文档,容易的找到site collection的

poj 2408 Anagram Groups(hash)

题目链接:poj 2408 Anagram Groups 题目大意:给定若干个字符串,将其分组,按照组成元素相同为一组,输出数量最多的前5组,每组按照字典序输出所 有字符串.数量相同的输出字典序较小的一组. 解题思路:将所有的字符串统计字符后hash,排序之后确定每组的个数并且确定一组中字典序最小的字符串.根据个数 以及字符串对组进行排序. #include <cstdio> #include <cstring> #include <vector> #include &

No plugin found for prefix &#39;jetty&#39; in the current project and in the plugin groups

现在Jetty的版本已经到9了,也早已经在Eclipse的门下了.所以有很多groupId,比如:org.eclipse.jetty.org.mortbay.jetty.这些都可以用的哦. 我在使用MyEclipse结合maven操作jetty作为开发的服务器,这开开发比较方便. 当我运行命令: jetty:run 出现: [ERROR] No plugin found for prefix 'jetty' in the current project and in the plugin gro

Codeforces 246E Blood Cousins Return(Dsu On the Tree)

题目链接 Blood Cousins Return 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define rep(i, a, b) for (int i(a); i <= (b); ++i) 6 7 const int N = 200010; 8 9 string s[N]; 10 int ans[N], sz[N], h[N]; 11 bool skip[N]; 12 vector <int> v[N

HOJ 1797 Red and Black

传送门  http://acm.hit.edu.cn/hoj/problem/view?id=1797 总体的思路是遍历可以到达的' . ',将其对应的vis数组化为1,然后统计所有为1的vis项; ①常用的加边法,防止越界 ②初始化,不然两次相同的输入得到的结果会不同,由于是二维数组,能力有限,只好在结尾初始化,为下次输入做准备 ③结束条件,递归函数一定要先写好结束条件,不然会炸 ④上下左右四向移动 ⑤直接递归函数调用自身 1 #include <stdio.h> 2 #include &l