链接:https://ac.nowcoder.com/acm/contest/12794/B
来源:牛客网

题目描述

According to the national statistics, a teenager sends/receives 100+ text messages a day. Dr. Orooji’s teenage children are no exception but the problem is Dr. O (an old-fashioned, face-to- face communicator) has difficulty reading text messages full of abbreviations (short-hands) sent to him by his children. Dr. O needs your help reading these text messages.

The Problem:

Given the list of abbreviations and a paragraph, you are to expand the text (paragraph) so that Dr. O can read it easily.

输入描述:

 

The first input linecontains an integer,n (1 ≤ n ≤ 20),indicating the number of abbreviations. Theseabbreviations are on the followingninputlines, one per line. Each input linestarts in column 1 and containsan abbreviation (1-5 characters, consisting of only lowercaseletters and/or digits). The abbreviation is followed by exactly one space, and this isfollowed by the expanded version ofthe abbreviation (1-50 characters, consisting of only lowercase letters and spaces; assume the expandedversion does not start or end with aspace and contains no multiple consecutive spaces between words).Assume that all abbreviations are distinct, i.e., no duplicates.

The list of abbreviations isfollowed by a positive integer,p,indicating the number of input lines containingthe paragraph to be expanded. Theparagraph is on the followingpinputlines. Assume these input linesdo not exceed column 50, donot start or end with a space, and each line contains at least one word. The paragraph will contain only lowercaseletters, digits, and spaces. Assume that there will not be multipleconsecutive spaces in theinput paragraph.

A word is defined as aconsecutive sequence of letters/digits.  Assume that a word will be entirely on oneinput line, i.e., a word isnot broken over two or more lines.

输出描述:

 

Each line of the inputparagraph must be on one line of output. Theinput line must be printed in theoutput exactly the same (spacing). Theonly exception is that each abbreviation must be replaced by its expanded version, i.e., when an abbreviation isfound in the input, its expanded version must beoutput.

Note that an abbreviationmust match a word completely and not just part of a word. For example,if u is an abbreviation for “you”, then u must appear as a word by itself in the paragraph

in order to be replaced,i.e., if the abbreviation is part of a word in the paragraph (e.g.,the paragraph containsthe word buy or ugly or you),the u in these words should not be replaced.

示例1

输入

复制8 g2g got to go g good c see l8 late l8r later d i am done u you r are 6 hi how r u you tell me you are l8 d c u l8r

8
g2g got to go
g good
c see
l8 late
l8r later
d i am done
u you
r are
6
hi
how r u
you tell me
you are l8
d
c u l8r

输出

复制hi how are you you tell me you are late i am done see you later

hi
how are you
you tell me
you are late
i am done
see you later

g2g c u l8r
返回全部题目

题意理解:
这就是一个使用map存储缩写和对应的全称的题目,处理好输入输出的就可以了。需要注意的是cin的输入字符串方式在遇到空格或者换行都会停止,这时候需要用到getchar()吸收一下。

#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//提议理解:就是将缩写的文字,先存起来,然后读入缩写后,输出整个字符春
//因为有对应的关系,所以要使用map

string a,b,c;
map<string,string> mp;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        cin>>a;
        getchar();
        getline(cin,b);
        mp[a]= b;
    }
    int m;
    cin>>m;
    while(m)
    {
        cin>>c;
        if(mp.count(c))
            cout<<mp[c];
        else
            cout<<c;
        char ch = getchar();
        if(ch == '\n') m--;
        cout<<ch;
    }
    return 0;
}

Tip to be Palindrome
题目链接:https://ac.nowcoder.com/acm/contest/12794/C

题目描述
One of the cool UCF CS alumni is Dr. Greg, The Palindrome Tipper. A palindrome is a string
that reads the same forward and backward, e.g., madam, abba, 3, 44, 525.
One cool thing about Dr. Greg is that he leaves at least 20% tip when he eats out, e.g., if the meal is 30, Dr. Greg leaves 30, Dr. Greg leaves 6 (30*.20) for tip. If the tip (20%) is not a whole dollar amount, he rounds up the tip to make it a whole number. For example, if the meal is 12, a 20% tip would be12,a202.40 (12*0.20) but Dr. Greg would leave $3 for tip.
Another cool thing about Dr. Greg is that he is a palindrome guru. If his total bill (meal plus tip) is not a palindrome, he will increase the total (by adding to the tip) to make the total a palindrome. He will, of course, add the minimum needed to make the total a palindrome.
The Problem:
Given Dr. Greg’s meal cost, your program should determine the tip amount for him (according to his rules) and the total bill.

