ACM训练赛第17场

ACM训练赛第17场

问题 A: Bing Bong to Bong Bong

时间限制: 2 Sec 内存限制: 128 MB
题目描述
Bing Bong, the pink imaginary friend from Riley’s childhood, is lonely.He wants to preserve his memory, but he wants to try to hide his name in the stories. He wants you to help him do this. Given text input, every time “Bing” is found, replace it with “Bong”.
输入
The first line of the input file will contain n ≤ 2000, the number of test cases.
Each test case will start with a single positive integer c < 100,followed by c words, all space separated. Note that a word may contain punctuation. All words will be separated by a single space. No test case will consist of more than 1000 characters.
输出
For each test case, print the sentence (not the number c from each test case), replacing “Bing” with “Bong”.The words in each test case should be space separated, and each test case should be on its own line.The replacement must be done for three cases: title case (“Bing” to “Bong”), lower case (“bing” to “bong”), and upper case (“BING” to “BONG”). Other cases (“BiNg”, “bInG”, etc.) should not be
replaced. Only whole words should be replaced; do not replace instances of “bing” within other words.
A space after the last word on the line is optional – either way is fine.
样例输入 Copy
5
2 Bing Bong
4 Bing Bong likes Riley
7 Spelled in lower case is bing bong
9 Do not replace the last 4 letters of gabbing
3 No replacements here
样例输出 Copy
Bong Bong
Bong Bong likes Riley
Spelled in lower case is bong bong
Do not replace the last 4 letters of gabbing
No replacements here

思路

暴力即可,防超时用输入输出挂。

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Stack;
 
public class Main {
     
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int T = in.nextInt();
        while (T -- > 0) {
            int n = in.nextInt();
            String tmp = "";
            for (int i = 0; i < n; i ++) {
                tmp = in.next();
                if (tmp.equals("Bing")) {
                    out.print("Bong");
                } else if (tmp.equals("bing")) {
                    out.print("bong");
                } else if (tmp.equals("BING")) {
                    out.print("BONG");
                } else {
                    out.print(tmp);
                }
                if (i != n - 1) {
                    out.print(" ");
                }
            }
            out.println();
        }
        out.close();
    }
     
     
    static class InputReader {
        // 自行百度
    }
}

问题 B: The Cost of Going UP!

时间限制: 1 Sec 内存限制: 128 MB
题目描述
Carl wants to fly his house, using thousands of balloons, to Paradise Falls to fulfill his promise to Ellie. Carl knows exactly how many balloons he needs to get his house airborne. Help Carl figure out how many packs of balloons he needs to buy.
Given the total number of balloons needed, and the number of balloons per pack, determine how many packs Carl needs to buy before he can fly.
输入
The first line of input, a positive integer n ≤ 1000, will be the number of test cases.
The following n lines will each consist of two non-negative integers,separated by a single space. The first will be the number of balloons needed to fly, and the second will be the number of balloons per pack.
There will never be zero balloons per pack. Both of these numbers are less than 200, 000.
输出
Each case will output one line; that line will contain only the number of packs necessary for that case.
样例输入 Copy
3
120097 60
100000 100
81 8
样例输出 Copy
2002
1000
11

思路

签到

#include<cstdio>
int n,p,q;
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        scanf("%d%d",&p,&q);
        if(q==0)
            printf("1\n");
        else if(p/q*q==p) {
            printf("%d\n",p/q);
        } else {
            printf("%d\n",1+p/q);
        }
    }
    return 0;
}

问题 C: The Next Toy Story

时间限制: 1 Sec 内存限制: 128 MB
题目描述
Toy Story sequels just keep coming out! Fortunately, the Toy Story creators are smarter than other movie producers and know better than to start with, well, movie number 4 and make the movies out of order.
Given a title of a Toy Story movie, find the next sequel.
输入
The first line of input will be a single integer, n ≤ 1000, which is the number of input cases. There will be n lines that follow. Each line is a Toy Story title, consisting of the string “Toy Story” followed by a space, then an integer −10, 000 ≤ x ≤ 10, 000.
输出
For each test case, output the name of the next consecutive Toy Story sequel. The sequel will always have a numerical value one higher than the supplied name.
样例输入 Copy
3
Toy Story 5
Toy Story 8
Toy Story -1
样例输出 Copy
Toy Story 6
Toy Story 9
Toy Story 0

