B - Cable master

本文介绍了一个关于电缆切割的问题,旨在找出从给定数量和长度的电缆中切割出尽可能多的等长段的方法。通过使用二分查找算法,文章提供了一种高效的解决方案。

B - Cable master

Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit

Status
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 input consists of several testcases. The first line of each testcase contains two integer numbers 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 centimeter and at most 100 kilometers in length. All lengths in the input are written with a centimeter precision, with exactly two digits after a decimal point.

The input is ended by line containing two 0’s.

Output
For each testcase write to the output 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 must contain the single number “0.00” (without quotes).

Sample Input
4 11
8.02
7.43
4.57
5.39
0 0

Sample Output
2.00


#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define eps 1e-3//不用这个超时 

const int MAX = 1*1e7+10;
int n,k;
double a[MAX];

int   judge(double mid)
{
     int sum=0,i;
     for(i=1;i<=n;++i)
     {
        sum+=(int)(a[i]/mid);
     }
     return sum;
}  


int main()
{
    int cnt;
    double l,r,mid;

    while(cin>>n>>k,n||k)
    {
        for(int i=1;i<=n;++i)
        {
            cin>>a[i];
        }

        l=0.0;
        r=100000.0;
        cnt=100;
        while(r-l>eps)
        {
            mid=(l+r)/2.0;
            if(k>judge(mid))//最大值为啥
            {
                r=mid;
            }
            else
            {
                l=mid;
            }
        } 
        printf("%.2lf\n",mid);
    }
 } 
