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 |
哪里错了啊 请大牛指点#include<stdio.h> //#include<memory.h> int N,R; long int C[1001],father[1001],t[1001]; int fa,so; long int ans=0; void greedy() { for(int i=1;i<=N;i++) { long int temp,mod; long double max; mod=0; max=0.0; temp=0; for(int j=1;j<=N;j++) { if(C[j]*1.0/t[j]>max&&j!=R) { max=C[j]/t[j]; temp=j; } } for(int j=1;j<=N;j++)// { if(father[j]==temp) father[j]=father[temp]; } ans+=t[father[temp]]*C[temp]; C[father[temp]]+=C[temp]; t[father[temp]]+=t[temp]; C[temp]=0; } printf("%ld\n",ans); } int main() { //freopen("a.in", "r", stdin); // freopen("slyar.out", "w", stdout); while(scanf("%d%d",&N,&R)) { if(N==0&&R==0)break; ans=0; for(int i=1;i<=N;i++) { scanf("%ld",&C[i]); ans+=C[i]; t[i]=1; } for(int i=1;i<=N-1;i++) { scanf("%d%d",&fa,&so); father[so]=fa; } greedy(); } // fclose(stdin); //fclose(stdout); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator