湖北中醫藥大學2019暑期練習賽題解(二)

A - Average is not Fast Enough!

A relay is a race for two or more teams of runners. Each member of a team runs one section of the race. Your task is to help to evaluate the results of a relay race.

You have to process several teams. For each team you are given a list with the running times for every section of the race. You are to compute the average time per kilometer over the whole distance. That’s easy, isn’t it?
So if you like the fun and challenge competing at this contest, perhaps you like a relay race, too. Students from Ulm participated e.g. at the “SOLA” relay in Zurich, Switzerland. For more information visit http://www.sola.asvz.ethz.ch/ after the contest is over.
Input
The first line of the input specifies the number of sections n followed by the total distance of the relay d in kilometers. You may safely assume that 1 <= n <= 20 and 0.0 < d < 200.0. Every following line gives information about one team: the team number t (an integer, right-justified in a field of width 3) is followed by the n results for each section, separated by a single space. These running times are given in the format “h:mm:ss” with integer numbers for the hours, minutes and seconds, respectively. In the special case of a runner being disqualified, the running time will be denoted by “-:–:--”. Finally, the data on every line is terminated by a newline character. Input is terminated by EOF.
Output
For each team output exactly one line giving the team’s number t right aligned in a field of width 3, and the average time for this team rounded to whole seconds in the format “m:ss”. If at least one of the team’s runners has been disqualified, output “-” instead. Adhere to the sample output for the exact format of presentation.
Sample Input
2 12.5
5 0:23:21 0:25:01
42 0:23:32 -:–:--
7 0:33:20 0:41:35
Sample Output
5: 3:52 min/km
42: -
7: 6:00 min/km

題目大意:

進行接力賽,每個團隊的人數爲n,接力賽長度爲len,已知團隊中每個人的所用的時間,求每個團隊的平均速度,單位爲min/km

解題思路:

將團隊中所有人的所用時間加起來,除以總路程。如果團隊中某個人的時間是-:–:--的形式,通過查看字符串的第一位是不是-來判斷,如果有,輸出爲printf("%3d: -\n",team);的形式。否則正常輸出。

源代碼:


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,team;
    double len;
    cin>>n>>len;
    while(~scanf("%d",&team))
    {

        int i;
        double sumh,summ,sums;
        int ans;
        int count=0;
        string a[25];
        for(i=0;i<n;i++)
            cin>>a[i];
        for(i=0,sumh=0,summ=0,sums=0;i<n;i++)
        {
            if(a[i][0]=='-')
            {
                count++;
                 break;
            }
            sumh=int(a[i][0]-'0')+sumh;
            summ=int(a[i][2]-'0')*10+int(a[i][3]-'0')+summ;
            sums=int(a[i][5]-'0')*10+int(a[i][6]-'0')+sums;

        }

        if(count!=0)
        {
            printf("%3d: -\n",team);
        }
        else
        {
            sums=summ*60+sumh*3600+sums;
            ans=int(sums/len+0.5);

            printf("%3d: %d:%02d min/km\n", team, ans/60, ans%60);
        }


    }
    return 0;
}

B - Keep on Truckin’

Boudreaux and Thibodeaux are on the road again . . .

“Boudreaux, we have to get this shipment of mudbugs to Baton Rouge by tonight!”

“Don’t worry, Thibodeaux, I already checked ahead. There are three underpasses and our 18-wheeler will fit through all of them, so just keep that motor running!”

“We’re not going to make it, I say!”

So, which is it: will there be a very messy accident on Interstate 10, or is Thibodeaux just letting the sound of his own wheels drive him crazy?
Input
Input to this problem will consist of a single data set. The data set will be formatted according to the following description.

The data set will consist of a single line containing 3 numbers, separated by single spaces. Each number represents the height of a single underpass in inches. Each number will be between 0 and 300 inclusive.
Output
There will be exactly one line of output. This line will be:

NO CRASH

if the height of the 18-wheeler is less than the height of each of the underpasses, or:

CRASH X

otherwise, where X is the height of the first underpass in the data set that the 18-wheeler is unable to go under (which means its height is less than or equal to the height of the 18-wheeler).
The height of the 18-wheeler is 168 inches.
Sample Input
180 160 170
Sample Output
CRASH 160

題目大意:

找出第一個1小於或等於168值並且輸出

解題思路:

找出第一個1小於或等於168值並且輸出

源代碼

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[3],i;
   while(cin>>a[0]>>a[1]>>a[2])
   {
        int count;
        for(i=0,count=0;i<3;i++)
        {
            if(a[i]<=168)
            {
                count++;
            }
            if(count!=0)
                break;

        }
        if(count==0)
        cout<<"NO CRASH"<<endl;
        else
            cout<<"CRASH "<<a[i]<<endl;

   }

    return 0;
}

C - Biker’s Trip Odometer

