可惜没如果=_=
时光的河入海流

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

Time Limit: 3 Sec  Memory Limit: 64 MB
Submit: 2812  Solved: 1449
[Submit][Status][Discuss]

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.

HINT

 

Source

这其实是今晚校内自测的第一题……当时想了好久好久的说qwq 没想到筛法还有这种妙用哇qwq对了laj蒟蒻终于完成小小小目标BZOJ50题了qwq 大佬勿喷qwq
 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <iostream>
 4 using namespace std;
 5 typedef long long LL;
 6 const int MAX=1e5+5;
 7 int n;
 8 int a[MAX],b[1000005],an[1000005];
 9 inline int read(){
10     int an=0,x=1;char c=getchar();
11     while (c<'0' || c>'9') {if (c=='-') x=-1;c=getchar();}
12     while (c>='0' && c<='9') {an=(an<<3)+(an<<1)+c-'0';c=getchar();}
13     return an*x;
14 }
15 int main(){
16     freopen ("pat.in","r",stdin);freopen ("pat.out","w",stdout);
17     register int i,j,mx=0;
18     n=read();
19     for (i=1;i<=n;i++) a[i]=read(),b[a[i]]++,mx=max(mx,a[i]);
20     for (i=1;i<=mx;i++)
21         if (b[i])
22             for (j=i;j<=mx;j+=i)
23                 an[j]+=b[i];
24     for (i=1;i<=n;i++)
25         printf("%d\n",an[a[i]]-1);
26     return 0;
27 }

 

posted on 2017-10-26 00:49  珍珠鸟  阅读(201)  评论(0编辑  收藏  举报