PS E:\rubyProject\student_curd> bundle exec rails server Usage: rails new APP_PATH [options] Options: [--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated engines) [--skip-collision-check], [--no-skip-collision-check] # Skip collision check -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: E:/Bitnami/redmine-5.0.3-0/ruby/bin/ruby.exe -m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) # Default: sqlite3 [--skip-gemfile], [--no-skip-gemfile] # Don't create a Gemfile -G, [--skip-git], [--no-skip-git] # Skip .gitignore file [--skip-keeps], [--no-skip-keeps] # Skip source control .keep files -M, [--skip-action-mailer], [--no-skip-action-mailer] # Skip Action Mailer files [--skip-action-mailbox], [--no-skip-action-mailbox] # Skip Action Mailbox gem [--skip-action-text], [--no-skip-action-text] # Skip Action Text gem -O, [--skip-active-record], [--no-skip-active-record] # Skip Active Record files [--skip-active-job], [--no-skip-active-job] # Skip Active Job [--skip-active-storage], [--no-skip-active-storage] # Skip Active Storage files -P, [--skip-puma], [--no-skip-puma] # Skip Puma related files -C, [--skip-action-cable], [--no-skip-action-cable] # Skip Action Cable files -S, [--skip-sprockets], [--no-skip-sprockets] # Skip Sprockets files [--skip-spring], [--no-skip-spring] # Don't install Spring application preloader [--skip-listen], [--no-skip-listen] # Don't generate configuration that depends on the listen gem -J, [--skip-javascript], [--no-skip-javascript] # Skip JavaScript files [--skip-turbolinks], [--no-skip-turbolinks] # Skip turbolinks gem [--skip-jbuilder], [--no-skip-jbuilder] # Skip jbuilder gem -T, [--skip-test], [--no-skip-test] # Skip test files [--skip-system-test], [--no-skip-system-test] # Skip system test files [--skip-bootsnap], [--no-skip-bootsnap] # Skip bootsnap gem [--dev], [--no-dev] # Set up the application with Gemfile pointing to your Rails checkout [--edge], [--no-edge] # Set up the application with Gemfile pointing to Rails repository [--master], [--no-master] # Set up the application with Gemfile pointing to Rails repository main branch [--rc=RC] # Path to file containing extra configuration options for rails command [--no-rc], [--no-no-rc] # Skip loading of extra configuration options from .railsrc file [--api], [--no-api] # Preconfigure smaller stack for API only apps [--minimal], [--no-minimal] # Preconfigure a minimal rails app -B, [--skip-bundle], [--no-skip-bundle] # Don't run bundle install --webpacker, [--webpack=WEBPACK] # Preconfigure Webpack with a particular framework (options: react, vue, angular, elm, stimulus) [--skip-webpack-install], [--no-skip-webpack-install] # Don't run Webpack install Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist Rails options: -h, [--help], [--no-help] # Show this help message and quit -v, [--version], [--no-version] # Show Rails version number and quit Description: The 'rails new' command creates a new Rails application with a default directory structure and configuration at the path you specify. You can specify extra command-line arguments to be used every time 'rails new' runs in the .railsrc configuration file in your home directory, or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set. Note that the arguments specified in the .railsrc file don't affect the defaults values shown above in this help message. Example: rails new ~/Code/Ruby/weblog This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
09-09
Usage: rails new APP_PATH [options] Options: [--skip-namespace] # Skip namespace (affects only isolated engines) # Default: false [--skip-collision-check] # Skip collision check # Default: false -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: C:/Ruby34-x64/bin/ruby.exe -n, [--name=NAME] # Name of the app -m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) -d, [--database=DATABASE] # Preconfigure for selected database # Default: sqlite3 # Possible values: mysql, trilogy, postgresql, sqlite3, mariadb-mysql, mariadb-trilogy -G, [--skip-git] # Skip git init, .gitignore and .gitattributes [--skip-docker] # Skip Dockerfile, .dockerignore and bin/docker-entrypoint [--skip-keeps] # Skip source control .keep files -M, [--skip-action-mailer] # Skip Action Mailer files [--skip-action-mailbox] # Skip Action Mailbox gem [--skip-action-text] # Skip Action Text gem -O, [--skip-active-record] # Skip Active Record files [--skip-active-job] # Skip Active Job [--skip-active-storage] # Skip Active Storage files -C, [--skip-action-cable] # Skip Action Cable files -A, [--skip-asset-pipeline] # Skip the asset pipeline setup -J, --skip-js, [--skip-javascript] # Skip JavaScript files [--skip-hotwire] # Skip Hotwire integration [--skip-jbuilder] # Skip jbuilder gem -T, [--skip-test] # Skip test files [--skip-system-test] # Skip system test files [--skip-bootsnap] # Skip bootsnap gem [--skip-dev-gems] # Skip development gems (e.g., web-console) [--skip-thruster] # Skip Thruster setup [--skip-rubocop] # Skip RuboCop setup [--skip-brakeman] # Skip brakeman setup [--skip-bundler-audit] # Skip bundler-audit setup [--skip-ci] # Skip GitHub CI files [--skip-kamal] # Skip Kamal setup [--skip-solid] # Skip Solid Cache, Queue, and Cable setup [--dev], [--no-dev], [--skip-dev] # Set up the application with Gemfile pointing to your Rails checkout [--devcontainer], [--no-devcontainer], [--skip-devcontainer] # Generate devcontainer files [--edge], [--no-edge], [--skip-edge] # Set up the application with a Gemfile pointing to the 8-1-stable branch on the Rails repository --master, [--main], [--no-main], [--skip-main] # Set up the application with Gemfile pointing to Rails repository main branch [--rc=RC] # Path to file containing extra configuration options for rails command [--no-rc] # Skip loading of extra configuration options from .railsrc file [--api], [--no-api], [--skip-api] # Preconfigure smaller stack for API only apps # Default: false [--minimal], [--no-minimal], [--skip-minimal] # Preconfigure a minimal rails app -j, --js, [--javascript=JAVASCRIPT] # Choose JavaScript approach # Default: importmap # Possible values: importmap, bun, webpack, esbuild, rollup -c, [--css=CSS] # Choose CSS processor. Check https://github.com/rails/cssbundling-rails for more options # Possible values: tailwind, bootstrap, bulma, postcss, sass -B, [--skip-bundle] # Don't run bundle install [--skip-decrypted-diffs] # Don't configure git to show decrypted diffs of encrypted credentials Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend], [--skip-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet], [--skip-quiet] # Suppress status output -s, [--skip], [--no-skip], [--skip-skip] # Skip files that already exist Rails options: -h, [--help], [--no-help], [--skip-help] # Show this help message and quit -v, [--version], [--no-version], [--skip-version] # Show Rails version number and quit Description: The `rails new` command creates a new Rails application with a default directory structure and configuration at the path you specify. You can specify extra command-line arguments to be used every time `rails new` runs in the .railsrc configuration file in your home directory, or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set. Note that the arguments specified in the .railsrc file don't affect the default values shown above in this help message. You can specify which version to use when creating a new rails application using `rails _<version>_ new`. Examples: `rails new ~/Code/Ruby/weblog` This generates a new Rails app in ~/Code/Ruby/weblog. `rails _<version>_ new weblog` This generates a new Rails app with the provided version in ./weblog. `rails new weblog --api` This generates a new Rails app in API mode in ./weblog. `rails new weblog --skip-action-mailer` This generates a new Rails app without Action Mailer in ./weblog. Any part of Rails can be skipped during app generation.
最新发布
11-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值