Most bicycle speedometers work by using a Hall Effect sensor fastened to the front fork of the bicycle. A magnet is attached to one of the spokes on the front wheel so that it will line up with the Hall Effect switch once per revolution of the wheel. The speedometer monitors the sensor to count wheel revolutions. If the diameter of the wheel is known, the distance traveled can be easily be calculated if you know how many revolutions the wheel has made. In addition, if the time it takes to complete the revolutions is known, the average speed can also be calculated.
For this problem, you will write a program to determine the total distance traveled (in miles) and the average speed (in Miles Per Hour) given the wheel diameter, the number of revolutions and the total time of the trip. You can assume that the front wheel never leaves the ground, and there is no slipping or skidding.
Input
Input consists of multiple datasets, one per line, of the form:

diameter revolutions time

The diameter is expressed in inches as a floating point value. The revolutions is an integer value. The time is expressed in seconds as a floating point value. Input ends when the value of revolutions is 0 (zero).
Output
For each data set, print:

Trip #N: distance MPH

Of course N should be replaced by the data set number, distance by the total distance in miles (accurate to 2 decimal places) and MPH by the speed in miles per hour (accurate to 2 decimal places). Your program should not generate any output for the ending case when revolutions is 0.

Constants

For p use the value: 3.1415927.
There are 5280 feet in a mile.
There are 12 inches in a foot.
There are 60 minutes in an hour.
There are 60 seconds in a minute.
There are 201.168 meters in a furlong.
Sample Input
26 1000 5
27.25 873234 3000
26 0 1000
Sample Output
Trip #1: 1.29 928.20
Trip #2: 1179.86 1415.84

題目大意

已知直徑d,轉的圈數r,所用時間t,求路程和平均速度

解題思路:

總路程len爲 d * pi * r,速度爲len除以總時間,主要注意單位的換算。

源代碼:

#include <bits/stdc++.h>
const double pi = 3.1415927;
using namespace std;
int main()
{
    double d,r,t;
    int count=0;
    while(cin>>d>>r>>t&&r)
    {

        count++;
        double len,v;
        len=(d*pi*r)/(5280*12);
        v=len/(t/3600.0);
        printf("Trip #%d: %.2f %.2f\n",count,len,v);
    }

    return 0;
}

D - Easier Done Than Said?

Password security is a tricky thing. Users prefer simple passwords that are easy to remember (like buddy), but such passwords are often insecure. Some sites use random computer-generated passwords (like xvtpzyo), but users have a hard time remembering them and sometimes leave them written on notes stuck to their computer. One potential solution is to generate “pronounceable” passwords that are relatively secure but still easy to remember.

FnordCom is developing such a password generator. You work in the quality control department, and it’s your job to test the generator and make sure that the passwords are acceptable. To be acceptable, a password must satisfy these three rules:

It must contain at least one vowel.

It cannot contain three consecutive vowels or three consecutive consonants.

It cannot contain two consecutive occurrences of the same letter, except for ‘ee’ or ‘oo’.

(For the purposes of this problem, the vowels are ‘a’, ‘e’ , ‘i’, ‘o’, and ‘u’; all other letters are consonants.) Note that these rules are not perfect; there are many common/pronounceable words that are not acceptable.
Input
The input consists of one or more potential passwords, one per line, followed by a line containing only the word ‘end’ that signals the end of the file. Each password is at least one and at most twenty letters long and consists only of lowercase letters.
Output
For each password, output whether or not it is acceptable, using the precise format shown in the example.
Sample Input
a
tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end
Sample Output
<a> is acceptable.
<tv> is not acceptable.
<ptoui> is not acceptable.
<bontres> is not acceptable.
<zoggax> is not acceptable.
<wiinq> is not acceptable.
<eep> is acceptable.
<houctuh> is acceptable.

題目大意:

給出一個字符串,判斷它是否acceptable。同時滿足如下三個條件時就是acceptable的
1.有元音字符
2.沒有三個元音字符或者三個輔音字符相連
3.除‘ee’,‘oo’之外,不能有兩個及以上連續相同的字符

解題思路:

每個條件分開判斷,三個條件同時滿足就輸出is acceptable,否則輸出 is not acceptable。

源代碼:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int i;
    while(cin>>s&&s!="end")
    {
        int rule1=0,rule2=1,rule3=1;
        for(i=0;i<s.length();i++)
        {
            if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
            {
                 rule1++;
                 break;
            }
        }
        int county,countf;
       for(i=0,county=0, countf=0;i<s.length();i++)
        {
            if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
            {
                 county++;
                 countf=0;
            }
            else
            {
                county=0;
                countf++;
            }
            if(countf==3||county==3)
            {
                rule2--;
                break;
            }
        }
        for(i=1;i<s.length();i++)
        {
            if(s[i]==s[i-1]&&(s[i]!='e'&&s[i]!='o'))
            {
                rule3--;
                break;
            }

        }
        if(rule1&&rule2&&rule3)
        {
            cout<<"<"<<s<<"> is acceptable."<<endl;
        }
        else
        {
            cout<<"<"<<s<<"> is not acceptable."<<endl;

        }

    }
    return 0;
}

E - Gridland