思路

签到

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
 
int n,p;
string s,t;
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        cin>>s>>t>>p;
        printf("Toy Story %d\n",p+1);
    }
    return 0;
}

问题 D: A Hard Day at Work

时间限制: 1 Sec 内存限制: 128 MB
题目描述
Sulley and Mike have a lot of work to do today! They have a number of doors to work on, through which they have to scare children to generate enough power for Monstropolis. They were up late last night,and are rather tired today, so they want to work as efficiently as possible. This means that they want to do the hardest ones done first. Help Sulley and Mike with this problem.
Given a list of doors, and a difficulty rating for each, list them in decreasing order.
输入
The input will start with n ≤ 250, the number of test cases.
Each test case will start with a integer value 1 ≤ d ≤ 100, which is the number of doors in that test case. Each door specification will be on its own line. Each door specification will consist of a single positive integer 1 ≤ x ≤ 1000 and the door name. A door’s name will be a string without whitespace (letters, numbers, and punctuation are valid) and be less than 100 characters long. There will never be two doors in the same test case that have the same difficulty or the same name.
输出
For each test case, first output “Case x:” on its own line – note that ‘x’ starts at 1, and don’t forget the colon. Each test case will have the d doors listed in decreasing difficulty order. There should be no extra space between the test cases.
样例输入 Copy
2
3
3 Most_Difficult
1 Least_Difficult
2 Moderately_Difficult
8
721 Sophia’s_Room
45 Olivia’s_Room
554 Emma’s_Room
684 Jackson’s_Room
461 Aiden’s_Room
1000 Liam’s_Room
1 Ava’s_Room
293 Noah’s_Room
样例输出 Copy
Case 1:
Least_Difficult
Moderately_Difficult
Most_Difficult
Case 2:
Ava’s_Room
Olivia’s_Room
Noah’s_Room
Aiden’s_Room
Emma’s_Room
Jackson’s_Room
Sophia’s_Room
Liam’s_Room

思路

签到

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,d,len[105];
char a[105][105];
struct str {
    int l;
    char s[105];
};
str sstr[105];
bool comp(str p,str q) {
    return p.l<q.l;
}
int main() {
    scanf("%d",&n);
    for(int i=0; i<=n-1; i++) {
        scanf("%d",&d);
        for(int j=0; j<=d-1; j++) {
            scanf("%d %s",&sstr[j].l,&sstr[j].s);
        }
        sort(sstr,sstr+d,comp);
        printf("Case %d:\n",i+1);
        for(int i=0; i<d; i++) {
            printf("%s\n",sstr[i].s);
        }
    }
    return 0;
}

问题 E: Racer Car Ranking

时间限制: 1 Sec 内存限制: 128 MB
题目描述
Lightning McQueen, Strip Weathers, and Chick Hicks are cars that compete in different races against each other. Some races — such as the Piston Cup — are considered more prestigious than others, while others — such as Thunder Hollow — are somewhat less prestigious (we realize only Lightning raced there). Given a list of races of various prestige, and who won each race, help Lightning and his competitors determine who is the best racer.
You will be provided with a list of c cars who are racing in these races. You will also be given a list of r races, each with a name, a prestige, and the first three cars to cross the finish line. Unlike the movie, there are no ties.
The value, v, of a race for the winner is equal to the total prestige of the race. The second place finisher has one-half that value (rounded down), and the third place winner has one-fourth — not one-third! — of the total prestige value (also rounded down). Note that some cars may not finish within the first three placements; these cars receive a value of 0 for such races. Racers accumulate value from each race throughout the entire season.
输入
The first line of the file, n ≤ 500, will be the number of test cases.
The first line of each test case is a string, naming the racing season. The next line contains a single number 3 ≤ c ≤ 100, which is the number of cars that are racing. The next c lines contain the name of each competitor as a string. The next line is a number 2 ≤ r ≤ 100, which is the number of races to consider.
The next r lines will have the information for one race on a single line (space separated), consisting of five values: the name (a string), a prestige value (non-negative integer), and the three winners (first place,second place, and third place, in that order).
All provided strings (racing seasons, car names, and race names) will be strings consisting of letters of either case, numbers, and/or underscores. All integers, as well as all computed values, will fit in a 32-bit signed integer variable.
All finishers in the various races will be listed in the list of c cars, but some cars may never finish in the first three places of a race. Not surprisingly, any given racer can only be listed once for a given race (i.e., one can’t place first and second place).
输出
For each test case, output the racing season name, followed by a colon. The next c lines should contain
the names of each racer followed by their total score. The list of racers should be in lexicographical order (“lexicographical” ordering is like alphabetical ordering, but allowing numbers as well). Keep in mind that,in lexicographical order, “car 3” comes after “car 20”. There should be no blank lines between output cases.
样例输入 Copy
1
2005_Season
4
Lightning_McQueen
Strip_Weathers
Chick_Hicks
Slowy_McSlowFace
3
Glen_Ellyn 200 Lightning_McQueen Strip_Weathers Chick_Hicks
Dinoco_400 240 Lightning_McQueen Strip_Weathers Chick_Hicks
Piston_Cup 300 Chick_Hicks Strip_Weathers Lightning_McQueen
样例输出 Copy
2005_Season:
Chick_Hicks 410
Lightning_McQueen 515
Slowy_McSlowFace 0
Strip_Weathers 370

