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. Java was started but returned exit code=13 问题解决

    我在安装完jdk后,也对环境进行了配置,且环境的配置是没有问题的.最后我下载了eclipse,然后打开之后就发现了以下图所示的错误: Java was started but returned exi ...

  2. js利用数组实现队列与堆栈效果

    之前在写Android的时候,会用到很多的队列与堆栈方式,其实js利用数组可以简单的实现类似的效果. 队列实现 var queue = new Array(); // unshift() 方法可向数组 ...

  3. 文本框控件JTextField和JTextArea的使用

    -----------------siwuxie095                             工程名:TestUI 包名:com.siwuxie095.ui 类名:TestTextF ...

  4. C++数组对象和构造函数

    定义数组对象以后,对数组中的对象初始化的方式分为两种: 一种方式是在定义的时候用列表初始化 A a[5] = {A(1),A(2),A(3),A(4),A(5)}; 一种方式是在定义了数组对象以后,再 ...

  5. Spring 框架学习 有用

    1.1.1 spring的优势 方便解耦,简化开发 通过Spring提供的IoC容器,可以将对象间的依赖关系交由Spring进行控制,避免硬编码所造成的过度程序耦合.用户也不必再为单例模式类.属性文件 ...

  6. Luogu 1514 [NOIP2010] 引水入城

    我就是过来开心一下……这道题从开坑以来已经堆积了大半年了……今天才发现广搜一直写挂…… 丢个线段覆盖的模板,设$f_{i}$表示覆盖区间[1, i]的最小代价,$g_{i, j}$表示覆盖区间[i, ...

  7. python3-list列表增删改查合并排序

    # Auther: Aaron Fan names = ["aaron", "alex", "james", "meihengfa ...

  8. java全栈day10--接口 多态

    接口的概念 接口是功能的集合,同样可看做是一种数据类型,是比抽象类更为抽象的”类”. 接口只描述所应该具备的方法,并没有具体实现,具体的实现由接口的实现类(相当于接口的子类)来完成.这样将功能的定义与 ...

  9. 冒泡排序的PHP实现

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

  10. DiscreteFrechetDist

    计算离散的frechet 距离,通过计算两条曲线之间的点的距离,将两条曲线上的点按照距离以及曲线的趋势进行配对,最后根据这些配对的距离选出最后的离散frechet距离(compute discrete ...