hihocoder 1513 小Hi的烦恼——bitset

题目:http://hihocoder.com/problemset/problem/1513

自带的题解写得很好……

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
int rdn()
{
  int ret=0;bool fx=1;char ch=getchar();
  while(ch>'9'||ch<'0'){if(ch=='-')fx=0;ch=getchar();}
  while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();
  return fx?ret:-ret;
}
const int N=3e4+5;
int n,rk[5][N],dy[5][N];
bitset<N> b[2][N];
int main()
{
  n=rdn();
  for(int i=1,d;i<=n;i++)
    for(int j=0;j<5;j++)
      {
    d=rdn();
    rk[j][i]=d; dy[j][d]=i;
      }
  for(int i=1;i<=n;i++)b[0][i].set();
  int u=1,v=0;
  for(int j=0;j<5;j++,swap(u,v))
    {
      int lst=dy[j][1];
      for(int i=2;i<=n;i++)
    {
      int cr=dy[j][i];
      b[u][cr]=b[u][lst];
      b[u][cr][lst]=1;
      lst=cr;
    }
      for(int i=1;i<=n;i++)
    b[u][i]&=b[v][i], b[v][i].reset();
    }
  for(int i=1;i<=n;i++)printf("%d\n",b[v][i].count());
  return 0;
}

 

转载于:https://www.cnblogs.com/Narh/p/10386184.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值