| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 864 人关注过本帖
标题:帮忙看看,这个数据都对的,怎么又错了呢?
只看楼主 加入收藏
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
结帖率:73.91%
收藏
已结贴  问题点数:18 回复次数:4 
帮忙看看,这个数据都对的,怎么又错了呢?
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
hjywyj
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:3
帖 子:1114
专家分:2611
注 册:2010-4-14
收藏
得分:0 
阁下的英语很厉害,我还是继续学习吧
2011-08-22 13:47
voidx
Rank: 12Rank: 12Rank: 12
来 自:邯郸
等 级:火箭侠
帖 子:1250
专家分:3538
注 册:2011-4-7
收藏
得分:0 
精度问题吧。
而且,根本没必要用数组吧
2011-08-22 13:49
wicky
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-8-22
收藏
得分:0 
不是很理解你的题目……
2011-08-23 00:02
A13433758072
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:广东潮州
等 级:小飞侠
威 望:1
帖 子:1182
专家分:2784
注 册:2010-7-22
收藏
得分:18 
回复 楼主 枫叶无痕
for(i=n不知对不;i>=1;i--)

[ 本帖最后由 A13433758072 于 2011-8-23 11:16 编辑 ]

一步一个脚印...............................默默地前进.....
诚邀乐于解答c菜鸟问题,的热心网友加入,  QQ群38490319
2011-08-23 11:05
快速回复:帮忙看看,这个数据都对的,怎么又错了呢?
数据加载中...
 
   



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

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