| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1245 人关注过本帖
标题:来做题啊!
只看楼主 加入收藏
虾米1号
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-2-29
收藏
 问题点数:0 回复次数:7 
来做题啊!
A Pilot in Danger!
Input file: Pilot.in
The World War II was going on in 1941. Germany, Italy and Hungary had occupied Yugoslavia for months. Led by Tito, though having losing thousands of lives and still being under the threat of Fascist, Yugoslav were fighting against the enemy toughly until the enemy escaped from their motherland. On the east, although on August 23rd, 1939 Germany and Soviet Union signed a treaty that they wouldn’t invade each other, Hitler attacked Soviet Union without declare on June 22nd, 1941. The war came into more and more impetuous. On October 2nd, Germany began to attack Moscow, trying to occupy it in ten days. However, Moscow still alive after two months, as sacrificing thousands of people! Then, after Moscow Defense and Stalingrad Defense, Soviet Union counterattacked Germany.
One day, the oil of a Soviet bomber on task run down, and the pilot had to bail out in the enemy region. He was in danger! He became calm quickly, and he must know whether he’s in enemy’s barrack, for he was not afraid of any enemy out of their barrack. If unfortunately he’s, he must get the secret number, which allowed anyone pass the watch without trouble.
The barrack was an area bounded by a fence on some flat field. In the plane projection the fence has a form of a closed polygonal line (without self-intersections), which was specified by Cartesian coordinates (xi, yi) of its n vertices. The pilot stood on the field at the point with coordinates (0, 0). The pilot may be located either outside or inside the fence, but not on its sides.
How to get the secret number of the barrack? There are two different primes p, q, p≠q, in the barrack, as everybody could get it with ease. The secret number indicated that how many positive integers that can not be in the form of px+qy while x, y are integers and x, y≥0.
For example, given p=3 and q=5, there are four positive integers, 1, 2, 4, 7, which can not be in the form mentioned above. So, the secret number was 4.
Your task: Decide whether the pilot was in the barrack. If he was, get the secret number.
Input
The input file consists with several tests. For every test, first line contains a single integer n, fitting 3≤n≤16, and while n=0 means the end of the input. n is the number of the vertices of the fence. Then n files follow, every line contains two real numbers xi and yi, separated by space(s). After that, there are two different primes p, q, 2≤p, q≤1000, in the next line, which help you to get the secret number as above.
The vertices may appear clockwise or counterclockwise.
Output
For every test, first output the number of the pilot. Next line tell us whether the pilot was in danger (if he’s in the enemy’s barrack) or not. If he was, tell us the secret number in the next line.
Write an empty line after every test.
Sample Input
4
-1.0 -1.0
2.0 -1.0
2.0 2.0
-1.0 2.0
3 5
5
-2.5 -2.5
10.5 -2.5
10.5 -1.5
-1.5 -1.5
-2.5 20.5
2 7
0
Sample Output for Sample Input
Pilot 1
The pilot is in danger!
The secret number is 4.

Pilot 2
The pilot is safe.
搜索更多相关主题的帖子: thousands fighting although against without 
2008-02-29 19:10
xfcyjhb
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:116
专家分:0
注 册:2008-2-26
收藏
得分:0 
头晕!!!!!!!!

多C多智慧,将C进行到底.........
2008-03-01 15:43
广陵绝唱
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:29
帖 子:3607
专家分:1709
注 册:2008-2-15
收藏
得分:0 
这不是在英国网站,就是在考英语。
2008-03-01 16:09
rxfengqihao
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-2-16
收藏
得分:0 
看不懂~~~~ - -!
2008-03-01 16:41
lovelark
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-6-29
收藏
得分:0 
迷茫啊
这些是什么啊
2008-03-01 16:55
zbqf109
Rank: 1
等 级:新手上路
帖 子:289
专家分:0
注 册:2006-12-31
收藏
得分:0 
题目我就不翻译了。要解决的问题有两个:
1、如何判断一个点是否在一个多边形内;
2、求不能表示成 px + qy 形式的正整数的个数。
对于后者,我主观的用了一种简单的办法,可能不对,欢迎纠正。
下面是我写的一个简单的示例程序,有不少地方待完善。为了看清每一步程序都做了什么,所以默认的,就输出多了一些信息,如果不想要,不必去删除那些条件编译语句,在前面删除
#define __DEBUG_
或者加上一个
#undef __DEBUG_
就可以了。
程序代码:
#include <stdio.h>
#include <stdlib.h>

typedef struct tagPOINT{
    float xi, yi;
}POINT;

#define __DEBUG_

