首页 | 博客群 | 公社 | 专栏 | 论坛 | 图片 | 资讯 | 注册 | 帮助 | 博客联播 | 随机访问
外交部就我飞机在东海遭日本战机驱赶答问- -| 回首页 | 2005年索引 | - -1998年国航一航班机长劫机到台湾内幕

一道关于导弹拦截的C算法题解

关键词一道关于导弹拦截的C算法题解                                          

Question:

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭。由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹。

输入导弹依次飞来的高度(雷达给出的高度数据是不大于30000的正整数),计算这套系统最多能拦截多少导弹,如果要拦截所有导弹最少要配备多少套这种导弹拦截系统。

Answer:

适应UNICODE或是ANSI两种平台SDK题解。^_^ (注: baofeng是我初上网时的网名) 

/////////////////////////////////////////////////////////////////////////////////
//
// Answer for Question of the Missile
// by baofeng, 2005/10/14
//
/////////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

int main(void)
{
    int iHeight;
    int iPrevious = 0;
    int iTotalCaptures = 0;
    int iNeedsSystem = 0;

    TCHAR szBuffer[1024] = TEXT('\0');
    
    LPTSTR pszSeparator = TEXT(",");
    LPTSTR pszNumber = NULL;
    
    _tprintf( TEXT("Please type the height of every ")
              TEXT("Missiles by order(less than 30000):\n")
              TEXT("NOTE: with the comma to separate ")
              TEXT("every one!\n") );

    
    _tprintf( szBuffer );
   
    // retrieve the height of Missiles by user input.
    _tscanf( TEXT("%s"), szBuffer );
   
    pszNumber = _tcstok( szBuffer, pszSeparator );
   
    while ( pszNumber != NULL )
    {
        iHeight = _ttoi( pszNumber );
        if ( iHeight < 30000 )
        {
            if ( iHeight > iPrevious )
            {
                iNeedsSystem++;
            }
            iTotalCaptures++;
            iPrevious = iHeight;
        }
        pszNumber = _tcstok( NULL, pszSeparator );
    }

    // print the result
    _tprintf( TEXT("total capture: %d, need the system: %d \n"), iTotalCaptures, iNeedsSystem );
   
    return (0);
}

/////////////////////////////////////////////////////////////////////////////////

如果要想在UNICODE平台下编译, 加上: #define _UNICODE 即可!

另, 此方案没有设定数组。因为用户输入的高度数量是未知数,所以根据逗号分隔的字串来获取。SMART! HEHE!

编译方法(菜鸟指引):你如果安装了VC++,那么你可用下面的build.bat进行编译它。
------------------------------------------------------
cl /c /Gz /O2 %1.c
link /SUBSYSTEM:CONSOLE /MACHINE:IX86 %1.obj kernel32.lib user32.lib gdi32.lib
------------------------------------------------------

在CMD.EXE下使用:

build <不包含扩展名的C文件名>

注:CL.EXE是VC++6.0的C/C++编译器、link.exe是它的链接器。

【作者: airgeneral】【访问统计:】【2005年12月4日 星期日 12:00】【注册】【打印

搜索

Google

Trackback

你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=3764343

来自《通往圣地》卫斯文《通往圣地》卫斯文的引用:

《通往圣地》卫斯文

博客手拉手

一道题! dreamrain
关于“放屁” lavu
关于“放屁” lavu
关于文字 忘了回头
关于三视图 sandy50

回复

- 评论人:匿名网友   2007-10-28 23:46:47   

int InsertList(PLIST head_a, PLIST head_b, int i, int j)
{
PLIST temp;
int n;

for (n = 1; head_a != NULL && n != i+1; n++)
{
head_a = head_a-〉next;
}
if (n != i+1)
{
return -1;
}

for (n = 1; head_b != NULL && n != j-1; n++)
{
head_b = head_b-〉next;
}
if (n != j-1)
{
return -1;
}

temp = head_b-〉next;
head_b-〉next = head_a;
while (head_a-〉next != NULL)
{
head_a = head_a-〉next;
}
head_a-〉next = temp;

return 0;
}

- 评论人:karyao   2006-01-11 18:13:21   karyao的博客  

你好 请问你是飞行员吗? 我希望你能上我的论坛作 空军板块的斑竹 能支持下我么 www.esim.cn

验证码:   
评论内容: