Description

It's Bessie's birthday and time for party games! Bessie has instructed the N (1 < N < 100,000) cows conveniently numbered 1..N to sit in a circle (so that cow i [except at the ends] sits next to cows i-1 and i+1; cow N sits next to cow 1). Meanwhile, Farmer John fills a barrel with one billion slips of paper, each containing some integer in the range 1..1,000,000.

Each cow i then draws a number Ai (1 ≤ Ai ≤ 1,000,000) (which is not necessarily unique, of course) from the giant barrel. Taking turns, each cow i then takes a walk around the circle and pats the heads of all other cows j such that her number Ai is exactly divisible by cow j's number Aj; she then sits again back in her original position.

The cows would like you to help them determine, for each cow, the number of other cows she should pat.

Input

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains a single integer: Ai

Output

* Lines 1..N: On line i, print a single integer that is the number of other cows patted by cow i.

Sample Input

5
2
1
2
3
4

Sample Output

2
0
2
1
3

Hint

The 5 cows are given the numbers 2, 1, 2, 3, and 4, respectively. The first cow pats the second and third cows; the second cows pats no cows; etc.

题目大概的意思就是说牛1手上的数字可以去整除其他牛的数字,则可以去爆他狗头。
一开始我是想说一一去枚举的,从一找到牛手上的数可以整除的数,去加他,但发现超时。
于是有了这种思路,我从1到牛手上的最大的数枚举,if这个数字是有的,那这个数的倍数都加上他的次数;
AC 代码
#include<stdio.h>
int num1[]={};
int num2[]={};
int a[];
int main()
{
int n,i,mix=,j; scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
num1[a[i]]++; } for(i=;i<=n;i++)
if(mix<a[i])
mix=a[i]; for(i=;i<=mix;i++)
{ if(num1[i]!=)
for(j=i;j<=mix;j=j+i)
{
num2[j]=num2[j]+num1[i]; }
} for(i=;i<=n;i++)
printf("%d\n",num2[a[i]]-);
}

Patting Heads的更多相关文章

  1. BZOJ-1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法+乱搞

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 1383 Solved: 7 ...

  2. BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lyds ...

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

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Description   今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏.     贝茜让N(1≤N≤10 ...

  4. bzoj1607 / P2926 [USACO08DEC]拍头Patting Heads

    P2926 [USACO08DEC]拍头Patting Heads 把求约数转化为求倍数. 累计每个数出现的个数,然后枚举倍数累加答案. #include<iostream> #inclu ...

  5. 浅谈桶排思想及[USACO08DEC]Patting Heads 题解

    一.桶排思想 1.通过构建n个空桶再将待排各个元素分配到每个桶.而此时有可能每个桶的元素数量不一样,可能会出现这样的情况:有的桶没有放任何元素,有的桶只有一个元素,有的桶不止一个元素可能会是2+: 2 ...

  6. [bzoj1607][Usaco2008 Dec]Patting Heads 轻拍牛头_筛法_数学

    Patting Heads 轻拍牛头 bzoj-1607 Usaco-2008 Dec 题目大意:题目链接. 注释:略. 想法:我们发现,位置是没有关系的. 故,我们考虑将权值一样的牛放在一起考虑,c ...

  7. 洛谷 P2926 [USACO08DEC]拍头Patting Heads

    P2926 [USACO08DEC]拍头Patting Heads 题目描述 It's Bessie's birthday and time for party games! Bessie has i ...

  8. [Usaco2008 Dec]Patting Heads

    It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 100,00 ...

  9. [USACO08DEC]拍头Patting Heads 数学 BZOJ 1607

    题目描述 It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 1 ...

随机推荐

  1. 1、序列化 2、转义 3、eval 4、正则表达式 5、时间处理

    1.序列化 JSON.stringify(obj)   序列化 JSON.parse(str)        反序列化 2.转义 decodeURI( )                   URl中 ...

  2. ROS探索总结(一)——ROS简介

    转自古-月 ROS探索总结(一)——ROS简介 一.历史 随着机器人领域的快速发展和复杂化,代码的复用性和模块化的需求原来越强烈,而已有的开源机器人系统又不能很好的适应需求.2010年Willow G ...

  3. unity3D中制作天空盒(Skyboxes)

    1.首先制作图片,需要把图片用Ps制作成psd格式,制作6张 2.把6个psd文件导入工程目录 Assets下, 3.在project属性列表中选中Assets,单击鼠标右键选择 Create —&g ...

  4. little case1

    这句话有问题: frame.setContentPane().add(button); The method setContentPane(Container) in the type JFrame ...

  5. Xcode 运行时找不到xib资源文件

    调试运行时候,提示找不到xib(或者其他)资源文件,在工程中确实看的到该资源文件,到具体运行的资源目录([[NSBundlemainBundle] resourcePath]),没有看到该文件,而其他 ...

  6. ZROI2018提高day2t1

    传送门 分析 考场上写了前20分和|a[i]|<=1的情况,但是因为没开long long爆零了.实际考场上差不多想到正解了,至少当时不会凸壳... 我们发现对于ax2+bx的大小关系我们可以将 ...

  7. p2657 windy数

    传送门 分析 首先这是一个询问一段区间内的个数的问题,所以我们可以用差分的思想用sum(R)-sum(L-1).然后我们考虑如何求出sum(n),我们用dp[i][j][k][t]表示考虑到第i位,最 ...

  8. Luogu 4103 [HEOI2014]大工程

    BZOJ 3611 明明在BZOJ上是$6s$的时限,怎么到Luogu上就变成$4s$了…… 按照套路建出虚树,点之间的距离可以变成边权表示在虚树上,然后考虑如何树形$dp$. 最大值和最小值应当比较 ...

  9. 冒泡排序的PHP实现

    定义: 它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成. 排序思想:(从后往前) 比较相邻的 ...

  10. python(一):作用域

    与c相比,python作用域很奇特. 在Python中变量的作用域是由它在源代码中的位置决定的,这一点与c相似. python只支持4种作用域,即局部作用域,全局作用域,内置作用域,嵌套作用域. 比较 ...