首页 > 代码库 > BZOJ1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
BZOJ1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 779 Solved: 404
[Submit][Status]
Description
今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏.
贝茜让N(1≤N≤100000)头奶牛坐成一个圈.除了1号与N号奶牛外,i号奶牛与i-l号和i+l号奶牛相邻.N号奶牛与1号奶牛相邻.农夫约翰用很多纸条装满了一个桶,每一张包含了一个独一无二的1到1,000,000的数字.
接着每一头奶牛i从柄中取出一张纸条Ai.每头奶牛轮流走上一圈,同时拍打所有编号能整除在纸条上的数字的牛的头,然后做回到原来的位置.牛们希望你帮助他们确定,每一头奶牛需要拍打的牛.
Input
第1行包含一个整数N,接下来第2到N+1行每行包含一个整数Ai.
Output
第1到N行,每行的输出表示第i头奶牛要拍打的牛数量.
Sample Input
5 //有五个数,对于任一个数来说,其它的数有多少个是它的约数
2
1
2
3
4
INPUT DETAILS:
The 5 cows are given the numbers 2, 1, 2, 3, and 4, respectively.
2
1
2
3
4
INPUT DETAILS:
The 5 cows are given the numbers 2, 1, 2, 3, and 4, respectively.
Sample Output
2
0
2
1
3
OUTPUT DETAILS:
The first cow pats the second and third cows; the second cows pats no cows;
etc.
0
2
1
3
OUTPUT DETAILS:
The first cow pats the second and third cows; the second cows pats no cows;
etc.
HINT
Source
Silver
题解:
竟然是筛法。。。想了好久没思路果断看题解。。。
这么暴力的思路?不过时间复杂度倒也不高
主要是没往这方面想。。。
代码:
1 var a,b,c:array[0..1500000] of longint; 2 i,max,j,n:longint; 3 begin 4 assign(input,‘input.txt‘);assign(output,‘output.txt‘); 5 reset(input);rewrite(output); 6 max:=0; 7 readln(n);for i:=1 to n do begin readln(a[i]);if a[i]>max then max:=a[i];inc(b[a[i]]);end; 8 for i:=1 to max do 9 if b[i]<>0 then10 begin11 j:=i;12 while j<=max do13 begin14 inc(c[j],b[i]);15 inc(j,i);16 end;17 end;18 for i:=1 to n do writeln(c[a[i]]-1);19 close(input);close(output);20 end.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。