BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法
1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=1607
Description
Input
第1行包含一个整数N,接下来第2到N+1行每行包含一个整数Ai.
Output
第1到N行,每行的输出表示第i头奶牛要拍打的牛数量.
Sample Input
5 //有五个数,对于任一个数来说,其它的数有多少个是它的约数
2
1
2
3
4
Sample Output
2
0
2
1
3
HINT
题意
题解:
筛法,对于每一个数,我们都筛一遍这个数对哪些数有贡献就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int n;
int H[maxn];
int H1[maxn];
int a[maxn];
int main()
{
n=read();
int M=;
int x;
for(int i=;i<=n;i++)
a[i]=read(),M=max(M,a[i]),H[a[i]]++;
for(int i=;i<=M;i++)
{
if(H[i])
{
for(int j=i;j<=M;j+=i)
H1[j]+=H[i];
}
}
for(int i=;i<=n;i++)
printf("%d\n",H1[a[i]]-);
}
BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法的更多相关文章
- BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Description 今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏. 贝茜让N(1≤N≤10 ...
- bzoj 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头——枚举倍数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1607 #include<iostream> #include<cstdio ...
- BZOJ 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头:统计 + 筛法【调和级数】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1607 题意: 给你n个数,问你除a[i]之外,有多少个数是a[i]的约数. 题解: ans ...
- BZOJ——1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
http://www.lydsy.com/JudgeOnline/problem.php?id=1607 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 2 ...
- bzoj 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头【瞎搞】
某种意义上真毒瘤?我没看懂题啊...于是看了题解 就是筛约数的那种方法,复杂度调和级数保证O(nlogn) 所以这题啥意思啊 #include<iostream> #include< ...
- 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 轻拍牛头(特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1607 其实题目描述不清楚,应该是 别人拿的数能整除自己拿的数 数据范围很大,n<=100000 ...
- 【BZOJ】1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
[算法]模拟 #include<cstdio> #include<algorithm> using namespace std; ,maxm=; int a[maxn],A[m ...
- [Usaco2008 Dec]Patting Heads 轻拍牛头[筛法]
Description 今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏. 贝茜让N(1≤N≤100000)头奶牛坐成一个圈.除了1号与N号奶牛外,i号奶牛与i-l号和i+l号奶 ...
随机推荐
- 130道ASP.NET面试题
转:http://boke.25k5.com/kan88569.html 1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . privat ...
- Java 如何防止线程意外中止
Thread的run方法是不抛出任何检查型异常(checked exception)的,但是它自身却可能因为一个异常而被终止,导致这个线程的终结.最麻烦的是,在线程中抛出的异常即使使用try...ca ...
- Android-监听sdcard状态
public class MyService extends Service { private static final String TAG = "MyService"; Fi ...
- wpa_cli调试工具的使用
1: run wpa_supplicant first use the following command: wpa_supplicant -Dwext -iwlan0 -C/data/system/ ...
- C# Read/Write another Process' Memory z
http://www.codeproject.com/Articles/670373/Csharp-Read-Write-another-Process-Memory This article aim ...
- C++ primer里的template用法
来源:http://c.chinaitlab.com/cc/ccjq/200806/752604_2.html -- template 的用法 在程序设计当中经常会出现使用同种数据结构的不同实 ...
- POJ 3744 Scout YYF I (概率dp+矩阵快速幂)
题意: 一条路上,给出n地雷的位置,人起始位置在1,向前走一步的概率p,走两步的概率1-p,踩到地雷就死了,求安全通过这条路的概率. 分析: 如果不考虑地雷的情况,dp[i],表示到达i位置的概率,d ...
- 【剑指offer 面试题23】从上往下打印二叉树
思路: 没啥好说的,BFS. C++: #include <iostream> #include <queue> using namespace std; struct Tre ...
- Linux基本命令(3)文件备份和压缩命令
文件备份和压缩命令 在Linux中,常用的文件压缩工具有gzip.bzip2.zip.bzip2是最理想的压缩工具,它提供了最大限度的压缩.zip兼容性好,Windows也支持. 命令 功能 bzip ...
- 【原】Storm Local模式和生产环境中Topology运行配置
Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...