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 ...
随机推荐
- CentOS6.5 安装ORACLE 安装界面乱码解决方案
在终端运行 export LANG=EN_US 然后再执行安装程序
- 使用HttpWebRequest POST 文件,带参数
public string HttpUploadFile(string url, string file, string paramName, string contentType, NameValu ...
- loader的简单使用过程分析
首先,fragment或者activity必须实现callback接口 必须实现的三个方法为 public Loader<Cursor> onCreateLoader(int id, Bu ...
- 项目一:在线下单(补充) activeMQ使用(重点) 重构客户注册功能,发短信功能分离
1 课程计划 1.在线下单(补充) 2.activeMQ使用(重点) n 简介和安装 n activeMQ入门案例 n spring整合activeMQ应用 3.重构客户注册功能,发短信功能分离 n ...
- bzoj4619 4619: [Wf2016]Swap Space
传送门 分析 首先不难想到我们要先处理容量变大的再处理容量变小的 对于第一种情况我们自然要选择x小的先格式化,因为这个样暂时存储所需空间较小,可以使得情况更优 而第二种情况y先考虑,因为这样对总空间的 ...
- 把数据分配到view
- vue 之 指令系统介绍
浏览目录 条件渲染 class 与style绑定 事件处理 指令系统介绍 所谓指令系统,大家可以联想咱们的cmd命令行工具,只要我输入一条正确的指令,系统就开始干活了. 在vue中,指令系统,设置一些 ...
- linux core文件机制
在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时加上调试信息).使用gdb来查看core文件,可以指示出导致程序出错的代码所在文件和行数. 1.core文件的生成开 ...
- C# 写 LeetCode easy #14 Longest Common Prefix
14.Longest Common Prefix Write a function to find the longest common prefix string amongst an array ...
- sql 插入
今天处理了一个有关数据库表数据批量插入的问题.部分细节,自己之前没有遇到过.索性就整理下来,做个备忘录. 主要是将一个表的数据导入到另一张表中.这种插入方法,需注意两张表的对于字段的数据结构需要保持一 ...