2021年度训练联盟热身训练赛第二场
B.
题意:给定缩写词以及空格后的完整词段,然后给出要拓写的段落,输出相应的扩展文本(段落),以便O博士可以轻松阅读。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s,b[1010];
map<string ,string>mp;
map<string ,bool>w;
getchar();
for(int i=0;i<n;i++)
{
cin>>s;
getchar();
getline(cin,b[i]);
mp[s]=b[i];
w[s]=true;
}
int t;
cin>>t;
string x;
getchar();
for(int i=0;i<t;i++)
{
char c='\0';
while(c!='\n'){
cin>>x;
c=getchar();//保留回车符
if(mp.count(x)!=1)cout<<x<<c;
else
{
cout<<mp[x]<<c;
}
}
//cout<<endl;
}
}
D. Soccer Standings
https://ac.nowcoder.com/acm/contest/12794/D
题目内容:
Soccer fever has gripped the world once again, and millions of people from dozens of countries will be glued to their TV sets for the World Cup. Being an enterprising sort, you’ve started up your own internet World Cup Soccer Channel for streaming matches online. Recently you came up with the idea of filling up the time between matches by having a couple of ‘experts’ offer critical analysis of games. For this purpose, you have devised a unique ranking system for soccer teams, which you must now implement. The Problem: Given a list of teams and a list of match scores, you must compute several quantities for each team. These are: the total number of goals scored over all their games, the total number of goals scored against them (goals allowed, for short), the number of wins, draws and losses, and the number of points scored so far. Points are to be computed as follows: winning a match nets a team 3 points, losing gets them nothing. In the event of a tie, both teams get 1 point. In addition to this, you must order the teams correctly according to your new system. Teams are ordered according to points, from highest to lowest. In the event of a tie in points, the team that has a higher goal difference comes first. The goal difference is defined as the total number of goals scored by the team minus the total number of goals scored against them. If there is still a tie (i.e., two or more teams have the same points and the same goal differences), the team with higher total goals scored comes first. If even this is tied, the team whose name comes first in alphabetical order goes first. 输入描述: The first input line contains a positive integer, n, indicating the number of data sets to be processed. The first line of each data set consists of two positive integers T (T ≤ 30) and G (G ≤ 400) – the number of teams in this group and the total number of games played by them. The next line contains T unique names separated by single spaces. Each name is a single uppercase word with no more than 15 characters. Each of the next G input lines will contain the results of a match. Each line is of the form . For example, “Greece 2 Nigeria 1” indicates that Greece and Nigeria played a game with score 2-1. All four terms will be separated by single spaces. 输出描述: At the beginning of output for each data set, output “Group g:” where g is the data set number, starting from 1. Next you should print a single line for each team, ordering teams as mentioned above. For each team, the line you print should be of the form “ ”. These items should be separated by single spaces. Leave a blank line after the output for each data set. 输入 2 2 1 KASNIA LATVERIA KASNIA 0 LATVERIA 1 4 6 ENGLAND USA ALGERIA SLOVENIA ENGLAND 1 USA 1 ALGERIA 0 SLOVENIA 1 SLOVENIA 2 USA 2 ENGLAND 0 ALGERIA 0 SLOVENIA 0 ENGLAND 1 USA 1 ALGERIA 0 输出 Group 1: LATVERIA 3 1 0 0 1 0 KASNIA 0 0 1 0 0 1 Group 2: USA 5 1 0 2 4 3 ENGLAND 5 1 0 2 2 1 SLOVENIA 4 1 1 1 3 3 ALGERIA 1 0 2 1 0 2
看了n遍才懂的题意:给出n个队伍和m场比赛,每场比赛有两个队伍,获胜的加3分,平局各加一分,输了0分,每行给出两个球队名称及他们各自的进球数,求n个球队的总分,获胜,输掉,以及平局的场次,还有自己的进球数和对方的进球数。
思路:模拟,用结构体记录两队的名称,总得分,赢得的场数,输掉的场数,平局的场数,自己的进球数,对方的进球数,并初始化为0,输入两队的进球数,各自加上对应的进球数,失球数,在比较两队的进球数,计算得分,赢得场次,输的场次,平局数
代码:
#include<bits/stdc++.h> using namespace std; struct group { int points,win,loss,draw,jin,shi;//总得分,赢得场数,输得场数,平局数,进球数,失球数即对方进球数 string name; }s[1000]; bool cmp(group a,group b) { if(a.points!=b.points)return a.points>b.points; else if(a.points==b.points&&(a.jin-a.shi)!=(b.jin-b.shi))return (a.jin-a.shi)>(b.jin-b.shi); else if(a.jin!=b.jin)return a.jin>b.jin; else return a.name<b.name; } int main() { int n; cin>>n; for(int i=1;i<=n;i++) { int t,g; cin>>t>>g; getchar(); for(int j=0;j<t;j++) { string a; cin>>a; s[j].name=a; s[j].points=s[j].win=s[j].loss=s[j].draw=s[j].jin=s[j].shi=0;//初始化为0 } for(int l=0;l<g;l++) { string a,b; int c,d; cin>>a>>c>>b>>d; for(int j=0;j<t;j++) { if(s[j].name==a) { s[j].jin+=c; s[j].shi+=d; if(c==d) { s[j].draw++; s[j].points++; } else if(c>d) { s[j].win++; s[j].points+=3; } else { s[j].loss++; } } if(s[j].name==b) { s[j].jin+=d; s[j].shi+=c; if(c==d) { s[j].draw++; s[j].points++; } else if(c<d) { s[j].win++; s[j].points+=3; } else { s[j].loss++; } } } } sort(s,s+t,cmp); cout<<"Group "<<i<<":"<<endl; for(int j=0;j<t;j++) { cout<<s[j].name<<" "<<s[j].points<<" "<<s[j].win<<" "<<s[j].loss<<" "<<s[j].draw<<" "<<s[j].jin<<" "<<s[j].shi<<endl; } cout<<endl; } }
E:NIH Budget
https://ac.nowcoder.com/acm/contest/12794/E
题目内容:
链接: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 150 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 输出 复制 Budget #1: Maximum of 2000 lives saved. Budget #2: Maximum of 500 lives saved. Budget #3: Maximum of 0 lives saved.
题意:给出n种病,每种有4个方案,分别写明了花费及对应的获救人数,一共有m钱,问最多可以就多少人,一种只能花一次
思路:分组背包
(01背包:有n种物品,有一个容量为m的背包,每种可选可不选,求背包所能放的最大价值;
for(int i=1;i<=n;i++) for(int j=m;j>=1;j--) if(j>=a[i].p ) f[j]=max(f[j-a[i].p]+a[i].v,f[j]);
该题:有n组物品,每组4种,有一个为m容量的背包,每组物品中最多选一种,问最多可放多大容量。因为每组有4种,所以要加一层循环。
代码:
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; for(int i=1;i<=t;i++) { int n,m; cin>>n>>m; int a[110][10],b[110][10]; for(int j=0;j<n;j++) { for(int l=0;l<4;l++) { cin>>a[j][l]>>b[j][l]; } } int s[100010]; memset(s,0,sizeof(s)); for(int j=0;j<n;j++) { for(int l=m;l>=0;l--) { for(int q=0;q<4;q++) { if(l>=a[j][q]) s[l]=max(s[l],s[l-a[j][q]]+b[j][q]); } } } cout<<"Budget #"<<i<<": Maximum of "<<s[m]<<" lives saved."<<endl<<endl; } }
A.
内容:
链接:https://ac.nowcoder.com/acm/contest/12794/A 来源:牛客网 Professor Boolando can only think in binary, or more specifically, in powers of 2. He converts any number you give him to the smallest power of 2 that is equal to or greater than your number. For example, if you give him 5, he converts it to 8; if you give him 100, he converts it to 128; if you give him 512, he converts it to 512. The Problem: Given an integer, your program should binarize it. 输入描述: The first input line contains a positive integer,n, indicating the numberof values to binarize. The values are on the followingninput lines, one per line. Each input will contain an integer between2 and 100,000 (inclusive). 输出描述: At thebeginning of each testcase, output “Inputvalue:v”wherevis the input value. Then,on the next output line, print the binarized version. Leave a blank line after the output for each test case. 示例1 输入 复制 3 900 16 4000 输出 复制 Input value: 900 1024 Input value: 16 16 Input value: 4000 4096
题意:给出一个数n,求大于或等于它的最小2的幂数
k<<n=k*2^n-----用于求二的n次幂数与k的乘积
代码:
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int k=1; while(k<=n) { k<<=1; } cout<<"Input value: "<<n<<endl; cout<<k<<"\n\n"; } }
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!
题意:有n个盘子,围成一圈,C可以在两个盘子间移动时间为0.5s,他会使盘子以p度每秒开始转动,盘子会以每秒5度的减速度降速,在盘子速度为0时C就要过去将其速度再次转为p,判断是否可以使n个盘子会保持转动。
思路:C的移动时间为0.5s,所以盘子在该时间降速2.5,直接用p/2.5看可以移动多少次,再与n比较,注意n为1时的情况。
代码:
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; for(int i=1;i<=n;i++) { int num,v; cin>>num>>v; cout<<"Circus Act "<<i<<":"<<endl; if(v/2.5>=num||num==1) { cout<<"Chester can do it!"<<"\n\n"; } else { cout<<"Chester will fail!"<<endl<<endl; } } }

浙公网安备 33010602011771号