思路

C++ STL map

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.TreeMap;
import java.util.Iterator;
 
public class Main {
     
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int T = in.nextInt();
        while (T -- > 0) {
            String Tname = in.next();
            int n = in.nextInt();
            TreeMap<String, Integer> mp = new TreeMap<String, Integer>();
            String tmp = "";
            for (int i = 0; i < n; i ++) {
                tmp = in.next();
                if (!mp.containsKey(tmp)) {
                    mp.put(tmp, 0);
                }
            }
            int cnt = in.nextInt();
            while (cnt -- > 0) {
                String tmep = in.next();
                int score = in.nextInt();
                String fir = in.next();
                String sec = in.next();
                String thi = in.next();
                int x1 = score;
                int y1 = mp.get(fir);
                y1 += x1;
                mp.put(fir, y1);
                int x2 = score / 2;
                int y2 = mp.get(sec);
                y2 += x2;
                mp.put(sec, y2);
                int x3 = score / 4;
                int y3 = mp.get(thi);
                y3 += x3;
                mp.put(thi, y3);
            }
            out.println(Tname + ":");
            Iterator it = mp.keySet().iterator();
            while (it.hasNext()) {
                Object x = it.next();
                 out.println(x + " " + mp.get(x));
            }
        }
        out.close();
    }
     
     
    static class InputReader {
        // 自行百度
    }
}

问题 F: A Brave Archery Tournament

时间限制: 1 Sec 内存限制: 128 MB
题目描述
Merida wants some help in predicting her score for an archery tournament. When she fires an arrow, we can compute that arrow’s trajectory given a quadratic formula and the arrow’s initial position and velocity. Then we can compute where on the target it will lie.
An arrow that lands strictly within 1 unit of the center of the target is worth 5 points, if it lands strictly within 2 units it is worth 3 points, and if it lands strictly within 3 units it is worth 1 point. Any further away and the shot is worth 0 points.
We will represent the archery range as a 2D plane. Merida will always shoot directly toward the target, but may miss above or below.
The center of the target is always at the point (0,0) and it extends up and down along the y-axis. Given the arrow’s initial position and velocity, compute the point value for the shot.
The formulas that govern the arrows’ path are:
x = vt + x0
y = wt − 5t2 + y0
Where t is the time since the arrow was fired in seconds, x and y are the arrow’s x and y coordinates
at time t, v and w are the x and y components of the arrow’s initial velocity, and x0 and y0 are the arrow’s initial position.
输入
The first line of input will be a single integer n ≤ 10, 000; n test cases will follow. Each test case consists of two lines. The first line will be two integers x and y, the x and y coordinates of the arrow’s initial position.
The second line will be two integers v and w, the x and y components of the arrow’s initial velocity as per the formulas above.
输出
For each test case, output a single line with a single integer, the number of points for that shot according to the point assignments above.
样例输入 Copy
2
-10 0
10 5
-10 0
9 4
样例输出 Copy
5
3

思路

模拟

#include<cstdio>
#include<cmath>
using namespace std;
int n;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        double x,y,v,w,t;
        scanf("%lf%lf%lf%lf",&x,&y,&v,&w);
        t=(0-x)/v;
        x=v*t+x;
        y=w*t-5*t*t+y;
        double l;
        l=x*x+y*y;
        if (l<1.00)
        {
            printf("5\n");
        } 
        else if (l<4.00)
        {
            printf("3\n");
        }
        else if (l<9.00)
        {
            printf("1\n");
        }
        else
        {
            printf("0\n");
        }
    }
}

