(poj)1064 Cable master 二分+精度

題目鏈接:http://poj.org/problem?id=1064

DescriptionInhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants using a "star" topology - i.e. connect them all to a single central hub. To organize a truly honest contest, the Head of the Judging Committee has decreed to place all contestants evenly around the hub on an equal distance from it. 
To buy network cables, the Judging Committee has contacted a local network solutions provider with a request to sell for them a specified number of cables with equal lengths. The Judging Committee wants the cables to be as long as possible to sit contestants as far from each other as possible. 
The Cable Master of the company was assigned to the task. He knows the length of each cable in the stock up to a centimeter,and he can cut them with a centimeter precision being told the length of the pieces he must cut. However, this time, the length is not known and the Cable Master is completely puzzled. 
You are to help the Cable Master, by writing a program that will determine the maximal possible length of a cable piece that can be cut from the cables in the stock, to get the specified number of pieces.
InputThe first line of the input file contains two integer numb ers N and K, separated by a space. N (1 = N = 10000) is the number of cables in the stock, and K (1 = K = 10000) is the number of requested pieces. The first line is followed by N lines with one number per line, that specify the length of each cable in the stock in meters. All cables are at least 1 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two digits after a decimal point.
OutputWrite to the output file the maximal length (in meters) of the pieces that Cable Master may cut from the cables in the stock to get the requested number of pieces. The number must be written with a centimeter precision, with exactly two digits after a decimal point. 
If it is not possible to cut the requested number of pieces each one being at least one centimeter long, then the output file must contain the single number "0.00" (without quotes).
Sample Input4 11
8.02
7.43
4.57
5.39
Sample Output2.00

題意:有N個棍可截取,問截取k個等長的棍的最大長度 如果小于0.01輸出0.00

方法:把最長的二分,但是需要考慮精度問題,可以吧二分的范圍都乘以100,去掉精度誤差

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define N 10010
#define INF 0x3f3f3f3f
#define ll long long
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
double a[N];
int main()
{int n,m;double maxx;while(scanf("%d %d",&n,&m)!=EOF){maxx=-1;for(int i=0; i<n; i++){scanf("%lf",&a[i]);maxx=max(maxx,a[i]);}double l=0,r=maxx*100,ans=0;int mid;double mm;while(l<=r){mid=(l+r)/2;int sum=0;mm=(double)mid/100;for(int i=0; i<n; i++){sum+=(a[i]/mm);}if(sum<m)r=mid-1;else{l=mid+1;ans=mid;}}ans/=100;if(ans<0.01)printf("0.00\n");elseprintf("%.2f\n",ans);}return 0;
}

?

轉載于:https://www.cnblogs.com/jun939026567/p/5788961.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/395272.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395272.shtml
英文地址,請注明出處:http://en.pswp.cn/news/395272.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

PHP中如何解決高并發

PHP中如何解決高并發 1&#xff1a;硬件方面 普通的一個p4的服務器每天最多能支持大約10萬左右的IP&#xff0c;如果訪問量超過10W那么需要專用的服務器才能解決&#xff0c;如果硬件不給力 軟件怎么優化都是于事無補的。主要影響服務器的速度 有&#xff1a;網絡-硬盤讀寫速度…

es6 迭代器_揭秘ES6迭代器和迭代器

es6 迭代器by Tiago Lopes Ferreira由Tiago Lopes Ferreira 揭秘ES6迭代器和迭代器 (Demystifying ES6 Iterables & Iterators) ES6 introduces a new way to interact with JavaScript data structures — iteration. Let’s demystify it.ES6引入了一種與JavaScript數據…

JS之this與語句分號問題v(**V**)v

1 <script >2 //this知識 單詞知識&#xff1a;property&#xff1a;屬性 prototype&#xff1a;原型3 //*Q&#xff1a;什么是this&#xff1f;4 //*A&#xff1a;所有函數內部都有一個this&#xff0c;任何函數本質上都是通過某個對象來調用的&#xff0c;…

計算機聯系函范文,致客戶聯絡函

致客戶聯絡函 相關內容:收到貴支部所發的“函調證明”通知&#xff0c;很高興我校畢業生xxx同學能成為貴支部的黨員發展對象&#xff0c;現對其在我校上學其間的表現證明如下&#xff1a;xxx&#xff0c;女&#xff0c;xxx年7月28日生&#xff0c;團員&#xff0c;XX年8月——X…

c語言堆棧基本代碼入棧出棧_c語言的簡單的進棧出棧

這個代碼運行時只能輸入4個以內的數有輸出4個以上就沒有輸出了求大神看看#include#include#defineStack_Size50typedefstructSeqstack{intelem[Stack_Size];inttop...這個代碼運行時只能輸入4個以內的數有輸出 4個以上就沒有輸出了 求大神看看 #include #include #define Stack…

P1401 城市(30分,正解網絡流)

