2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M题

来源:互联网 发布:多益网络 传送门骑士 编辑:程序博客网 时间:2024/06/11 14:11

解题思路:由于n很小我们很容易就想到用二进制解决这个问题,那么就是将每个集合变成一个数,然后用&判断就行了


代码:

#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int mx = 2e2+10;int n;double a;int cnt[mx];int main(){    scanf("%d%lf",&n,&a);    int x,y = 0,top = 0;    while(~scanf("%d",&x)){        char c = getchar();        x--;        y += (1<<x);        while(c!='\n'){            scanf("%d",&x);            x--;            c = getchar();            y += (1<<x);        }        cnt[top++] = y;        y = 0;    }    int sum = (1<<n);    a = a*top;    int ans = 0;    for(int i=1;i<sum;i++){        int to = 0,po,size = 0;        for(int j=0;j<top;j++){        if((i&cnt[j])==i) size++;        }        if(size>=a) ans++;    }    printf("%d\n",ans);    return 0;}


阅读全文
0 0
原创粉丝点击