问题 G: N Queens

时间限制: 1 Sec 内存限制: 128 MB
题目描述
Ant Island has n ant colonies each with 1 queen. Each queen directs 5 teams of n/2 size. Each member of those teams has 5 sub-teams of their own of (n/2)/2 = n/4 size. Those teams have 5 sub-sub-teams of ((n/2)/2)/2 = n/8 size (and downward). Teams of size 1 have no sub-teams. Team size must be an integer – you can’t have half an ant – so if there are 7 colonies on Ant Island, then each queen will have 5 teams of size 3.
For example, consider the case where n = 4. There are 4 colonies, each with 1 queen – that’s 4 ants so far. Each of the 4 queens has 5 teams of 4/2 = 2 ants each. That’s 4 · 5 · 2 = 40 more ants. Each of those 40 ants has 5 sub-teams of 4/2/2 = 1 ant each – that’s 200 more ants. Thus, there are 4 + 40 + 200 = 244 ants total.
Given n colonies, how many total ants are there on Ant Island?
输入
The first line of the input will be a single integer x ≤ 600, which is the number of input cases.
Each input case will be on its own line, and will contain a single non-negative integer 0 ≤ n ≤ 500,which is the number of colonies on Ant Island.
输出
Each input case should have a single number printed on its own line. All output values will fit inside a 64-bit signed integer variable (i.e., a long).
样例输入 Copy
4
1
2
3
4
样例输出 Copy
1
12
18
244

思路

模拟

#include<cstdio>
#include<iostream>
using namespace std;
 
typedef long long ll;
ll n,m,ans,t;
int main() {
    cin>>n;
    for(int i=1; i<=n; i++) {
        cin>>m;
        ans=0;
        t=m;
    //  int z=0;
        while(m) {  //  cout<<t<<endl;
            ans+=t;
            t=t*5*int(m/2);
            m/=2;
        }
        cout<<ans<<endl;
    }
    return 0;
}

问题 H: Communicating with WALL-E

时间限制: 1 Sec 内存限制: 128 MB
题目描述
WALL-E and EVE need to communicate, but they are worried that AUTO and GO-4 might be listening in on their conversations. Help them communicate secretly so that they can find the plant and turn the Axiom back toward Earth.
WALL-E and EVE communicate using a substitution cipher. The cipher works by having each letter map to another letter for encryption, and then map back for decryption. Only lower case letters,spaces, and the newline character will be provided as input.
Consider the provided mapping of “defghijklmnopqrstuvwxyzabc”, which is the input provided in the first test case below. Since the first letter in that 26 character string is a ‘d’, that means that ‘a’ in the plain text will map to ‘d’ in the cipher text (encrypted version), and ‘d’ in the cipher text will map to ‘a’ in the original plain text message. Likewise, ‘b’ maps to ‘e’, etc. You will notice that this is a Caesar cipher – but not all the mappings will be such. The second test case uses the alphabet “wjseqvofacugtyhxmpdnikrlzb” – so ‘a’ maps to ‘w’, ‘b’ to ‘j’, etc.
Given a secret message from EVE that has been encrypted with a substitution cipher, help WALL-E decode it and print the result.
输入
The first line of the input will be a single integer n ≤ 1, 000. There will be n test cases that follow.
Each test case consists of two lines: the mapping, and the encrypted text. Recall that each encoded message consisting of lower-case letters (a-z) and spaces. All words will only have once space between them. Messages will not have leading or trailing white space. There will always be at least one word in an input case.
输出
For each encoded message, decode it and print it out on its own line.
样例输入 Copy
2
defghijklmnopqrstuvwxyzabc
zdooh dqg hyh juhz d sodqw
wjseqvofacugtyhxmpdnikrlzb
winh ad yh ghyoqp ay sfwpoq hv nfq wlaht
样例输出 Copy
walle and eve grew a plant
auto is no longer in charge of the axiom

思路

