Ant Counting POJ-2437

Farmer John has a problem: the dirt road from his farm to town has suffered in the recent rainstorms and now contains (1 <= N <= 10,000) mud pools. 

Farmer John has a collection of wooden planks of length L that he can use to bridge these mud pools. He can overlap planks and the ends do not need to be anchored on the ground. However, he must cover each pool completely. 

Given the mud pools, help FJ figure out the minimum number of planks he needs in order to completely cover all the mud pools.
Input
* Line 1: Two space-separated integers: N and L 

* Lines 2..N+1: Line i+1 contains two space-separated integers: s_i and e_i (0 <= s_i < e_i <= 1,000,000,000) that specify the start and end points of a mud pool along the road. The mud pools will not overlap. These numbers specify points, so a mud pool from 35 to 39 can be covered by a single board of length 4. Mud pools at (3,6) and (6,9) are not considered to overlap. 
Output
* Line 1: The miminum number of planks FJ needs to use.
Sample Input
3 3
1 6
13 17
8 12
Sample Output
5
Hint
INPUT DETAILS: 

FJ needs to use planks of length 3 to cover 3 mud pools. The mud pools cover regions 1 to 6, 8 to 12, and 13 to 17. 

OUTPUT DETAILS: 

FJ can cover the mud pools with five planks of length 3 in the following way: 
                   111222..333444555....

                   .MMMMM..MMMM.MMMM....

                   012345678901234567890

     这个题挺有意思的,没有用到什么算法,就算是单纯的找找规律,不算麻烦。题意是:一条路(坐标轴)上给你n个坑,给坑的起点s_i和 终点e_i,然后给L长的木板,可无缝起来的那种,问走过所有的坑最少用多少木板搭路。

      也幸亏有着下面的一个图解,对着比划一下,规律就出来了,不过说也不好形容,在代码里面体现吧。

代码如下:

#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
struct Node
{
    int s,e,len;
}node[10010];
int cmp(const Node &a,const Node &b)
{
    if(a.s<b.s)
        return 1;
    return 0;
}
int main()
{
    int N,L;
    while(~scanf("%d%d",&N,&L) && N && L)
    {
        for(int i=1; i<=N; i++)
        {
            scanf("%d%d",&node[i].s,&node[i].e);
            //cin>>node[i].s>>node[i].e;
            node[i].len=node[i].e-node[i].s;
        }
        sort(node+1,node+N+1,cmp);
        int flag=0;
        long long sum=0;
        int cnt=0;
        int temp1=0,temp2=0;
        for(int i=1; i<=N; i++)
        {
            cnt=(node[i].len-flag+L-1)/L;
            sum+=cnt;
            temp1=node[i].s+L*cnt+flag;
            temp2=temp1-node[i+1].s;
            if(temp1>node[i+1].s)
            {
                flag=temp2;
            }
            else if(temp1<node[i+1].s && temp2>L/2)
            {
                flag=temp2;
            }
            else
            {
                flag=0;
            }
        }
        printf("%I64d\n",sum);
        //cout<<sum<<endl;
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
boosting-crowd-counting-via-multifaceted-attention是一种通过多方面注意力提升人群计数的方法。该方法利用了多个方面的特征来准确估计人群数量。 在传统的人群计数方法中,往往只关注人群的整体特征,而忽略了不同区域的细节。然而,不同区域之间的人群密度可能存在差异,因此细致地分析这些区域是非常重要的。 该方法首先利用卷积神经网络(CNN)提取图像的特征。然后,通过引入多个注意力机制,分别关注图像的局部细节、稀疏区域和密集区域。 首先,该方法引入了局部注意力机制,通过对图像的局部区域进行加权来捕捉人群的局部特征。这使得网络能够更好地适应不同区域的密度变化。 其次,该方法采用了稀疏区域注意力机制,它能够识别图像中的稀疏区域并将更多的注意力放在这些区域上。这是因为稀疏区域往往是需要重点关注的区域,因为它们可能包含有人群密度的极端变化。 最后,该方法还引入了密集区域注意力机制,通过提取图像中人群密集的区域,并将更多的注意力放在这些区域上来准确估计人群数量。 综上所述,boosting-crowd-counting-via-multifaceted-attention是一种通过引入多个注意力机制来提高人群计数的方法。它能够从不同方面细致地分析图像,并利用局部、稀疏和密集区域的特征来准确估计人群数量。这个方法通过考虑人群分布的细节,提供了更精确的人群计数结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值