static const POINT poly1[5] = {-2.5, -2.5, 10.5, -2.5, 10.5, -1.5, -1.5, -1.5, -2.5, 20.5};
static const POINT poly2[4] = {-1.0, -1.0, 2.0, -1.0, 2.0, 2.0,-1.0, 2.0};

int main()
{
    #ifndef __DEBUG_
    // 获取边数
    int n = 0;
    printf("输入多边形边数: ");
    scanf("%d", &n);
    
    
    POINT *poly = (POINT *) malloc (n * sizeof(POINT));
    
    // 获取各个顶点坐标
    printf("依次输入 %d 个顶点的坐标: \n", n);
    for (int i = 0; i < n; i++)
    {
        scanf("%f%f", &(poly[i].xi), &(poly[i].yi));
    }
    
    
    // 获取两个质数 p, q
    printf("输入两个质数: ");
    int p = 0, q = 0;
    scanf("%d%d", &p, &q);
    #endif
    // 判断飞行员是否有危险
    /* 判断原则: (0, 0) 在多边形内部表示有危险, 外部表示安全 */
    //int safe = 0;    // safe 为 0 表示不安全, 非 0 表示安全
    /* 从原点引一条射线, 这条射线经过多边形的第一个顶点, 这条射线的方程就是
        y = (poly[0].yi / poly[0].xi) * x; (x * xi >= 0)
        判断这条射线与多边形的其它边是否有交点, 并记录交点的个数
    */
    #ifdef __DEBUG_
    #ifdef POLY2
    #define poly poly2
    #define n 4
    #define p 3
    #define q 5
    #else
    #define poly poly1
    #define n 5
    #define p 2
    #define q 7
    #endif
    #endif
    
    int nodus_number = 1;
    float k0 = (float) poly[0].yi / poly[0].xi;
    float k1 = 0.0;
    float *nodus = (float *) malloc ((n-2) * sizeof(float));
    for (int i = 2; i < n; i++)
    {
        // 求出交点横坐标
        float x = 0.0;
        if (poly[i].xi != poly[i-1].xi)
        {    
            k1 = (poly[i].yi - poly[i-1].yi) / (poly[i].xi - poly[i - 1].xi);
            x = (k1 * poly[i].xi - poly[i].yi) / (k1 - k0);
            // 判断是否在边上
            if (x * poly[0].xi >= 0)
            {
                /* 将每个交点的横坐标记录到 nodus 数组中, 当发现"新"的交点时, 与nodus数组中
                    的每一个元素对比看是否重复, 如果不重复, 再加入数组中, 并将交点个数加1
                */
                if (nodus_number == 1)
                {
                    nodus[nodus_number-1] = x;
                    nodus_number++;
                }
                else {
                    int ok_new = 0;
                    for (int j = 0; j < nodus_number - 1; j++)
                    {
                        if (nodus[j] == x)
                        {
                            ok_new = 1;
                            break;
                        }
                    }
                    if (!ok_new)
                    {
                        nodus[nodus_number - 1] = x;
                        nodus_number++;
                    }
                }
            }
        }
        #ifdef __DEBUG_
        printf("k0 = %f, k1 = %f\n", k0, k1);
        printf("x = %f\n", x);
        printf("poly[%d].xi = %f, poly[%d].xi = %f\n\n", i, poly[i].xi, i-1, poly[i-1].xi);
        #endif
    }
    if (nodus_number % 2)
    {
        printf("飞行员不安全, 敌军密码是 ");
        // 破解密码
        int max = p + q;
        int secret_number = 1;
        for (int i = 2; i < max; i++)
        {
            if ((i % p == 0) || (i % q == 0))
                continue;
            else 
                secret_number++;
        }
        printf("%d\n", secret_number);
    }
    else {
        //printf("The pilot is safe!")
        printf("飞行员安全\n");
    }
    system("pause");
    return 0;
}

坚决不跟用TC的人打交道!
2008-03-01 22:35
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1029
专家分:177
注 册:2007-5-10
收藏
得分:0 
http://acm.fzu.
你直接贴题目地址不就行了,无聊。
2008-03-02 16:08
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1029
专家分:177
注 册:2007-5-10
收藏
得分:0 
回复 6# 的帖子
你猜测“对于任意z,z>=p+q,都有非负整数x,y使得z=px+qy成立”的结论是错误的。
事实上,对于p,q,
如果gcd(p,q)=1,那么最大的不能被式子z=px+qy表示出来的z是(p-1)*(q-1)-1
如果gcd(p,q)!=1,那么不存在最大的上述意义的z,不能被表示出来的数有无穷多。
2008-03-02 17:17
快速回复:来做题啊!
数据加载中...
 
   



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

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