HDU 2570 写在这里,提醒自己不要粗心。。。。。。。

import java.util.Scanner;
import java.util.Arrays;
public class Main
{
       int n;
       int v;
       int w;
       int[] a;
       Main( int n,int v,int w )
       {
             this.n = n;
             this.v = v;
             this.w = w;
             this.a = new int[n];
       }
       public void setA( int i,int b )
       {
              this.a[i] = b;
       }
       public void getM()
       {
              Arrays.sort( this.a );
              int k = 0;
              int sum = 0;   
              int f = this.w;                    
              for( int i=0;i<this.n;i++ )
              {                 
                   sum += this.a[i];                 
                   if( sum>this.w )
                   {
                       sum -= this.a[i];                      
                       break;
                   }
                   else
                   {
                       k++;
                       this.w += f;
                    }
              }            
              if( k>0 ) 
              {                
                  double c = sum*0.01/k;
                  System.out.print( k*this.v  + " " );
                  System.out.printf( "%.2f",c );
                  System.out.println();
              }
              else
              {
                  System.out.println( "0 0.00" );
              }
       }
       public static void main(String[] args)
       {
              int n=0;
              Scanner s = new Scanner(System.in);
              int c=0;
              c = s.nextInt();
              int v=0;
              int w=0;
              while( c>0 )
              {
                     n = s.nextInt();
                     v = s.nextInt();
                     w = s.nextInt();
                     Main m = new Main( n,v,w );
                     for( int i=0;i<n;i++ )
                     {
                          int b = s.nextInt();
                          m.setA( i,b );
                     }
                     m.getM();
                     c--;
              }
       }
}


唉,确实还是太粗心了。。。。。。

提醒自己不要粗心。。。。。。







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值