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);
        }
    }
    

      

  • 相关阅读:
    MFC CDialog/CDialogEx DoModal ALT
    yum和apt-get用法及区别
    ubuntu 12.04 source.list 源更新
    elasticsearch 优化
    TRIE树
    数据统计经验浅谈
    机器学习
    python 读取libsvm文件
    spark 参数调优
    python中的一些函数
  • 原文地址:https://www.cnblogs.com/SfailSth/p/6435403.html
Copyright © 2011-2022 走看看