洛谷 P2926 [USACO08DEC]拍头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 A_i (1 <= A_i <= 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 A_i is exactly
divisible by cow j's number A_j; 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.
今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏.
贝茜让N(1≤N≤100000)头奶牛坐成一个圈.除了1号与N号奶牛外,i号奶牛与i-l号和i+l号奶牛相邻.N号奶牛与1号奶牛相邻.农夫约翰用很多纸条装满了一个桶,每一张包含了一个不一定是独一无二的1到1,000,000的数字.
接着每一头奶牛i从柄中取出一张纸条Ai.每头奶牛轮流走上一圈,同时拍打所有手上数字能整除在自己纸条上的数字的牛的头,然后做回到原来的位置.牛们希望你帮助他们确定,每一头奶牛需要拍打的牛.
输入输出格式
输入格式:
Line 1: A single integer: N
- Lines 2..N+1: Line i+1 contains a single integer: A_i
输出格式:
- Lines 1..N: On line i, print a single integer that is the number of other cows patted by cow i.
输入输出样例
说明
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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,maxn;
int a[];
int ma[],ans[];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
ma[a[i]]++;maxn=max(a[i],maxn);
}
for(int i=;i<=maxn;i++){
if(!ma[i]) continue;
for(int j=i;j<=maxn;j+=i)
ans[j]+=ma[i];
}
for(int i=;i<=n;i++)
cout<<ans[a[i]]-<<endl;
}
洛谷 P2926 [USACO08DEC]拍头Patting Heads的更多相关文章
- 【题解】洛谷P2926 [USACO08DEC]拍头Patting Heads
洛谷P2926:https://www.luogu.org/problemnew/show/P2926 思路 对于每一个出现的数 从1到Max 凡是这个数的倍数 那么ans就加上他的个数 PS:最后要 ...
- bzoj1607 / P2926 [USACO08DEC]拍头Patting Heads
P2926 [USACO08DEC]拍头Patting Heads 把求约数转化为求倍数. 累计每个数出现的个数,然后枚举倍数累加答案. #include<iostream> #inclu ...
- [USACO08DEC]拍头Patting Heads 数学 BZOJ 1607
题目描述 It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 1 ...
- [USACO08DEC]拍头Patting Heads 水题
类似素数筛,暴力可过,不需要太多的优化 Code: #include<cstdio> #include<algorithm> #include<string> us ...
- 洛谷 P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵 ...
- 洛谷——P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N< ...
- 洛谷p2922[USACO08DEC]秘密消息Secret Message
题目: 题目链接:[USACO08DEC]秘密消息Secret Message 题意: 给定n条01信息和m条01密码,对于每一条密码A,求所有信息中包含它的信息条数和被它包含的信息条数的和. 分析: ...
- C++ 洛谷 P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题解
P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 分析: 这棵树上有且仅有一个环 两种情况: 1.讨论一个点在环上,如果在则答案与它指向点相同, 2 ...
- 洛谷P2925 [USACO08DEC]干草出售Hay For Sale
题目描述 Farmer John suffered a terrible loss when giant Australian cockroaches ate the entirety of his ...
随机推荐
- 四、服务器上的 Git
一个远程仓库通常只是一个裸仓库(bare repository)— 即一个没有当前工作目录的仓库.因为该仓库仅仅作为合作媒介,不需要从磁碟检查快照:存放的只有 Git 的资料.简单的说,裸仓库就是你专 ...
- Python中的itertools.product
例子1:import itertoolsa = itertools.product([1,2,3],[100,200])print(a)for item in itertools.product([1 ...
- 移动设备safari不支持jquery的live绑定的解决方案
给元素加上样式如下即可 <style> .btn{ cursor: pointer; } </style>
- Windows 10快速在指定目录打开命令行
一.我们在想要到达的目录上按住shift键并点击鼠标右键.看到了吗,这时候在弹出菜单里多了一个选项,就是"在此处打开命令窗口",我们点开看一下. 二.不过有时候我们需要以管理员的权 ...
- PHP下的异步尝试三:协程的PHP版thunkify自动执行器
PHP下的异步尝试系列 如果你还不太了解PHP下的生成器和协程,你可以根据下面目录翻阅 PHP下的异步尝试一:初识生成器 PHP下的异步尝试二:初识协程 PHP下的异步尝试三:协程的PHP版thunk ...
- -bash: wget 未找到命令的解决办法
在Linux操作系统中,我们会经常要用到wget下载文件.wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性. 在linux中使用wget时,若报-bash: wget: comman ...
- MongoDB之Java測试代码(DAO层)
MongoInit.java是数据库初始化及连接类 MongoUtils.java是对mongodb的各种操作方法 MongoInit.java package com.wlwcloud.datate ...
- 哈理工2015暑假训练赛 zoj 2078Phone Cell
Phone CellTime Limit:10000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu SubmitStatus ...
- [jzoj 5930] [NOIP2018模拟10.26】山花 解题报告 (质因数分类)
题目链接: http://172.16.0.132/senior/#contest/show/2538/2 题目: 小S决定从某一个节点$u$开始对其子树中与$u$距离小于$K$的节点代表的花树进行采 ...
- C#~异步编程再续~你必须要知道的ThreadPool里的throw
问题依旧存在 之前写过相关文章异步编程的文章,本文主要还是一点补充,之前在IIS经常发w3wp进程无做挂了的情况,但一直没能找到真正的原因,而查找相关资料,找了一些相关的文章,如await和async ...