zoukankan      html  css  js  c++  java
  • HDU 5833 Zhu and 772002 ——线性基

    【题目分析】

        这题貌似在UVA上做过,高精度高斯消元。

        练习赛T2,然后突然脑洞出来一个用Bitset的方法。

        发现代码只需要30多行就A掉了

        Bitset大法好

    【代码】

    #include <cstdio>
    #include <bitset>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define F(i,j,k) for (int i=j;i<=k;++i)
    #define D(i,j,k) for (int i=j;i>=k;--i)
    #define ll long long
    #define maxn 2005
    const int md=1000000007;
    int pr[maxn],ispr[maxn],top=0;
    bitset <505> lb[505],now;
    int main()
    {
        F(i,2,maxn-1)
        {
            if (!ispr[i]) pr[++top]=i;
            for (int j=1;j<=top&&pr[j]*i<maxn;++j)
            {
                if (i%pr[j]==0) {ispr[i*pr[j]]=1; break;}
                ispr[i*pr[j]]=1;
            }
        }
        int t,n,cnt;ll x;
        scanf("%d",&t);
        int kas=0;
        while (t--)
        {
            printf("Case #%d:
    ",++kas);
            cnt=0;
            F(i,0,504) lb[i].reset();
            scanf("%d",&n);
            F(i,1,n)
            {
                scanf("%lld",&x);
                now.reset();
                F(i,1,top)
                {
                    int flag=0;
                    while (x%pr[i]==0) x/=pr[i],flag^=1;
                    now[i]=flag;
                }
                int tag=1;
                D(j,500,1)
                    if (now[j])
                    {
                        if (lb[j].count()==0) {lb[j]=now;tag=0;break;}
                        else now^=lb[j];
                    }
                cnt+=tag;
            }
            ll ans=1;
            while (cnt)
            {
                ans<<=1;
                ans%=md;
                cnt--;
            }
            printf("%lld
    ",(ans-1+md)%md);
        }
    }
    

      

  • 相关阅读:
    P4014 分配问题 网络流
    P4015 运输问题 网络流问题
    P4013 数字梯形问题 网络流
    网络流 P2770 航空路线问题
    网络流之最小费用最大流 P1251 餐巾计划问题
    二分图定理
    数论 C
    网络流 E
    网络流 之 P2766 最长不下降子序列问题
    scp使用
  • 原文地址:https://www.cnblogs.com/SfailSth/p/6435403.html
Copyright © 2011-2022 走看看