BZOJ【1607】轻拍牛头
1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
Time Limit: 3 Sec Memory Limit: 64 MB
Submit: 1245 Solved: 650
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
2
1
2
3
4
INPUT DETAILS:
The 5 cows are given the numbers 2, 1, 2, 3, and 4, respectively.
Sample Output
0
2
1
3
OUTPUT DETAILS:
The first cow pats the second and third cows; the second cows pats no cows;
etc.
HINT
Source
注意读题,记录每个奶牛持有的卡号被整除的次数,直接ans[a[i]],类似于求素数,筛法
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define maxn 1000000+10
#define inf 0x7fffffff
using namespace std;
int a[maxn],cnt[maxn],ans[maxn];
int main()
{
int n,maxm=-inf;
cin>>n;
for(int i=;i<=n;++i) scanf("%d",&a[i]),cnt[a[i]]++;
for(int i=;i<=n;++i) maxm=max(maxm,a[i]);
for(int i=;i<=maxm;++i)
{ if(cnt[i])
for(int j=i;j<=maxm;j+=i) ans[j]+=cnt[i];}
for(int i=;i<=n;++i) printf("%d\n",ans[a[i]]-);
return ;
}
BZOJ【1607】轻拍牛头的更多相关文章
- 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 ...
- 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个数,求每个数能被多少个其他的数整除. 分析 暴力一点的做法就是每个数去筛它的 ...
- [bzoj1607][Usaco2008 Dec]Patting Heads 轻拍牛头_筛法_数学
Patting Heads 轻拍牛头 bzoj-1607 Usaco-2008 Dec 题目大意:题目链接. 注释:略. 想法:我们发现,位置是没有关系的. 故,我们考虑将权值一样的牛放在一起考虑,c ...
- 【BZOJ】1607: [Usaco2008 Dec]Patting Heads 轻拍牛头(特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1607 其实题目描述不清楚,应该是 别人拿的数能整除自己拿的数 数据范围很大,n<=100000 ...
- bzoj 1607 Patting Heads 轻拍牛头
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1607 题解: 题目似乎出错,应为“同时拍打所有所持纸条上的数字能被此牛所持纸条上的数字整除 ...
- 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 ...
随机推荐
- 51nod——2476 小b和序列(预处理 思维)
对于每一个元素,预处理出它作为最小值,两边可以作用到的最大位置.比如下标∈[0,8]的这个数组:1 8 6 2 5 4 3 8 7,1可以作用到所有区间,2可以作用到区间[1,8],第一个8可以作用到 ...
- jquery实现全选、取消反选、加JavaScript三元运算(三种法法实现反选)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- oracle一些常用的数据类型
字符数据类型 char数据类型 当需要固定长度时,使用char数据类型,此数据类型长度可以使1-2000字节.若是不指定大小默认占1字节,如果长度有空余时会以空格进行填充,如果大于设定长度 数据库则会 ...
- java.lang.ClassCastException: com.sun.proxy.$Proxy53 cannot be cast to cn.service.impl.WorkinggServiceImpl
java.lang.ClassCastException: com.sun.proxy.$Proxy53 cannot be cast to cn.service.impl.WorkinggServi ...
- PHP跨域请求nodejs
摘要:用nodejs作为服务器,php作为客服端进行跨域请求,并返回数据. 一:windows环境下的nodejs安装(以及express模板的安装):http://blog.uifanr.com/2 ...
- linux 的安装
3linux 软件安装 3.1 vm ware 软件安装 双击VMware-workstation-full-10.0.2-1744117.1398244508.exe 单击下一步 单击下一步 选择典 ...
- hive的常用HQL语句
1.过滤条件 where .limit. distinct. between and . null. is not nullselect * from emp where sal > 3000; ...
- 适合学习的QT开源项目-SerialTool
https://github.com/Skiars/SerialTool A cross platform Serial-Port/TCP/UDP debugging tool. SerialTool ...
- Keywords Search HDU - 2222 ( ac自动机)模版题
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- Codeforces Round #462 (Div. 2) D. A Determined Cleanup
D. A Determined Cleanup time limit per test1 second memory limit per test256 megabytes Problem Descr ...