[BZOJ1607][Usaco2008 Dec]Patting Heads 輕拍牛頭
阿新 • • 發佈:2017-09-02
sca n+1 out center style detail content logs problem
Submit: 2590 Solved: 1361
[Submit][Status][Discuss]
第1行包含一個整數N,接下來第2到N+1行每行包含一個整數Ai.
2
1
2
3
4
INPUT DETAILS:
The 5 cows are given the numbers 2, 1, 2, 3, and 4, respectively.
0
2
1
3
OUTPUT DETAILS:
The first cow pats the second and third cows; the second cows pats no cows;
etc.
題意為有n個數字,對於每個數字,回答除自己外,能整除這個數字的個數,數字小於等於1e6
1607: [Usaco2008 Dec]Patting Heads 輕拍牛頭
Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 2590 Solved: 1361
[Submit][Status][Discuss]
Description
今天是貝茜的生日,為了慶祝自己的生日,貝茜邀你來玩一個遊戲. 貝茜讓N(1≤N≤100000)頭奶牛坐成一個圈.除了1號與N號奶牛外,i號奶牛與i-l號和i+l號奶牛相鄰.N號奶牛與1號奶牛相鄰.農夫約翰用很多紙條裝滿了一個桶,每一張包含了一個獨一無二的1到1,000,000的數字. 接著每一頭奶牛i從柄中取出一張紙條Ai.每頭奶牛輪流走上一圈,同時拍打所有編號能整除在紙條上的數字的牛的頭,然後做回到原來的位置.牛們希望你幫助他們確定,每一頭奶牛需要拍打的牛.Input
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.
Sample Output
20
2
1
3
OUTPUT DETAILS:
The first cow pats the second and third cows; the second cows pats no cows;
etc.
#include <cstdio> #include <algorithm> using namespace std; const int maxn = 100000 + 10, Max = 1000000 + 10; int a[maxn], ans[Max] = {0}, cnt[Max] = {0}, mx = 0; int main(){ int n; scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d", a + i); cnt[a[i]]++; mx = max(mx, a[i]); } for(int i = 1; i <= mx; i++) if(cnt[i]) for(int j = 1; i * j <= mx; j++) ans[i * j] += cnt[i]; for(int i = 1; i <= n; i++) printf("%d\n", ans[a[i]] - 1); return 0; }
[BZOJ1607][Usaco2008 Dec]Patting Heads 輕拍牛頭