1 条题解

  • 0
    @ 2023-6-11 12:17:08

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    int len[100]; // 绳子长度
    int n,m,i,lbound,ubound,mid;
    
    int main() { 
       cin>>n; 
       int count = 0;
       for (i = 0; i < n; i++) { 
           cin>>len[i];
           count = count + len[i];
       }
       
       cin>>m;
       if (count < m) {
          cout<<"Failed"<<endl;
    	  return 0;
       }
       
       lbound = 1;
       ubound = 1000000;
       while (lbound < ubound) {
           mid = (lbound + ubound + 1) / 2;
    	   count = 0;
    	   for (i = 0; i < n; i++)
    	      count = count + len[i] / mid;
    	   if (count < m) 
    	      ubound = mid - 1; 
    	   else
    	      lbound = mid;
       }
       cout<<lbound<<endl; 
       
       return 0;
    }
    
    

    Python :

    n=int(input())
    a=[]
    sr=input().split()
    for i in range(n):
        a.append(int(sr[i]))
    a=sorted(a)
    a.reverse()
    m=int(input())
    da=a[0]
    while(da>=1):
        s=0
        for i in range(n):
            s=s+a[i]//da
        if(s>=m):
            break
        else:
            da=da-1
    if(da>=1):
        print(da)
    else:
        print("Failed")
    
    • 1

    信息

    ID
    2333
    时间
    1000ms
    内存
    16MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者