題目描述 N(2<n<200)個城市&#xff0c;M(1<m<40000)條無向邊&#xff0c;你要找T(1<T<200)條從城市1到城市N的路&#xff0c;使得最長的邊的長度最小&#xff0c;邊不能重復用。 輸入輸出格式 輸入格式&#xff1a; 第1行三個整數N,M,T用空格隔開。 第2行到…

sqlserver游標概念與實例全面解說

引言 我們先不講游標的什么概念&#xff0c;步驟及語法&#xff0c;先來看一個例子&#xff1a; 表一 OriginSalary 表二 AddSalary 現在有2張表&#xff0c;一張是OriginSalary表--工資表&#xff0c;有三個字段0_ID 員工…

為什么Docker對初創企業有意義

by Charly Vega查理維加(Charly Vega) 為什么Docker對初創企業有意義 (Why Docker makes sense for startups) Docker is becoming the standard to develop and run containerized applications.Docker正在成為開發和運行容器化應用程序的標準。 Long ago, this piece of te…

MyEclipse中Maven Web項目部署路徑設置

轉載于:https://www.cnblogs.com/langzichanglu/p/10336805.html

小米電視聯網后顯示無法解析小米電視服務器,小米電視連上無線不能上網怎么回事?教你解決辦法...

原標題&#xff1a;小米電視連上無線不能上網怎么回事&#xff1f;教你解決辦法互聯網電視憑借在線觀看影視劇這個獨有的優勢受到越來越多家庭的喜愛。特別是配置不俗的小米電視&#xff0c;然而隨之而來的的問題也讓很多用戶頭疼&#xff0c;比如家里的小米電視突然上不了網了…

配置Server Side TAF

實驗環境&#xff1a;Oracle 11.2.0.4 RAC1.為設置TAF在RAC集群上新建服務2.啟動server_taf服務3.檢查確認服務正在運行4.找到剛創建服務的service_id5.根據service_id審查服務的信息6.給服務添加server side failover參數7.再次審查服務可以看到Method, Type和Retries值8.檢查…

fgets阻塞 stdin 退出_來自stdin問題的fgets[c]

我試過你的代碼,但無法重現問題。以下代碼的工作方式正是您所期望的,它會提示您輸入名稱,等待您鍵入名稱,然后提示您輸入地址,等等。我想知道你是否不需要在提示輸入更多信息之前閱讀stdin并清空它?typedef struct {char* name;char* address;}employeeRecord;int readrecord(…

2016.08.19

轉載于:https://www.cnblogs.com/hiramlee0534/p/5789453.html

服務器上運行arp,服務器ARP病毒的特征及防護說明

服務器ARP病毒的特征及防護說明更新時間&#xff1a;2008年01月29日 15:50:33 作者&#xff1a;服務器ARP病毒的特征及防護說明近期有些用戶反映服務器上所有網站被插入了病毒代碼,但是這些病毒代碼在服務器的源文件上并不能找到,因此,網管想清理病毒也無從下手,這是什么原因…

使用React Native進行氣泡動畫

by Narendra N Shetty由納倫德拉N謝蒂(Narendra N Shetty) 使用React Native進行氣泡動畫 (Bubble animation with React Native) 使用Animated和PanResponder構建React Native應用程序時獲得的經驗教訓 (Lessons learned while building a React Native App using Animated a…

Machine Learning from Start to Finish with Scikit-Learn

2019獨角獸企業重金招聘Python工程師標準>>> Machine Learning from Start to Finish with Scikit-Learn This notebook covers the basic Machine Learning process in Python step-by-step. Go from raw data to at least 78% accuracy on the Titanic Survivors …

Excel 宏編碼實現,指定列的字符串截取

1、打開Excel憑證&#xff0c;啟用宏&#xff0c;ALTF11 或 菜單“視圖”-"宏-查看宏" Sub 分割字符串1() Dim i As Integer Dim b() As String Dim length 用length表示數組的長度 Dim sublength Dim bb() As String 篩選日期 2 點 For i 2 To 20000 b() Split(Ce…

mysql for update 鎖_MySql FOR UPDATE 鎖的一點問題……

問題描述假設一個情況&#xff0c;這里只是假設&#xff0c;真實的情況可能不會這樣設計&#xff0c;但是假如真的發生了....鐵老大有一張這樣的ticket表&#xff0c;用來存放北京到上海的票。iduidstart_addrend_addrbook_time11300009860上海北京1386666032120上海北京30上海…

服務器機房新風系統,某機房新風系統設計方案參考

《某機房新風系統設計方案參考》由會員分享&#xff0c;可在線閱讀&#xff0c;更多相關《某機房新風系統設計方案參考(3頁珍藏版)》請在人人文庫網上搜索。1、某機房新風系統設計方案參考根據以上要求并結合中華人民共和國電子計算機機房的設計規范&#xff0c;為保證機房正壓…

css 畫三角形

CSS三角形繪制方法#triangle-up {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 100px solid red;}#triangle-down {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid trans…