Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:兄台,我不是很明白你的公式(XX-2)/(d-1), 但是我用循环做不用公式一样没超时,效率和你的差不多,是600几MS. Why?

Posted by winsweet at 2009-08-22 20:21:23 on Problem 3385
In Reply To:Re:兄台,我不是很明白你的公式(XX-2)/(d-1), 但是我用循环做不用公式一样没超时,效率和你的差不多,是600几MS. Why? Posted by:gzw_02 at 2008-07-08 22:13:35
那是化简后的向上取整。。。

> #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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator