国产探花免费观看_亚洲丰满少妇自慰呻吟_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])
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安溪县| 阿图什市| 鹿泉市| 汉沽区| 临高县| 澜沧| 泸州市| 肥西县| 北流市| 于田县| 寻甸| 洪雅县| 高州市| 邛崃市| 进贤县| 枣庄市| 鹤山市| 射阳县| 桃园县| 洞口县| 岳池县| 武强县| 鹤壁市| 汉阴县| 永吉县| 黄石市| 西贡区| 平遥县| 青铜峡市| 秀山| 务川| 英德市| 蒲江县| 林州市| 定州市| 东源县| 简阳市| 兴文县| 东莞市| 罗源县| 民县|