输入描述:
The first input line contains a positive integer, n, indicating the number of times Dr. Greg ate out. The meal costs are on the following n input lines, one per line. Each input will contain an integer between 5 and 10000 (inclusive).

输出描述:
At the beginning of each test case, output “Input cost: c” where c is the input cost. Then, on the next output line, print the tip amount and the total bill, separated by one space. Leave a blank line after the output for each test case.

示例1
输入
2
12
84
输出
Input cost: 12
10 22

Input cost: 84
17 101

#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//题意理解:就是输入的cost,求出tip=cost*0.2向上取整,tip+cost如果
//不是回文数,就一直向上加,直到是一个回文数

//判断是否为回文数
bool judge(int n)
{
    int i = n;
    int m = 0;
    while(i>0)
    {
        m = m*10+i%10;
        i/=10;
    }
    return m == n;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int m;
        cin>>m;
        int num = ceil(m*0.2);
        while(judge(m+num)==0)
            num++;
        cout<<"Input cost: "<<m<<endl;
        cout<<num<<" "<<num+m<<endl;

}
    return 0;
}

链接:https://ac.nowcoder.com/acm/contest/12794/E
来源:牛客网

题目描述

Recently, a job for an algorithms specialist opened up at NIH. You never thought you’d be using your expertise in algorithms to save lives, but now, here is your chance! While the doctors are very good in carrying out medical research and coming up with better cures for diseases, they are not so good with numbers. This is where you come in.

You have been tasked to allocate money for all disease research at NIH. The interesting thing about disease research is that the number of lives saved doesn’t linearly increase with the amount of money spent, in most cases. Instead, there are “break-points”. For example, it might be the case that for disease A, we have the following break-points:

Research Funding

Lives Saved

10 million

5

50 million

100

100 million

1000

250 million

1100

If you spend more money than one breakpoint and less than another, the number of lives saved is equal to the amount saved for the previous breakpoint. (In the above example, if you spent 150million,you’dstillonlysave1000lives,andifyouspentanyamountmorethan150 million, you’d still only save 1000 lives, and if you spent any amount more than 150million,you’dstillonlysave1000lives,andifyouspentanyamountmorethan250 million, you’d still save 1100 lives.)

The doctors have figured out charts just like this one for all the diseases for which they do research.   Given these charts, your job will be to maximize the number of lives saved spending no more than a particular budget.

The Problem:

Given several charts with information about how much has to be spent to save a certain number of lives for several diseases and a maximum amount of money you can spend, determine the maximum number of lives that can be saved.

输入描述:

The first input line contains a positive integer, n (n ≤ 100), indicating the number of budgets to consider.  The first line of each budget contains two positive integers, d (d ≤ 10), representing the number  of  diseases  for which there is data and B (B ≤ 100000), the total budget, in millions of dollars.  The following d lines contain information about each of the d diseases.  Each of these lines will contain exactly four ordered pairs of positive integers separated by spaces.  Each pair will  represent  a  dollar  level  (in  millions)  followed  by  the number  of  lives  saved  for  that  dollar

level of funding.  Each of the pairs will be separated by spaces as well.  Each of these values will be less than or equal to 100,000.  Assume that the dollar levels on an input line are distinct and in increasing  order,  and  that  the  number  of  lives  saved  on  an  input line  are  also distinct  and  in increasing order.

输出描述:

For each test case, just output a line with the following format:
Budget #k: Maximum of x lives saved.
where k is the number of the budget, starting at 1, and x is the maximum number of lives saved in that budget.
Leave a blank line after the output for each test case.

示例1

输入

复制3 2 2000 10 5 50 100 100 1000 250 1100 100 1 200 2 300 3 1900 1000 3 100 10 100 40 200 70 300 100 500 5 1 25 2 35 3 50 4 200 10000 300 20000 400 30000 500 40000 1 10 100 2 200 3 300 5 400 6

3
2 2000
10 5 50 100 100 1000 250 1100
100 1 200 2 300 3 1900 1000
3 100
10 100 40 200 70 300 100 500
5 1 25 2 35 3 50 4
200 10000 300 20000 400 30000 500 40000
1 10
100 2 200 3 300 5 400 6

输出

复制Budget #1: Maximum of 2000 lives saved. Budget #2: Maximum of 500 lives saved. Budget #3: Maximum of 0 lives saved.

Budget #1: Maximum of 2000 lives saved.Budget #2: Maximum of 500 lives saved.Budget #3: Maximum of 0 lives saved.

