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加倍???
[解决办法]