poj-2976 Dropping tests

呂振麒 bio photo By 呂振麒 Comment

傳送門:

Dropping tests

思路:

這題 相似,換湯不換藥,參考一下即可。

code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
int N,K;
double eps = 1e-3;
ll sa[1005], sb[1005];
long double sorting[1005];
void init(){
  for(int i=0;i<N;i++)
    sa[i] = getint() * 100;
  for(int i=0;i<N;i++)
    sb[i] = getint();
}
inline bool suc(long double x){
  long double cnt = 0.0;
  for(int i=0;i<N;i++)
    sorting[i] = (long double)sa[i] - x*sb[i];
  sort(sorting, sorting+N, greater<long double>());
  for(int i=0;i<N-K;i++) cnt += sorting[i];
  return cnt > -eps;
}
int sol(){
  long double L = 0.0, R = 101;
#define mid ((L+R)/2)
  while(R-L>eps) suc(mid) ? L=mid : R=mid;
  return int(L+0.5);
}
int main(){
  while(cin >> N >> K && N+K){
    init();
    cout << sol() << endl;
  }
}
comments powered by Disqus