bitset 巧妙用法 hdu5972

題目鏈接

bitset用法整理

#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<stdlib.h>
#include<time.h>
#include <iomanip>
#include <bitset>
#define lowbit(x) (x&(-x))
#define inf  0x7fffffff
#define linf 0x7fffffffffffffff
#define mem(x,y) memset(x,y,sizeof(x))
#define fup(i,x,y) for(int i=(x);i<=(y);i++)
#define fdn(i,x,y) for(int i=(x);i>=(y);i--)
#define sp(x) setprecision(x)
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define sc(n) scanf("%s",n)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pff(x) printf("%lf\n",x)
#define N 5000005
#define M 150005
#define pi acos(-1)
//cout.setf(ios::fixed);

//freopen("out.txt","w",stdout);
using namespace std;
typedef long long ll;
typedef double db;
bitset<1005> b[12],ans;
char c[N];
int main()
{
    int n;
    sd(n);
    fup(i,0,n-1)
    {
        int k;
        sd(k);
        fup(j,0,k-1)
        {
            int x;
            sd(x);
            b[x].set(i);
        }
    }
    sc(c);
    int len=strlen(c);
    fup(i,0,len-1)
    {
        ans<<=1;
        ans.set(0);
        ans&=b[c[i]-'0'];
    //    cout<<b[c[i]-'0']<<endl;
        if(ans[n-1]==1)
        {
            char cc=c[i+1];
            c[i+1]='\0';
            puts(c+i-n+1);
            c[i+1]=cc;
        }
    }
    return 0;
}
/*
5
2 5 4 3 1
*/

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章