【无标题】

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;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值