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号奶 ...
随机推荐
- TCP/IP详解学习笔记(6)-UDP协议
1.UDP简要介绍 UDP是传输层协议,和TCP协议处于一个分层中,但是与TCP协议不同,UDP协议并不提供超时重传,出错重传等功能,也就是说其是不可靠的协议. 2.UDP协议头 2.1.UDP端口号 ...
- Android中FragmentPagerAdapter对Fragment的缓存(一)
ViewPager + FragmentPagerAdapter,时我们经常使用的一对搭档,其实际应用的代码也非常简单,但是也有一些容易被忽略的地方,这次我们就来讨论下FragmentPagerAda ...
- 自己动手写路由器之ioctl获取网络接口信息
最近打算写一个简单路由器,里面有用到ioctl获取网络接口信息,那就先把这部分单独拿出来说一说吧! ioctl这个函数,可以用来对特殊文件的基础设备参数进行操作,它们可以完成与打开文件描述符相关联的控 ...
- IOS color 颜色值比较
/生成采样对照颜色(黑色) UIColor* sampleColor = [UIColor colorWithRed:(0/255.0f) green:(0/255.0f) blue:(0/255. ...
- iOS已发布应用中对异常信息捕获和处理
iOS已发布应用中对异常信息捕获和处理 iOS开发中我们会遇到程序抛出异常退出的情况,如果是在调试的过程中,异常的信息是一目了然,但是如果是在已经发布的程序中,获取异常的信息有时候是比较困难的. iO ...
- JQuery WEB前段开发
JQuery WEB前段开发 Jquery是继prototype之后又一个优秀的Javascript框架.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, S ...
- [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数
Built-in Operators Relational Operators The following operators compare the passed operands and gene ...
- [转]Ubuntu下GitHub的使用
转自Pythoner 本文将对Ubuntu下Git的安装,以及如何连接GitHub进行讲解. 1.环境 OS: Ubuntu13.04 64bitsGit: 1.8.1.2 2.Git安装 执行如下命 ...
- MVC使用Google OAuth[OWIN]注意事項
1.前提條件,申請一個client id,頁面:https://console.developers.google.com/ 2.添加連接域名,javascript那欄位為域名即可,另一欄需要加上具體 ...
- HDU 5744 Keep On Movin (贪心)
Keep On Movin 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...