2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)

D.Distinctive Character

看到样例,第一个反应贪心。先写了个按这一位1和0的数目多少,确定0还是1的东西。感觉不够真,又写了个尽量加到相似的比较小的串上的贪心。在和前边的那个组合一下,换了换顺序。。。好吧就过了13组样例。。。正解如下:考虑如何求出,所有2^k个状态与这n个串的最大相似度。起初的n个串的答案显然为k,那改变一个位置,相似度就改变为k-1,对于一个状态,越早算出来的相似度,越大,那么就可以直接bfs求出所有状态的最大相似度了。答案就是取最小值的状态。

#include <bits/stdc++.h>
#define mem(W) memset(W,0,sizeof(W))
using namespace std;
int n, k, a[1<<23], b[1<<23];
char s[25];
int q[1<<23],l=0,r=0;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<(1<<k);++i)b[i]=-1;
    for(int i=1;i<=n;++i) {
        scanf(" %s",s);
        for(int j=0;j<k;++j) a[i]=a[i]*2+(s[j]-‘0‘);
        q[r]=a[i];++r;
        b[a[i]]=k;
    }
    while(l<r){
        int S=q[l]; ++l;
        for(int i=0;i<k;++i){
            if(b[S^(1<<i)]==-1){
                b[S^(1<<i)]=b[S]-1;
                q[r]=S^(1<<i); ++r;
            }
        }
    }
    int MN=10000,ans=0;
    for(int i=0;i<(1<<k);++i){
        if(MN>b[i]){
            MN=b[i];
            ans=i;
        }
    }
    for(int i=k-1;i>=0;--i)printf("%d",!!(ans&(1<<i)));puts("");
}

  

原文地址:https://www.cnblogs.com/RRRR-wys/p/9086143.html

时间: 2024-11-09 14:04:46

2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)的相关文章

(寒假GYM开黑)2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

layout: post title: 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces 传送门 付队! B.Baby Bites (签到模拟) 按照题意模拟就行了 int a[maxn]; string s; int main() { std::ios::syn

Gym .101933 Nordic Collegiate Programming Contest (NCPC 2018) (寒假gym自训第四场)

(本套题算是比较温和吧,就是罚时有点高. B .Baby Bites 题意:给出一个婴儿给出的数组,有一些数字听不清楚,让你还原,问它是否是一个从1开始的一次增加的数组. 思路:从左往右依次固定,看是否有矛盾即可. #include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(int i=a;i<=b;i++) #define rep2(i,a,b) for(int i=a;i>=b;i--) using n

Nordic Collegiate Programming Contest 2015? B. Bell Ringing

Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells that have 6 different pitches. We assign the number 1 to the bell highest in pitch, 2 to the second highest, and so on. When the 6 bells are rung in

(寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces 传送门 付队! 许老师! B.Buildings (polya定理) 题意 B:给你m面墙,每面墙是n*n的格子,你有c种颜色,问你有多少种涂色方案.用po

【离散化树状数组】Nordic Collegiate Programming Contest G.Galactic Collegiate Programming Contest

1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int n,m; 5 const int maxn=1e5+3; 6 struct node 7 { 8 int team; 9 int num; 10 int time; 11 int id; 12 }a[maxn]; 13 int ans[maxn]; 14 int b[maxn]; 15 int c[maxn]; 16 int s[maxn

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018 Problem A. Can Shahhoud Solve it? Problem B. Defeat the Monsters Problem C. UCL Game Night Problem

ACM International Collegiate Programming Contest, JUST Collegiate Programming Contest (2018)

ACM International Collegiate Programming Contest, JUST Collegiate Programming Contest (2018) B. New Assignment 有n个人(1?≤?n?≤?104),有男有女,每个人都有一个id,现在这n个人分成学习互助小组,有三种组队模式,一个男人一组,一个女人一组,一男一女一组,如果要一男一女一组,那么这两人id的gcd要>1.保证任意三个人的gcd=1.求小组的组数最少是多少? 看起来是一个很裸的二

2018 German Collegiate Programming Contest (GCPC 18)

2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib> #include <iomanip> #include <bit

2018 ACM-ICPC, Syrian Collegiate Programming Contest

2018 ACM-ICPC, Syrian Collegiate Programming Contest A Hello SCPC 2018! 水题 B Binary Hamming 水题 C Portals 思路:并查集维护连通性 代码: //#pragma GCC optimize(3) //#pragma comment(linker, "/STACK:102400000,102400000") //c++ // #pragma GCC diagnostic error &quo