BZOJ——1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
http://www.lydsy.com/JudgeOnline/problem.php?id=1607
Time Limit: 3 Sec Memory Limit: 64 MB
Submit: 2795 Solved: 1438
[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
筛法求出每个ai对ans 的贡献
#include <algorithm>
#include <cstdio> inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
}
const int M();
const int N();
int n,a[N],b[N];
int cnt[M],maxn,ans[M]; int Presist()
{
read(n);
for(int i=; i<=n; ++i)
{
read(a[i]),cnt[a[i]]++;
maxn=maxn>a[i]?maxn:a[i];
}
for(int i=; i<=maxn; ++i)
{
if(!cnt[i]) continue;
for(int j=i; j<=maxn; j+=i)
ans[j]+=cnt[i];
}
for(int i=; i<=n; ++i)
printf("%d\n",ans[a[i]]-);
return ;
} int Aptal=Presist();
int main(int argc,char**argv){;}
BZOJ——1607: [Usaco2008 Dec]Patting Heads 轻拍牛头的更多相关文章
- 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 轻拍牛头——枚举倍数
题目: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 轻拍牛头【瞎搞】
某种意义上真毒瘤?我没看懂题啊...于是看了题解 就是筛约数的那种方法,复杂度调和级数保证O(nlogn) 所以这题啥意思啊 #include<iostream> #include< ...
- 【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 ...
- BZOJ-1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法+乱搞
1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 1383 Solved: 7 ...
- [bzoj1607][Usaco2008 Dec]Patting Heads 轻拍牛头_筛法_数学
Patting Heads 轻拍牛头 bzoj-1607 Usaco-2008 Dec 题目大意:题目链接. 注释:略. 想法:我们发现,位置是没有关系的. 故,我们考虑将权值一样的牛放在一起考虑,c ...
随机推荐
- synchronized 和ReentrantLock的区别
历史知识:JDK5之前,只有synchronized 可以用,之后就有了ReetrantLock可以用了 ReetrantLock (再入锁) 1.位于java.util.concurrnt.lock ...
- 洛谷 P1514 引水入城
这次不说闲话了,直接怼题 这道题用bfs其实并不难想,但比较困难的是怎么解决满足要求时输出蓄水厂的数量.其实就像其他题解说的那样,我们可以用bfs将它转化成一个区间覆盖问题,然后再进行贪心. 首先枚举 ...
- Git学习——版本切换
版本回退 回退到前面几个版本的命令如下: git reset --hard HEAD^ //回退到前一个版本 git reset --hard HEAD^^ //回退到前前一个版本 git reset ...
- html块级元素和行级元素的区别和使用
行内.块状元素区别: 1.行内元素与块级函数可以相互转换,通过修改display属性值来切换块级元素和行内元素,行内元素display:inline,块级元素display:block. 2.行内元素 ...
- MySQL学习点滴
MySQL学习点滴 --分区表 概述: 分区功能并不是在存储引擎层完成的,因此很多存储引擎包括InnoDB, MyISAM, NDB等都支持分区功能.但也并不是所有的存储引擎都支持分区.在使用分区前, ...
- LeetCode(119) Pascal's Triangle II
题目 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [ ...
- LeetCode(72) Edit Distance
题目 Given two words word1 and word2, find the minimum number of steps required to convert word1 to wo ...
- Maven运行报错:-Dmaven.multiModuleProjectDirectory system propery is not set.
eclipse中使用maven插件的时候,运行run as maven build的时候报错 -Dmaven.multiModuleProjectDirectory system propery is ...
- grunt与seajs结合应用
9.seajs构建的问题 01.png和02.jpg 10.seajs与grunt如何结合开发.两个插件:grunt-cmd-transport grunt-cmd-contact ,去grunt官网 ...
- HTML与XML的区别
什么是HTML HTML的全拼是Hypertext Markup Language, 中文也就是超文本链接标示语言.HTML(HyperTextMark-upLanguage)即超文本标记语言,是WW ...