zoukankan      html  css  js  c++  java
  • bzoj1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

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

    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

    INPUT DETAILS:

    The 5 cows are given the numbers 2, 1, 2, 3, and 4, respectively.

    Sample Output

    2
    0
    2
    1
    3

    OUTPUT DETAILS:

    The first cow pats the second and third cows; the second cows pats no cows;
    etc.

    题解:
    开几个数组乱搞就好啦,要注意数组大小qwq
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #define qread(x)x=read();
    using namespace std;
    inline int read()
    {
        int f=1,x=0;char ch;
        while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return f*x;
    }
    int n;
    int a[1100000],s[5100000],k[5100000];
    int main()
    {
        qread(n);int maxx=-999999999;
        for(int i=1;i<=n;i++)
        {    
            qread(a[i]);
            k[a[i]]++;
            maxx=max(a[i],maxx);
        }
        for(int i=1;i<=maxx;i++)
        {
            if(k[i])
                for(int j=i;j<=maxx;j+=i)
                    s[j]+=k[i];
        }
        for(int i=1;i<=n;i++)printf("%d
    ",s[a[i]]-1);
        return 0;
    }
  • 相关阅读:
    Qt 学习 之 二进制文件读写
    QT学习 之 文本文件读写
    Qt学习 之 文件
    QT学习 之 三维饼图绘制
    Haskell 笔记(四)函数系统
    QT学习 之 事件与事件过滤器(分为五个层次)
    Qt学习 之 数据库(支持10种数据库)
    Qt5制作鼠标悬停显示Hint的ToolTip
    【码云周刊第 32 期】程序员眼中的 Vue 与 Angular !
    Qt学习 之 多线程程序设计(QT通过三种形式提供了对线程的支持)
  • 原文地址:https://www.cnblogs.com/CHerish_OI/p/7899328.html
Copyright © 2011-2022 走看看