#牛客在线求职答疑中心#长度无限长的公路上,小美雇佣了n位工人来种树,每个点最多种一棵树。
全部评论
求解答
点赞 回复 分享
发布于 2024-08-31 20:38 安徽
蹲一个解答
点赞 回复 分享
发布于 2024-08-31 20:53 江苏
result=k/n 先获得一个比较接近的数,然后判断与k的大小进行++和--,但是最后测试用例只通过了90%
点赞 回复 分享
发布于 2024-08-31 20:55 安徽
我的思路是使用一个数组存放我是否放了树,每次增加区间就将该数组重置为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; }
点赞 回复 分享
发布于 2024-08-31 20:58 四川

相关推荐

起名字真难233:人家只有找猴子的预算,来个齐天大圣他们驾驭不住呀😂😂
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客企业服务