代码如下:

#include<bits/stdc++.h>
#include<cstring>#define ll long long
#define mem(a) memset(a,0,sizeof(a))using namespace std;
//分组背包问题
/*
题意:t组测试,每组测试的第一行输入多少组病例(n),和预算m
接下来有n行,每行输入改组病例的4个治疗方案(花费p元,救v人),每组病例只能
选择一种治疗方案,求能救的最大人数。
思路:01背包的变形分组背包问题
01背包:有n中物品,有一个容量为m的背包,每种可选可不选,求背包所能放的
最大价值;
for(int i=1;i<=n;i++)
{for(int j=k;j>=1;j--){if(j>=a[i].p) f[j] = max(f[j-a[i].p]+a[i].v,f[j]);}
}for(int i=1;i<=n;i++)
{for(int j=k;j>=1;j--){for(int m=1;m<=4;m++)if(i>=a[i][m].p) f[j] = max(f[j-a[i][m].p]+a[i][m].v,f[j]);}
}分组背包:有n组物品,每组四种。有一个容量为m的背包,每组物品中最多选一个,
求背包所能放的最大价值;
区别:每一组中有不同的物品,体积,价值不固定,在枚举物品时,极爱一层循环,
枚举组里的所有物品。
for(int i=1;i<=n;i++)
{for(int j=k;j>=1;j--){for(int m=1;m<=4;m++)if(i>=a[i][m].p) f[j] = max(f[j-a[i][m].p]+a[i][m].v,f[j]);}
}*///一维代码
struct gg{int p,v;
}a[12][8];int f[1000050];int main()
{int t,m,n,cnt = 1;cin>>t;while(t--){mem(f);cin>>n>>m;for(int i=1;i<=n;i++){for(int j=1;j<=4;j++){cin>>a[i][j].p>>a[i][j].v;}}for(int i=1;i<=n;i++)for(int j=m;j>=1;j--)for(int k=1;k<=4;k++){if(j>=a[i][k].p) f[j] = max(f[j-a[i][k].p]+a[i][k].v,f[j]);}printf("Budget #%d: Maximum of %d lives saved.\n\n",cnt++,f[m]);}
}

G. Plate Spinning,模拟,贪心分析
链接:https://ac.nowcoder.com/acm/contest/12794/G
来源:牛客网

题目描述
Plate spinning is a circus act where a person spins various objects(usually plates and bowls) on poles without them falling off. It involves spinning an object and then returning back to the object in order to add additional speed to prevent it from falling off the pole.
In this problem you will simulate plate spinning where the plates are placed in a circular arrangement (much like the picture to the right). You must determine whether Chester the Clown will be able to maintain the plates spinning or whether one or more plates will end up falling off poles.

The Problem:
Given the number of poles/plates in a circular arrangement and the speed up to which Chester the Clown spins the plates (in degrees per second), determine if he can maintain the act or if plates will fall. For this problem, we will assume that plates degrade (slow down) at a constant rate of 5-degrees-per-second per second and that Chester can move from one pole to any other pole in 0.5 seconds. In addition, assume that Chester can spin up a plate with zero time cost.
A plate falls off when its rate is zero. However, if Chester arrives at a plate exactly at the same time the rate reaches zero, Chester will spin the plate and prevents it from falling, i.e., the rate must reach zero before Chester arrives for the plate to fall.

输入描述:
The first line of the input will be a single positive integer, a, representing the number of acts to evaluate. Each of the following a lines will represent a single act and will contain two positive integers, n and p, separated by a single space, where n represents the number of poles (1 ≤ n ≤ 15) and p represents the speed up to which Chester spins a plate (0 < p ≤ 100) in degrees per second. At the very beginning of each act, all plates are initially spinning at this speed, and he is currently at a plate in the circle (he can choose which plate to start at in order to maximize his chance of success).

输出描述:
For each circus act, output a header “Circus Act i:” on a line by itself where i is the number of the act (starting with 1). Then, on the next line, output “Chester can do it!” if Chester can maintain the act, or output “Chester will fail!” if one or more plates will fall. Leave a blank line after the output for each test case.

示例1
输入
复制
3
2 10
5 7
2 12
输出
复制
Circus Act 1:
Chester can do it!

Circus Act 2:
Chester will fail!

Circus Act 3:
Chester can do it!
代码如下:

