您的位置:首页 > 其它

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

2013-04-03 21:39 597 查看
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
;
}
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--;
}
}
}


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

提醒自己不要粗心。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: