POJ3069
讨论版里说是贪心大水题...思路看书明白了,可是实现的时候感觉心有余而力不足,bug满天飞,调了半个小时还没调完,明天再调吧(如果明天还能过来的话)
#include<iostream>
#include<stack>
#include<queue>
#include<cstring>
#include<string>
#include<algorithm>
//不清楚这上下那个在前面
const int INF = 0x3f3f3f3f;
using namespace std;
int n,shoot;
int x[1005];
int ans=0;
void solve()
{
sort(x+1,x+n+1);
int num=1,choice=1;
ans=0;
x[n+1]=INF;//在边界处修修补补
while(num<=n)
{
/*if(choice==n)
{
ans++;
break;
}*///尝试用这种方式防止choice溢出,先入为主地认为最后一个点被前面所包围。实际上有可能是单独于前面之外的.bug
if(x[choice]-x[num]<=shoot)//条件忘记用了.浅层bug
{
choice++;
}
else
{
ans++;
//num=choice;
num=choice-1;//最后一个bug,向后照射的时候应该是以前面的最后一个人来计算,而不是往后跳跃
while(x[choice]-x[num]<=shoot)
{
choice++;
}
num=choice;
}
//忽略了探照灯也是能往后照射的.bug
cout<<"the_motherfucker_num:"<<x[num]<<endl<<"the_motherfucker_choice"<<x[choice]<<endl;//输出调试
}
cout<<ans<<endl;
}
int main()
{
while(true)
{
cin>>shoot>>n;
if(shoot<0||n<0)//maybe bug
{
break;
}
for(int i=1;i<=n;i++)
{
cin>>x[i];
}
solve();
}
return 0;
}