| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 864 人关注过本帖
标题:帮忙看看,这个数据都对的,怎么又错了呢?
取消只看楼主 加入收藏
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
结帖率:73.91%
收藏
已结贴  问题点数:18 回复次数:0 
帮忙看看,这个数据都对的,怎么又错了呢?
Control Points

Time Limit:1000MS  Memory Limit:65536K
Total Submit:59 Accepted:20

Description

Joe is a skilled programmer. The management of the highway police division wants to control the traffic on the highway, and hired him to solve the following problem. There are some fixed control points on the highway. The highway police division wants to place specialized devices to record information from all the control points. Such a device is very expensive and unfortunately can cover an interval of only one meter (including the left endpoint and excluding the right endpoint). The management wants to place the minimum number of devices to cover all the control points. Joe must find an efficient solution.

Input

The program input is from a text file. Each data set in the file stands for a particular configuration of control points. A data set starts with the number n (n <= 100000) – the number of control points, followed by the real values in ascending order describing the coordinates of the control points (the highway is considered a real line). The coordinates are expressed in meters.
White spaces can occur freely in the input. The input data terminate with an end of file.

Output

For each set of data the program has to print the minimum number of devices needed to cover all the control points to the standard output.
An input/output sample is in the table bellow. There are two data sets. In the first case, there are 2 points: 3.56 and 4. Only one device is needed.

Sample Input


2
3.56 4
3
1 2 2.9
Sample Output


1
2


#include<stdio.h>
const int maxn=100020;
float num[maxn];
int main()
{
    int n;
    int i,j,s;
    float k;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
        {
            printf("0\n");
            continue;
        }
        for(i=1;i<=n;i++)
        {
            scanf("%f",&num[i]);
        }
        k=num[1];
        j=1;
        for(i=2;i<=n;i++)
        {
            if(num[i]>=k+1)
            {
                j++;
                k=num[i];
            }
        }
        k=num[n];
        s=1;
        for(i=n-1;i>=1;i--)
        {
            if(num[i]<=k-1)
            {
                s++;
                k=num[i];
            }
        }
        if(j>s)
        printf("%d\n",s);
        else
        printf("%d\n",j);
    }
    return 0;
}
搜索更多相关主题的帖子: police management following control 
2011-08-22 13:39
快速回复:帮忙看看,这个数据都对的,怎么又错了呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011876 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved