zoukankan      html  css  js  c++  java
  • upc组队赛16 Winner Winner【位运算】

    Winner Winner

    题目链接

    题目描述

    The FZU Code Carnival is a programming competetion hosted by the ACM-ICPC Training Center of Fuzhou University. The activity mainly includes the programming contest like ACM-ICPC and strive to provide participants with interesting code challenges in the future.
    Before the competition begins, YellowStar wants to know which teams are likely to be winners. YellowStar counted the skills of each team, including data structure, dynamic programming, graph theory, etc. In order to simplify the forecasting model, YellowStar only lists M skills and the skills mastered by each team are represented by a 01 sequence of length M. 1 means that the team has mastered this skill, and 0 does not.
    If a team is weaker than other teams, this team cannot be a winner. Otherwise, YellowStar thinks the team may win. Team A(a1, a2, ..., aM ) is weaker than team B(b1, b2, ..., bM ) if ∀i ∈ [1, M], ai ≤ bi and ∃i ∈ [1, M], ai < bi.
    Since YellowStar is busy preparing for the FZU Code Carnival recently, he dosen’t have time to forecast which team will be the winner in the N teams. So he asks you to write a program to calculate the number of teams that might be winners.

    输入

    Input is given from Standard Input in the following format:

    输出

    Print one integer denotes the number of X.

    样例输入

    3 3
    2 5 6
    

    样例输出

    2
    

    题意

    给出n个数,将其转化为m位二进制数。
    如果存在其他数跟当前数 1所在位置相同并且1的数量更多,那么当前数就会被舍弃。问最后能保留几个数
    例如样例 2 = 010 , 5 = 101 , 6 = 110
    那么就认为2会因为6被舍弃 ,但5和6却无法比较所以都留下来,输出为2

    题解

    通过位运算 从大到小遍历(因为最大的一定会留下来),把有比当前值对应二进制各个位置小的(即0)值打上记号(改为-1),当遍历到被标记的数时跳过。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i,a,n) for(int i=a;i<n;i++)
    #define scac(x) scanf("%c",&x)
    #define sca(x) scanf("%d",&x)
    #define sca2(x,y) scanf("%d%d",&x,&y)
    #define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define scl(x) scanf("%lld",&x)
    #define scl2(x,y) scanf("%lld%lld",&x,&y)
    #define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
    #define pri(x) printf("%d
    ",x)
    #define pri2(x,y) printf("%d %d
    ",x,y)
    #define pri3(x,y,z) printf("%d %d %d
    ",x,y,z)
    #define prl(x) printf("%lld
    ",x)
    #define prl2(x,y) printf("%lld %lld
    ",x,y)
    #define prl3(x,y,z) printf("%lld %lld %lld
    ",x,y,z)
    #define mst(x,y) memset(x,y,sizeof(x))
    #define ll long long
    #define LL long long
    #define pb push_back
    #define mp make_pair
    #define P pair<double,double>
    #define PLL pair<ll,ll>
    #define PI acos(1.0)
    #define eps 1e-6
    #define inf 1e17
    #define mod 1e9+7
    #define INF 0x3f3f3f3f
    #define N 1005
    int a[1<<20];
    int n,m,x;
    int main()
    {
        sca2(n,m);
        int mx = -1;
        rep(i,0,n)
        {
         sca(x);
         a[x]++;
         mx = max(x,mx);
        }
        int ans = 0;
        for(int i = mx;i>=0;i--)
        {
            if(a[i])
            {
                if(a[i]>0) ans+=a[i];
                for(int j=m-1;j>=0;j--)
                {
                    if(i&(1<<j))
                        a[i^(1<<j)] = -1; //标记第j位取反的数
                }
            }
        }
        pri(ans);
        return 0;
    }
    
  • 相关阅读:
    Hadoop面试题总结(三)——MapReduce
    Hadoop面试题总结(二)——HDFS
    Hadoop面试题(一)
    html table有跨行跨列时,设置td宽度失效
    ubuntu14.04 安装五笔输入法(fcitx)
    NetCore生产环境禁用Swagger教程
    使用Jenkins与Docker持续集成与发布NetCore项目(实操篇)
    解决 Docker Unable to load the service index for source https://api.nuget.org/v3/index.json 问题
    .net webapi 接收图片保存到服务器,并居中剪裁压缩图片
    .net webapi 接收 xml 格式数据的三种情况
  • 原文地址:https://www.cnblogs.com/llke/p/10815210.html
Copyright © 2011-2022 走看看