#牛客在线求职答疑中心#长度无限长的公路上,小美雇佣了n位工人来种树,每个点最多种一棵树。
全部评论
求解答
蹲一个解答
result=k/n 先获得一个比较接近的数,然后判断与k的大小进行++和--,但是最后测试用例只通过了90%
我的思路是使用一个数组存放我是否放了树,每次增加区间就将该数组重置为0,但是最后结果不对,不能理解
#include <iostream>
(30316)#include<algorithm>
#include<vector>
using namespace std;
int main() {
int people=0,tree=0;
cin>>people>>tree;
vector<int>location(people,0);
for(int i=0;i<people;i++){
cin>>location[i];
}
int needspace=1;
vector<int>tongjitree(location[people-1]+tree,0);
while (true)
{
fill(tongjitree.begin(),tongjitree.end(),0);
for(int k=0;k<people;k++){
for(int m=1;m<needspace;m++){
tongjitree[location[k]+m]=1;
}
}
int getsize=0;
for(int l=0;l<location[people-1]+tree;l++){
if(tongjitree[l]==1){
getsize++;
}
}
if(getsize>=0){
break;
}
needspace++;
}
cout<<needspace;
}
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享