zoukankan      html  css  js  c++  java
  • BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://www.lydsy.com/JudgeOnline/problem.php?id=1607

    Description

      今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏.
        贝茜让N(1≤N≤100000)头奶牛坐成一个圈.除了1号与N号奶牛外,i号奶牛与i-l号和i+l号奶牛相邻.N号奶牛与1号奶牛相邻.农夫约翰用很多纸条装满了一个桶,每一张包含了一个独一无二的1到1,000,000的数字.
        接着每一头奶牛i从柄中取出一张纸条Ai.每头奶牛轮流走上一圈,同时拍打所有编号能整除在纸条上的数字的牛的头,然后做回到原来的位置.牛们希望你帮助他们确定,每一头奶牛需要拍打的牛.

    Input

      第1行包含一个整数N,接下来第2到N+1行每行包含一个整数Ai.

    Output

    第1到N行,每行的输出表示第i头奶牛要拍打的牛数量.

    Sample Input

    5 //有五个数,对于任一个数来说,其它的数有多少个是它的约数
    2
    1
    2
    3
    4

    Sample Output

    2
    0
    2
    1
    3

    HINT

    题意

    题解

    筛法,对于每一个数,我们都筛一遍这个数对哪些数有贡献就好了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <bitset>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 1200051
    #define mod 10007
    #define eps 1e-9
    int Num;
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    int n;
    int H[maxn];
    int H1[maxn];
    int a[maxn];
    int main()
    {
        n=read();
        int M=0;
        int x;
        for(int i=1;i<=n;i++)
            a[i]=read(),M=max(M,a[i]),H[a[i]]++;
        for(int i=1;i<=M;i++)
        {
            if(H[i])
            {
                for(int j=i;j<=M;j+=i)
                    H1[j]+=H[i];
            }
        }
        for(int i=1;i<=n;i++)
            printf("%d
    ",H1[a[i]]-1);
    }
  • 相关阅读:
    【转】禁用chrome firefox 的 WebRTC功能防止真实IP泄漏
    这是我的主场
    【转】反编译获取任何微信小程序源码(完)
    【转】npm 安装express npm ERR! code UNABLE_TO_VERIFY_LEAF_SIGNATURE
    查询最新的邮编地区
    【转】汇编语言入门教程
    Microsoft Windows远程桌面协议中间人攻击漏洞(CVE-2005-1794)漏洞解决方案(Windows server2003)
    IIS隐藏版本号教程(Windows Server 2003)
    Windows Server 2003添加防火墙策略教程
    Tomcat禁用SSLv3和RC4算法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4771116.html
Copyright © 2011-2022 走看看