zoukankan      html  css  js  c++  java
  • dtoj3317. 人类基因(human)

    题目描述

    上了大学之后,小W和小Z一起报了一门三宝课,在实践课上遇到了一些问题。

    一条染色体上有nn对基因,每种基因都可以用一个数ai来表示,作为标号。

    现在,在其中一条染色单体上某基因发生了突变。

    此时染色体上有n−1对相同的基因和一对不同的基因。

    他们通过某种方法获得了这条染色体上的全部基因。

    现在他们想知道发生突变的基因的标号是什么。

    输入

    第一行一个数n

    第二行2×n个数表示。

    输出

    两个数,代表发生突变的基因的标号。

    样例输入

    5 
    1 2 3 4 7 8 4 3 2 1

    样例输出

    7 8

    提示

    对于30%的数据:1≤n≤100,1≤ai≤2×1051≤n≤100,1≤ai≤2×105 ;

    对于60%60%的数据:1≤n≤5×105,1≤ai≤2×1051≤n≤5×105,1≤ai≤2×105; 

    对于100%100%的数据:1≤n≤5×105,1≤ai≤2×1091≤n≤5×105,1≤ai≤2×109; 

    来源


    挺有意思的题

    按照套路,我们把每一个数异或起来

    这样只能得到a^b

    那么考虑对于每一位,

    把该位为1的数异或起来

    若a^b某位为1

    #include<cstdio>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int n,t,s[33],xo,a,b;
    int main()
    {
        cin>>n;
        for(int i=1;i<=n+n;i++){
            scanf("%d",&t);
            xo^=t;
            for(int i=0;i<33;i++)if((t&(1<<i))>0){
                s[i]^=t;
            }
            
        }
        for(int i=0;i<33;i++)if(xo&(1<<i)){
            a=s[i];break;
        }
        b=xo^a;
        if(a>b)swap(a,b);
        printf("%d %d
    ",a,b);
        return 0;
    }
    View Code

    那么这一位的答案就是a或b

  • 相关阅读:
    php_l3arning_notes_3
    php_l3arning_notes_2
    php_l3arning_notes_1
    从 HTTP 到 HTTPS 再到 HSTS
    WSGI&ASGI
    WSGI 介绍
    什么是multipart/form-data请求
    SSH 端口转发
    Redis与RabbitMQ作为消息队列的比较
    数据库索引,到底是什么做的?
  • 原文地址:https://www.cnblogs.com/liankewei/p/12369035.html
Copyright © 2011-2022 走看看