| ||||||||||
| 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 | |||||||||
救救孩子把!!!一直WA,麻了import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int n = 0;
static int k = 0;
static int[][] text = null;
static int[] ans = null;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
n = sc.nextInt();
k = sc.nextInt();
text= new int[n][2];
ans = new int[k];
for(int i = 0; i < n; i++) {
text[i][0] = sc.nextInt();
text[i][1] = sc.nextInt();
}
double left = 0;
double right = 1.1; //上界是1,比1大就可以
while(right-left>=1e-6) {
double mid = (left+right)/2;
if(C(mid)) {
left = mid;
}else {
right = mid;
}
}
for(int index = 0; index < k; index++){
System.out.printf("%d%c",ans[index]+1,index==k-1?'\n':' ');
}
}
}
public static boolean C(double mid) {
int sum = 0;
SZ[] value = new SZ[n];
for(int i = 0; i < n; i++) {
value[i] = new SZ();
value[i].pow = text[i][0] - mid*text[i][1];
value[i].index = i;
}
Arrays.sort(value);
for(int j = 0; j < k; j++) {
sum+=value[n-j-1].pow;
ans[j] = value[n-j-1].index;
}
return sum>=0;
}
}
class SZ implements Comparable{
double pow;
int index;
public int compareTo(Object o) {
if(this.pow>((SZ)o).pow)
return 1;
else if(this.pow<((SZ)o).pow)
return -1;
else
return 0;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator