7-22 龟兔赛跑 (20 分)

乌龟与兔子进行赛跑,跑场是一个矩型跑道,跑道边可以随地进行休息。乌龟每分钟可以前进3米,兔子每分钟前进9米;兔子嫌乌龟跑得慢,觉得肯定能跑赢乌龟,于是,每跑10分钟回头看一下乌龟,若发现自己超过乌龟,就在路边休息,每次休息30分钟,否则继续跑10分钟;而乌龟非常努力,一直跑,不休息。假定乌龟与兔子在同一起点同一时刻开始起跑,请问T分钟后乌龟和兔子谁跑得快?

输入格式:

输入在一行中给出比赛时间T(分钟)。

输出格式:

在一行中输出比赛的结果:乌龟赢输出@[email protected],兔子赢输出^_^,平局则输出-_-;后跟1空格,再输出胜利者跑完的距离。

输入样例:

242

输出样例:

@[email protected] 726

想来想去还是用函数解决这个问题,函数图像是初始是两条过原点的直线,判断兔子是否睡觉,睡觉即将兔子的函数图像沿x轴向右移动30个单位(可能超出时间界限)兔子: y = 9(x-30n)乌龟: y = 3x
 1 #include<stdio.h>
 2 int main()        /*  龟兔赛跑 */
 3 {
 4     int i,T,g,t,n;
 5     t=g=n=0;
 6     scanf("%d",&T);
 7     for(i=0;i<=T;  ){
 8         g = 3 *i;
 9         t = 9 *(i-n*30);
10         if(i%10==0 && t>g && i!=0)
11         {
12             i+=30;
13             if(i> T){
14                 g = 3*T;
15                 break;
16             }
17
18             n++;
19         }else{
20             i++;
21         }
22
23     }
24     if(t>g)                            /*兔子赢*/
25     printf("^_^ %d",t);
26     else if(t==g)                    /*平局*/
27     printf("-_- %d",T*3);
28     else                             /*乌龟赢*/
29     printf("@[email protected] %d",T*3);
30     return 0;
31 }
32
33                     

原文地址:https://www.cnblogs.com/baoshudegua/p/11567295.html

时间: 2024-08-10 12:34:31

7-22 龟兔赛跑 (20 分)的相关文章

5-22 龟兔赛跑 (20分)

乌龟与兔子进行赛跑,跑场是一个矩型跑道,跑道边可以随地进行休息.乌龟每分钟可以前进3米,兔子每分钟前进9米:兔子嫌乌龟跑得慢,觉得肯定能跑赢乌龟,于是,每跑10分钟回头看一下乌龟,若发现自己超过乌龟,就在路边休息,每次休息30分钟,否则继续跑10分钟:而乌龟非常努力,一直跑,不休息.假定乌龟与兔子在同一起点同一时刻开始起跑,请问T分钟后乌龟和兔子谁跑得快? 输入格式: 输入在一行中给出比赛时间T(分钟). 输出格式: 在一行中输出比赛的结果:乌龟赢输出@[email protected],兔子赢

PAT-JAVA-5-22 龟兔赛跑 (20分)

乌龟与兔子进行赛跑,跑场是一个矩型跑道,跑道边可以随地进行休息.乌龟每分钟可以前进3米,兔子每分钟前进9米:兔子嫌乌龟跑得慢,觉得肯定能跑赢乌龟,于是,每跑10分钟回头看一下乌龟,若发现自己超过乌龟,就在路边休息,每次休息30分钟,否则继续跑10分钟:而乌龟非常努力,一直跑,不休息.假定乌龟与兔子在同一起点同一时刻开始起跑,请问T分钟后乌龟和兔子谁跑得快? 输入格式: 输入在一行中给出比赛时间T(分钟). 输出格式: 在一行中输出比赛的结果:乌龟赢输出@[email protected],兔子赢

7-22 龟兔赛跑(20 分)

7-22 7-22 龟兔赛跑(20 分) 乌龟与兔子进行赛跑,跑场是一个矩型跑道,跑道边可以随地进行休息.乌龟每分钟可以前进3米,兔子每分钟前进9米:兔子嫌乌龟跑得慢,觉得肯定能跑赢乌龟,于是,每跑10分钟回头看一下乌龟,若发现自己超过乌龟,就在路边休息,每次休息30分钟,否则继续跑10分钟:而乌龟非常努力,一直跑,不休息.假定乌龟与兔子在同一起点同一时刻开始起跑,请问T分钟后乌龟和兔子谁跑得快? 输入格式: 输入在一行中给出比赛时间T(分钟). 输出格式: 在一行中输出比赛的结果:乌龟赢输出@

PAT 乙级 1083 是否存在相等的差(20 分)

1083 是否存在相等的差(20 分) 给定 N 张卡片,正面分别写上 1.2.--.N,然后全部翻面,洗牌,在背面分别写上 1.2.--.N.将每张牌的正反两面数字相减(大减小),得到 N 个非负差值,其中是否存在相等的差? 输入格式: 输入第一行给出一个正整数 N(2 ≤ N ≤ 10 000),随后一行给出 1 到 N 的一个洗牌后的排列,第 i 个数表示正面写了 i 的那张卡片背面的数字. 输出格式: 按照"差值 重复次数"的格式从大到小输出重复的差值及其重复的次数,每行输出一

PAT 甲级 1001 A+B Format (20)(20 分)

1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Each input file contains one test case. Each case

pat 1015 Reversible Primes(20 分)

1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime. Now given a

pat 1136 A Delayed Palindrome(20 分)

1136 A Delayed Palindrome(20 分) Consider a positive integer N written in standard notation with k+1 digits a?i?? as a?k???a?1??a?0?? with 0≤a?i??<10 for all i and a?k??>0. Then N is palindromic if and only if a?i??=a?k?i?? for all i. Zero is written

pat 1116 Come on! Let&#39;s C(20 分)

1116 Come on! Let's C(20 分) "Let's C" is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny as the following: 0

pat 1124 Raffle for Weibo Followers(20 分)

1124 Raffle for Weibo Followers(20 分) John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo -- that is, he would select winners from every N followers who forwarded his post, and give away gifts.