我的思路是使用一个数组存放我是否放了树,每次增加区间就将该数组重置为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; }
点赞 1
正在热议
更多
牛客网
牛客企业服务