首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

HDU 2570 一直WA,该如何处理

2013-04-09 
HDU 2570 一直WAimport java.util.Scannerimport java.util.Arrayspublic class Main{int nint vint w

HDU 2570 一直WA
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;           //k来获得总的体积
              int sum = 0;         //sum获得总的浓度              
              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 += this.w;
                    }


              }            
              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--;
              }
       }
} HDU ACM
[解决办法]
this.w += this.w;

每次w加倍???
[解决办法]

引用:
引用:this.w += this.w;

每次w加倍???

是啊,(p1%+p2%+....+pn%)/n < w 吗?
这样的和,加上一个pi%,就要加上一个w了啊?

不是这样吗?

但是你现在加到p3的时候是4个原来的w。加到p4的时候是8个原来的w。加到p5的时候是16个原来的w。

热点排行