| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:兄台,我不是很明白你的公式(XX-2)/(d-1), 但是我用循环做不用公式一样没超时,效率和你的差不多,是600几MS. Why?In Reply To:有时AC……有时RE……还有时TLE…… Posted by:a_team at 2007-09-23 13:22:57 #include <stdio.h>
#include <memory.h>
int child[100001];
int n,d;
int get_child(int c){
int p,m,s=0;
while(c>d){
s+=(p=c/d);
m=c%d;
c=p+m;
}
return s;
}
int main() {
int i, c, sum;
while(scanf("%d %d", &n, &d)!=EOF){
sum=0;
memset(child,0,sizeof(int)*(n+1));
for(i = 0; i < n; i++){
scanf("%d", &c);
child[c]++;
}
for(i = 0; i < n; i++)
if(child[i] > d)
sum+=get_child(child[i]);
printf("%d\n", sum);
}
return 1;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator