• 二分(结果向下取整)


    http://poj.org/problem?id=1064

    题意:给出n(1 <= n <= 10000)段绳子,将这些绳子切成k(1 <= k <= 10000)段相同的长度,问k最长为多少?

    输入数据以米为单位,精度为厘米。

    解法:二分长度,判断是否满足条件。

    注意最后输出时,要对答案进行向下取整,避免四舍五入。

    //#include<bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <iostream>
    #include <string>
    #include <stdio.h>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <string.h>
    #include <vector>
    typedef long long ll ;
    #define int ll
    #define mod 1000000007
    #define gcd __gcd
    #define rep(i , j , n) for(int i = j ; i <= n ; i++)
    #define red(i , n , j)  for(int i = n ; i >= j ; i--)
    #define ME(x , y) memset(x , y , sizeof(x))
    //ll lcm(ll a , ll b){return a*b/gcd(a,b);}
    //ll quickpow(ll a , ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;b>>=1,a=a*a%mod;}return ans;}
    //int euler1(int x){int ans=x;for(int i=2;i*i<=x;i++)if(x%i==0){ans-=ans/i;while(x%i==0)x/=i;}if(x>1)ans-=ans/x;return ans;}
    //const int N = 1e7+9; int vis[n],prime[n],phi[N];int euler2(int n){ME(vis,true);int len=1;rep(i,2,n){if(vis[i]){prime[len++]=i,phi[i]=i-1;}for(int j=1;j<len&&prime[j]*i<=n;j++){vis[i*prime[j]]=0;if(i%prime[j]==0){phi[i*prime[j]]=phi[i]*prime[j];break;}else{phi[i*prime[j]]=phi[i]*phi[prime[j]];}}}return len}
    #define INF  0x3f3f3f3f
    #define PI acos(-1)
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define lson l,mid,root<<1
    #define rson mid+1,r,root<<1|1
    #define pb push_back
    #define mp make_pair
    #define cin(x) scanf("%lld" , &x);
    using namespace std;
    const int N = 1e7+9;
    const int maxn = 1e5+9;
    const double esp = 1e-2;
    int n , k ;
    double a[maxn];
    bool check(double x){
        int ans = 0 ;
        rep(i , 1 , n){
            ans += (int)(a[i] / x);
        }
        return ans >= k ;
    }
    void solve(){
        //cin >> n >> k ;
        rep(i , 1 , n){
            scanf("%lf" , &a[i]);
        }
        double l = 0 , r = 1e9;
        for(int i = 0 ; i < 200 ; i++){
            double mid = (l + r) / 2 ;
            if(check(mid)){
                l = mid ;
            }else{
                r = mid ;
            }
        }
        printf("%.2f
    " , floor(l*100)/100);
    }
    
    signed main()
    {
        //ios::sync_with_stdio(false);
        //cin.tie(0); cout.tie(0);
        //int t ;
        //cin(t);
        //while(t--){
        while(~scanf("%lld%lld" , &n , &k))
            solve();
        //}
    }
    
  • 相关阅读:
    P3973 [TJOI2015]线性代数
    P3168 [CQOI2015]任务查询系统
    二次剩余学习笔记
    URL注入攻击+知识星球资源整理
    我的网络安全架构知识点的总结(待完善)
    Sudo提权
    DNSlog平台各种利用姿势(盲注)
    Wireshark抓包理论加实操
    Fofa搜索技巧(理论加实践的整理)
    Windows留后门维持权限(其中包括详细的telnet改端口与连接)
  • 原文地址:https://www.cnblogs.com/nonames/p/12463865.html
Copyright © 2020-2023  润新知