若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1102: Problem C – Snakes

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,182

题目描述

Problem C – Snakes
Buffalo Bill wishes to cross a 1000×1000 square field. A number of snakes are on the field at various positions, and each snake can strike a particular distance in any direction. Can Bill make the trip without being bitten?
Assume that the southwest corner of the field is at (0,0) and the northwest corner at (0,1000). The input consists of a line containing n <= 1000, the number of snakes. A line follows for each snake, containing three real numbers: the (x,y) location of the snake and its strike distance. The snake will bite anything that passes closer than this distance from its location.
Bill must enter the field somewhere between the southwest and northwest corner and must leave somewhere between the southeast and northeast corners.
If Bill can complete the trip, give coordinates at which he may enter and leave the field. If Bill may enter and leave at several places, give the most northerly. If there is no such pair of positions, print "Bill will be bitten."

输入

暂无

输出

暂无

样例输入

3
500 500 499
0 0 999
1000 1000 200

样例输出

Bill enters at (0.00, 1000.00) and leaves at (1000.00, 800.00).

参考代码

/* use of random() portable among:
   Solaris, SunOS, DECUnix, Linux
*/
#include <stdio.h>
#include <stdlib.h>
char jane[200], john[200];
int janei, johni;
main() 
{
    int i,j;
    gets(jane);
    gets(john);
    for (j=janei=johni=0;j<1000 && strlen(jane)&&strlen(john);j++) 
    {
        if (jane[janei] == john[johni]) 
        {
            if (random()/141%2 == 0) 
            {
                /* jane wins */
                printf("Snap! for Jane: ");
                for (i=strlen(jane);i>janei;i--) jane[i+johni+1] = jane[i];
                strncpy(jane+janei+1,john,johni+1);
                strcpy(john,john+johni+1);
                janei = janei + johni + 2;
                johni = 0;
                for (i=janei-1;i>=0;i--) printf("%c",jane[i]);
                printf("n");
         }else{  /* john wins */ 
            printf("Snap! for John: ");
            for (i=strlen(john);i>johni;i--) john[i+janei+1] = john[i];
            strncpy(john+johni+1,jane,janei+1);
            strcpy(jane,jane+janei+1);
            johni = johni + janei + 2;
            janei = 0;
            for (i=johni-1;i>=0;i--) printf("%c",john[i]);
            printf("n");
         }
      }else{
         janei++; johni++;
      }
      if (!jane[janei]) janei = 0;
      if (!john[johni]) johni = 0;
   }
   if (!strlen(jane)) printf("John wins.n");
   else if (!strlen(john)) printf("Jane wins.n");
   else printf("No winner after %d turnsn",j);
}

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Skip 原站点 Dreams孤独患者
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist