国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

POJ3111-K Best-最大化平均值

2019-11-08 18:30:14
字體:
來源:轉載
供稿:網友

原題鏈接 K Best Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 9788 Accepted: 2510 Case Time Limit: 2000MS Special Judge Description

Demy has n jewels. Each of her jewels has some value vi and weight wi.

Since her husband John got broke after recent financial crises, Demy has decided to sell some jewels. She has decided that she would keep k best jewels for herself. She decided to keep such jewels that their specific value is as large as possible. That is, denote the specific value of some set of jewels S = {i1, i2, …, ik} as

.

Demy would like to select such k jewels that their specific value is maximal possible. Help her to do so.

Input

The first line of the input file contains n — the number of jewels Demy got, and k — the number of jewels she would like to keep (1 ≤ k ≤ n ≤ 100 000).

The following n lines contain two integer numbers each — vi and wi (0 ≤ vi ≤ 106, 1 ≤ wi ≤ 106, both the sum of all vi and the sum of all wi do not exceed 107).

Output

Output k numbers — the numbers of jewels Demy must keep. If there are several solutions, output any one.

Sample Input

3 2 1 1 1 2 1 3 Sample Output

1 2 Source

Northeastern Europe 2005, Northern Subregion 題意:從n個寶石中找出加權平均數最大的k個數 思路:二分該加權平均數

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double EPS = 1.0e-5;const double INF = 10000010.0;const int maxn = 1e5 + 10;int v[maxn],w[maxn],n,k;pair<double,int> c[maxn];bool used[maxn];bool _can(double x){ memset(used,false,sizeof(used)); for(int i=1;i<=n;i++){ c[i].first = v[i] - x*w[i]; c[i].second = i; } sort(c+1,c+n+1); double sum = 0; for(int i=n-k+1;i<=n;i++){ sum += c[i].first; used[c[i].second]=true; } return sum>=0.0;}int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) scanf("%d%d",&v[i],&w[i]); double l=0,r=INF; while(r-l>EPS){//這里的平均數可不是一個整數,而且我們需要一定的精度,注意不用while而用for循環100次會超時 double mid = (l+r)/2; if(_can(mid)) l=mid; else r=mid; } for(int i=1;i<=n;i++) if(used[i])
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杭锦旗| 红河县| 乳源| 固镇县| 城口县| 牟定县| 马边| 阜宁县| 平安县| 天祝| 静海县| 万源市| 明光市| 双辽市| 化州市| 宜都市| 珲春市| 芜湖县| 上林县| 双江| 辰溪县| 奎屯市| 和龙市| 濉溪县| 文安县| 六安市| 望城县| 郁南县| 社旗县| 德兴市| 乐清市| 正镶白旗| 新昌县| 纳雍县| 许昌市| 潞城市| 苏尼特左旗| 长葛市| 泸溪县| 淮阳县| 定襄县|