模拟

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char a[26];
int n;
string s;
int t[26];
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        scanf("%s",&a);
        for(int i=0; i<26; i++) {
            t[int(a[i]-'a')]=i;
        }
        getchar();
        getline(cin,s);
        for(int i=0; i<s.length(); i++) {
            if(s[i]!=32) {
                cout<<char(t[int(s[i]-'a')]+'a');
            } else cout<<" ";
 
        }
        cout<<endl;
    }
    return 0;
}

问题 I: What to Cook?

时间限制: 1 Sec 内存限制: 128 MB
题目描述
The renowned restaurant Gusteau’s has closed down, and now Remy is working at a new restaurant called Highly Sophisticated Parisian Cuisine (HSPC). However, business is busy, and Remy needs help determining whether he can cook the various dishes that patrons are asking for.
Given a list of ingredients on hand and an ordered list of recipes the guests are asking for, state if a recipe can be cooked with the ingredients left.
If an earlier recipe uses up a given ingredient, then that ingredient is no longer available to successive recipes. For example, assume there are 5 slices of bread in the inventory, the first recipe uses 4 of them,and the second uses 3. The first recipe could be made, but not the second, since there is only 1 slice of bread left over after the first recipe is made. If a recipe can not be made, then there are no ingredients removed for that given recipe. All recipies should be considered in the order provided.
输入
The first line of input will be a single integer n ≤ 200. There will be n test cases that follow.
Each test case will begin with a line with two space-separated integers: 1 ≤ i ≤ 75 and 1 ≤ r ≤ 75. The i is for how many items are in stock in the inventory, and r represents how many recipies will be specified. The inventory will be represented by the following i lines; each line will each hold one ingredient. Each line will contain the ingredient count (a positive integer) and the ingredient (an alphanumeric string). Any given ingredient will only be listed once per test case in the inventory.
r recipes will follow. Each recipe begins with a line consisting of an integer l ≤ 10, the number of ingredients for that recipe. Each of the following l lines will hold one required ingredient for the recipe (and the quantity), represented as they were in the inventory specification. An ingredient not listed in the inventory may be listed in a recipe. Any given ingredient will only be listed once for any given recipe.
输出
For each test case, first output the test case number x as “Case x:” (start from 1 and don’t forget the colon!) on its own line. Then, iterate through the recipes in that test case; output “Yes” if it can be made with the ingredients remaining or “No” if it cannot. There should be no blank lines between test cases.
样例输入 Copy
1
5 3
1 apples
3 onions
2 eggs
5 beans
1 pepper
3
1 apples
1 onions
4 beans
1
2 beans
1
1 oranges
样例输出 Copy
Case 1:
Yes
No
No

思路

模拟

#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
int n,I,r,p,q,t;
string s,str;
int nums[80];string tt[80];
int main() {
    scanf("%d",&n);
    for(int ii=1; ii<=n; ii++) {
        printf("Case %d:\n",ii);
        scanf("%d%d",&I,&r);
        map<string,int>mp;
        for(int i=1; i<=I; i++) {
            cin>>p>>s;
            mp[s]=p;
        }
        for(int i=1; i<=r; i++) {
            scanf("%d",&t);
            int flag=1;
 
            for(int j=1; j<=t; j++) {
                cin>>q>>str;
                nums[j]=q;
                tt[j]=str;
                if(q==0) {
                    ;
                } else {
                    if(mp[str]==0) {
                        flag=0;
                    } else {
                        if(mp[str]-q<0)
                            flag=0;
                        else {
                            ;// mp[str]-=q;;
                        }
                    }
                }
            }
            if(flag) {
                for(int j=1; j<=t; j++) {
                    mp[tt[j]]-=nums[j];
                }
                printf("Yes\n");
            } else
 
            {
                printf("No\n");
            }
 
        }
    }
    return 0;
}

问题 M: Addition

时间限制: 1 Sec 内存限制: 128 MB
题目描述
How high can you count?
Given a number, print one number higher.
输入
The first value of the input will be a number n, which will be the number of test cases. The next n lines will contain a single integer.
All supplied values will fit into a signed 32 bit integer variable.
输出
For each test case, print the number one higher than the input value.
All output values will fit into a signed 32 bit integer variable.
样例输入 Copy
3
-1
0
1
样例输出 Copy
0
1
2

思路

签到

#include<cstdio>
int n,p;
int main() {
    scanf("%d",&n);
    while(n--) {
        scanf("%d",&p);
        printf("%d\n",p+1);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值