|
发表于 2023-12-1 14:06:51
|
显示全部楼层
本楼为最佳答案
代码实现如下
- #include <iostream>
- #include <stdio.h>
- #include <vector>
- #include <stdbool.h>
- using namespace std;
- int main(int argc, char const *argv[])
- {
- int N,K,stand = 0;
- cin >> N >> K;
- vector<float> lengths(N);
- float all_len = 0;
- float short_len = 0;
- float standlen = 0;
- bool flag = true;
- for (int i = 0; i < N; i++) {
- cin >> lengths[i];
- all_len += lengths[i];
- if(short_len > lengths[i] || short_len <= 0)
- {
- short_len = lengths[i];
- }
-
- }
- if(all_len/K > short_len)
- {
- standlen = short_len;
- }
- else
- {
- standlen = all_len/K;
- }
- while ((stand < K)&&(standlen >= 0))
- {
- stand = 0;
- for (int i = 0; i < N; i++)
- {
- stand += lengths[i]/standlen;
- }
- standlen -= 0.01;
- }
- if(stand >= K)
- {
- printf("%0.2f\n",standlen+0.01);
- }
- else
- {
- printf("0.00\n");
- }
-
- return 0;
- }
复制代码 |
|