For years, computer scientists have been trying to find efficient solutions to different computing problems. For some of them efficient algorithms are already available, these are the “easy” problems like sorting, evaluating a polynomial or finding the shortest path in a graph. For the “hard” ones only exponential-time algorithms are known. The traveling-salesman problem belongs to this latter group. Given a set of N towns and roads between these towns, the problem is to compute the shortest path allowing a salesman to visit each of the towns once and only once and return to the starting point.

The president of Gridland has hired you to design a program that calculates the length of the shortest traveling-salesman tour for the towns in the country. In Gridland, there is one town at each of the points of a rectangular grid. Roads run from every town in the directions North, Northwest, West, Southwest, South, Southeast, East, and Northeast, provided that there is a neighbouring town in that direction. The distance between neighbouring towns in directions North–South or East–West is 1 unit. The length of the roads is measured by the Euclidean distance. For example, Figure 7 shows 2 × 3-Gridland, ie, a rectangular grid of dimensions 2 by 3. In 2 × 3-Gridland, the shortest tour has length 6.

Input
The first line contains the number of scenarios.

For each scenario, the grid dimensions m and n will be given as two integer numbers in a single line, separated by a single blank, satisfying 1 < m < 50 and 1 < n < 50.
Output
The output for each scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. In the next line, print the length of the shortest traveling-salesman tour rounded to two decimal digits. The output for every scenario ends with a blank line.
Sample Input
2
2 2
2 3
Sample Output
Scenario #1:
4.00

Scenario #2:
6.00

題目大意:

長爲n,寬爲m的的矩形,經過每個點,需要走的總路程

解題思路

只有當長和寬都是奇數的時候矩形纔不能一筆畫完,如果原點的座標爲(0,0),並且一定可以回到座標爲(1,1)的位置,所以當長和寬都是奇數的時候,就先走完其他位置,再走(1,1)。
總長度就是mn+根號2,否則總長度就是mn。

源代碼:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t,count=0;
    cin>>t;
    while(t--)
    {
        count++;
        int n,m;
        cin>>m>>n;
        if(m%2!=0&&n%2!=0)
            printf("Scenario #%d:\n%.2lf\n\n",count,(double)m*n+0.41);
        else
            printf("Scenario #%d:\n%.2lf\n\n",count,(double)m*n);
    }
    return 0;
}

F - The Hardest Problem Ever

Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked.
You are a sub captain of Caesar’s army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (ie, if the letter is ‘A’, the cipher text would be ‘F’). Since you are creating plain text out of Caesar’s messages, you will do the opposite:

Cipher text
ABCDEFGHIJKLMNOPQRSTU VWXYZ

Plain text
VWXYZABCDEFGHIJKLMNOP QRSTU

Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.

A single data set has 3 components:

Start line - A single line, “START”

Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar

End line - A single line, “END”

Following the final data set will be a single line, “ENDOFINPUT”.
Output
For each data set, there will be exactly one line of output. This is the original message by Caesar.
Sample Input
START
NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX
END
START
N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ
END
START
IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ
END
ENDOFINPUT
Sample Output
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME
DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE

題目大意:

將START與 END中間的那一行字符串每個字符的大小減五。並且START爲ENDOFINPUT時中止

解題思路:

通過getchar()接收空格,gets(str)接收一整行的空格,把str字符串中的各個字符遍歷,當再A與Z之間的時候字符減5,減五之後如果小於A,就加上26達到循環的效果。

源代碼

#include <bits/stdc++.h>
using namespace std;
int main()
{
   char s[15],e[15];
    while(cin>>s&&strcmp(s,"ENDOFINPUT"))
    {
        char str[300];
        getchar();
        gets(str);
        getchar();
        cin>>e;
        for(int i=0;i<strlen(str);i++)
        {
            if(str[i]>='A'&&str[i]<='Z')
            {
                str[i]-=5;
                if(str[i]<'A')
                    str[i]+=26;
            }
        }
        cout<<str<<endl;
    }
    return 0;
}

G - Climbing Worm HDU - 1049

An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and resting then repeats. How long before the worm climbs out of the well? We’ll always count a portion of a minute as a whole minute and if the worm just reaches the top of the well at the end of its climbing, we’ ll assume the worm makes it out.
Input
There will be multiple problem instances. Each line will contain 3 positive integers n, u and d. These give the values mentioned in the paragraph above. Furthermore, you may assume d < u and n < 100. A value of n = 0 indicates end of output.
Output
Each input instance should generate a single integer on a line, indicating the number of minutes it takes for the worm to climb out of the well.
Sample Input
10 2 1
20 3 1
0 0 0
Sample Output
17
19

題目大意

蝸牛在深度爲n的一個洞底,蝸牛一分鐘向上爬u米,然後休息一分鐘,在這一分鐘下滑d米,問多少分鐘後可以從洞中爬出來

解題思路

通過循環,先向上爬u米,判斷離洞口的距離,如果爲小於等於0,循環結束,輸出時間,如果大於0,離洞口的時間再加d。

源代碼

#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n,u,d,ans;
   while(cin>>n>>u>>d&&(n||u||d))
   {
       ans=0;
       while(n)
       {
           n-=u;
           ans++;
           if(n<=0)
            break;
           n+=d;
           ans++;

       }
       cout<<ans<<endl;
   }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章