日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 1064 -- Cable master(二分)

發布時間:2024/4/18 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 1064 -- Cable master(二分) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接

Description

Inhabitants 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.

Input

The 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.

Output

Write 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 Input

4 11 8.02 7.43 4.57 5.39

Sample Output

2.00

AC

  • 二分枚舉
  • 精度問題:可以轉化為整數,也可以直接用小數
  • 小數
#include <iostream> #include <stdio.h> #include <map> #include <vector> #include <queue> #include <algorithm> #include <cmath> #define N 10005 #define ll long long #define P pair<int, int> #define mk make_pair using namespace std;double a[N]; int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin); #endifint n, m;while (scanf("%d%d", &n, &m) != EOF) {for (int i = 0; i < n; ++i) {scanf("%lf", &a[i]);} double l = 0, r = 100005;while ((r - l) > 1e-9) {double mid = (l + r) / 2.0;int sum = 0;for (int i = 0; i < n; ++i) {sum += a[i] / mid;}if (sum >= m) l = mid;else r = mid;}// 這里要輸出右區間,具體不太清楚。printf("%.2f\n", floor(r * 100) / 100.0);}return 0; }
  • 整數
#include <iostream> #include <stdio.h> #include <map> #include <vector> #include <queue> #include <algorithm> #include <cmath> #define N 10005 #define ll long long #define P pair<int, int> #define mk make_pair using namespace std;int a[N]; int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin); #endifint n, m;while (scanf("%d%d", &n, &m) != EOF) {for (int i = 0; i < n; ++i) {double len;scanf("%lf", &len);a[i] = len * 100;} int l = 1, r = 10000500;while (l <= r) {int mid = (l + r) >> 1;int sum = 0;for (int i = 0; i < n; ++i) {sum += a[i] / mid;}if (sum >= m) l = mid + 1;else r = mid - 1;}printf("%.2f\n", double(r) / 100);}return 0; }

總結

以上是生活随笔為你收集整理的POJ 1064 -- Cable master(二分)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。