Patting Heads
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.
* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 contains a single integer: Ai
* Lines 1..N: On line i, print a single integer that is the number of other cows patted by cow i.
5
2
1
2
3
4
2
0
2
1
3
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.
#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的更多相关文章
- BZOJ-1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法+乱搞
1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 1383 Solved: 7 ...
- BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法
1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lyds ...
- BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Description 今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏. 贝茜让N(1≤N≤10 ...
- bzoj1607 / P2926 [USACO08DEC]拍头Patting Heads
P2926 [USACO08DEC]拍头Patting Heads 把求约数转化为求倍数. 累计每个数出现的个数,然后枚举倍数累加答案. #include<iostream> #inclu ...
- 浅谈桶排思想及[USACO08DEC]Patting Heads 题解
一.桶排思想 1.通过构建n个空桶再将待排各个元素分配到每个桶.而此时有可能每个桶的元素数量不一样,可能会出现这样的情况:有的桶没有放任何元素,有的桶只有一个元素,有的桶不止一个元素可能会是2+: 2 ...
- [bzoj1607][Usaco2008 Dec]Patting Heads 轻拍牛头_筛法_数学
Patting Heads 轻拍牛头 bzoj-1607 Usaco-2008 Dec 题目大意:题目链接. 注释:略. 想法:我们发现,位置是没有关系的. 故,我们考虑将权值一样的牛放在一起考虑,c ...
- 洛谷 P2926 [USACO08DEC]拍头Patting Heads
P2926 [USACO08DEC]拍头Patting Heads 题目描述 It's Bessie's birthday and time for party games! Bessie has i ...
- [Usaco2008 Dec]Patting Heads
It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 100,00 ...
- [USACO08DEC]拍头Patting Heads 数学 BZOJ 1607
题目描述 It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 1 ...
随机推荐
- Solr5.5.3的研究之路 ---1、从Mysql导入数据并创建索引
公司需要用到全文检索,故使用Solr,也是新人一枚,本人查看的前提是Solr已经安装部署成功,我用的服务器是自带的Jetty 1.创建Collection [root@whoami bin]# ./s ...
- [Python Study Notes]双层柱状图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- CUDA编程接口:异步并发执行的概念和API
1.主机和设备间异步执行 为了易于使用主机和设备间的异步执行,一些函数是异步的:在设备完全完成任务前,控制已经返回给主机线程了.它们是: 内核发射; 设备间数据拷贝函数; 主机和设备内拷贝小于64KB ...
- ES02 变量、数组、对象、方法
1 变量 1.1 变量的声明 利用var关键字来声明变量,例如: var a = 100; <!DOCTYPE html> <html> <head> <me ...
- SQl Server T-sql语句学习
T-sql语句就是通过代码来代替鼠标完成一些操作,使用起来要比鼠标方便很多. 创建数据库 careate database +数据库名. 数据库名不能为中文,不能以数字开头. use 数据库 ...
- 中华人民共和国建筑工业行业标准—IFC详细解读 第五篇
- 高性能MySQL笔记-第5章Indexing for High Performance-004怎样用索引才高效
一.怎样用索引才高效 1.隔离索引列 MySQL generally can’t use indexes on columns unless the columns are isolated in t ...
- Mat 类的内存管理
使用 Mat 类,内存管理变得简单,不再像使用 IplImage 那样需要自己申请和释放内存.虽然不了解 Mat 的内存管理机制,也无碍于 Mat 类的使用,但是如果清楚了解 Mat 的内存管理,会更 ...
- 形式化验证工具(PAT)Perterson Algorithm学习
今天学习一下Perterson Algorithm. 这个算法是使用三个变量来实现并发程序的互斥性算法. 具体看一下代码: Peterson算法是一个实现互斥锁的并发程序设计算法,核心就是三个标志位是 ...
- kaggle Titanic
# coding: utf-8 # In[19]: # 0.78468 # In[20]: import numpy as np import pandas as pd import warnings ...