#include<bits/stdc++.h>
#include<cstring>#define ll long long
#define mem(a) memset(a,0,sizeof(a))using namespace std;
int main()
{int T;cin>>T;for(int i=1;i<=T;i++){cout<<"Circus Act "<<i<<":"<<endl;int n,p;cin>>n>>p;double c = 2.5*n;if(n==1) cout<<"Chester can do it!"<<endl;else{if(p>=c)cout<<"Chester can do it!"<<endl;elsecout<<"Chester will fail!"<<endl;}cout<<endl;}return 0;
}

2021年度训练联盟热身训练赛第二场相关推荐

  1. 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FFT)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FF ...

  2. 2021年度训练联盟热身训练赛第五场

    2021年度训练联盟热身训练赛第五场 链接:https://ac.nowcoder.com/acm/contest/13926 A Binary Seating #include<bits/st ...

  3. 2021年度训练联盟热身训练赛第八场

    目录 2021年度训练联盟热身训练赛第八场 A-Fire on Field 题意 思路 代码 B-Gene Tree 题意 思路 代码 I-Thread Knots 题意 思路 代码 J-Triang ...

  4. 2021年度训练联盟热身训练赛第三场赛后补题

    2021年度训练联盟热身训练赛第三场赛后补题 A Circuit Math [题目分析] [代码展示] B Diagonal Cut [题目分析] [代码展示] C Gerrymandering [题 ...

  5. 2021年度训练联盟热身训练赛第三场(待补)

    文章目录 前言 一.Circuit Math(后缀表达式---栈&&fgets) 二.Diagonal Cut(gcd最大公因数,数论) 三.expected primary-expr ...

  6. 2021年度训练联盟热身训练赛第二场(全)

    传送门 怎么说呢,这次的训练赛的题目难度不是很大,但就是字多 A Binarize It Professor Boolando can only think in binary, or more sp ...

  7. 2021年度训练联盟热身训练赛第二场(ICPC North Central NA Contest 2019,南阳师范学院),签到题ABCDEFGIJ

    A. Binarize It,简单枚举 链接:https://ac.nowcoder.com/acm/contest/12794/A 来源:牛客网 题目描述 Professor Boolando ca ...

  8. 【2021年度训练联盟热身训练赛第二场】Soccer Standings(python)

    import math import cmath import sys import string import bisect import heapq import copy from queue ...

  9. 【2021年度训练联盟热身训练赛第二场】Tip to be Palindrome(python)

    import math import cmath import sys import string import bisect import heapq import copy from queue ...

  10. 【2021年度训练联盟热身训练赛第二场】g2g c u l8r(python)

    import math import cmath import sys import string import bisect import heapq import copy from queue ...

最新文章

  1. ZooKeeper学习第二期--ZooKeeper安装配置
  2. 前端 css+js实现返回顶部功能
  3. python序列类型举例说明_Python基础__Python序列基本类型及其操作(1)
  4. 【推荐】ABAP select语句性能优化之高级教程
  5. phpredis中文手册——《redis中文手册》 php版
  6. 早起 - 对我影响最大的习惯
  7. 重新编译hadoop-2.7.2-src的native以支持Snappy解压压缩库
  8. 用protues作RC桥式振荡电路仿真,无法形成正弦波,求解惑
  9. android 联系人 字母索引,Android手机联系人带字母索引的快速查找
  10. 一个新手RHCE的酸甜苦辣
  11. linux C之srand函数
  12. 均值,期望,方差,标准差,协方差
  13. 【深度思考,极客大学Java进阶训练营
  14. 伴随着Web标准发展
  15. Summation of polynomials
  16. ubuntu mysql密码忘记了怎么办,ubuntu怎么查看mysql密码
  17. 利用Python基础代码语句,实现2G时代文字小游戏,世界如此简单!
  18. 虚拟页式存储管理——页面置换算法及其影响的缺页中断率
  19. 短视频的特点和分类——今抖云创
  20. JAVA:AudioFiction(有声小说)项目实现

热门文章

  1. word2013中如何去除尾注分隔符? 网上教程说是在普通视图下,而2013无此视图
  2. 小程序车牌键盘的实现
  3. Windows使用mitmdump踩过的坑
  4. 详解比springSecurity和shiro更简单优雅的轻量级Sa-Token框架,比如登录认证,权限认证,单点登录,OAuth2.0,分布式Session会话,微服务网关鉴权
  5. 数据库_初识mysql
  6. GOPRO 6 相关
  7. 欧几里德算法,扩展算法
  8. Apache Ftp Server 部署,它的帐号密码加密算法是什么呢?
  9. threshold计算机英语,计算机专业英语
  10. 计算机仿真技术教学大纲,《计算机仿真技术》教学大纲