传送门

怎么说呢,这次的训练赛的题目难度不是很大,但就是字多

A Binarize It

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

打表+二分查找的签到题

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,m,cnt;
int a[N];
void solve()
{cin>>n;printf("Input value: %d\n",n);int t=lower_bound(a+1,a+cnt+1,n)-a;cout<<a[t]<<endl<<endl;
}
signed main()
{a[1]=1;for(cnt=2;a[cnt-1]<=1000000;cnt++)  a[cnt]=a[cnt-1]<<1;int T;cin>>T;while(T--)  solve();return 0;
}

B g2g c u l8r

题目描述
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
输出
复制
hi
how are you
you tell me
you are late
i am done
see you later

字符串的map使用,注意一下空格就行

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
map < string , string > mp;
string s[N];
void solve()
{cin>>n;while(n--){string s1,s2;cin>>s1;getchar();getline(cin,s2);mp[s1]=s2;}cin>>m;getchar();while(m--){int t=1;string s1;getline(cin,s1);s1+=" ";int sz=s1.size();for(int i=0;i<sz;i++){if(s1[i]==' ')  t++;else  s[t]+=s1[i];}for(int i=1;i<t;i++){if(mp[s[i]]=="")  cout<<s[i]<<" ";else  cout<<mp[s[i]]<<" ";s[i]="";}cout<<endl;}
}
signed main()
{solve();return 0;
}

C Tip to be Palindrome

题目描述
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

输入一个数n,求一个数m,m>=0.2*n,且m+n为回文数,求最小的m

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
bool check(int x)
{int a[15];int t=0;while(x){a[++t]=x%10;x/=10;}for(int i=1;i<=t;i++)  if(a[i]!=a[t-i+1])  return 0;return 1;
}
void solve()
{cin>>n;printf("Input cost: %d\n",n);m=ceil(n*0.2);for(;;m++){if(check(n+m))  break;}cout<<m<<" "<<n+m<<endl;puts("");
}
signed main()
{int T;cin>>T;while(T--)  solve();return 0;
}

D Soccer Standings

题目描述
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
<country_1> <score_1> <country_2> <score_2>. 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.

示例1
输入
复制
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

模拟题,求得分,获胜比赛数,失败比赛数,平局数,进球数,被进球数

然后按照得分高低,进球数减被进球数的高低,进球数高低,名字顺序排序

大模拟

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e3+5;//?????????? 4e8
int n,m;
struct node
{string s;int a[10];
}e[N];
map < string , int > mp;
bool cmp(node i,node j)
{if(i.a[1]!=j.a[1])  return i.a[1]>j.a[1];if(i.a[5]-i.a[6]!=j.a[5]-j.a[6])  return i.a[5]-i.a[6]>j.a[5]-j.a[6];if(i.a[5]!=j.a[5])  return i.a[5]>j.a[5];return i.s<j.s;
}
void solve()
{cin>>n>>m;memset(e,0,sizeof(e));mp.clear();for(int i=1;i<=n;i++){string s1;cin>>s1;mp[s1]=i;e[i].s=s1;}while(m--){string s1,s2;int x,y;cin>>s1>>x>>s2>>y;int t1=mp[s1];int t2=mp[s2];e[t1].a[5]+=x,e[t1].a[6]+=y;e[t2].a[5]+=y,e[t2].a[6]+=x;if(x==y){e[t1].a[1]++;e[t2].a[1]++;e[t1].a[4]++;e[t2].a[4]++;}else if(x>y){e[t1].a[1]+=3;e[t1].a[2]++;e[t2].a[3]++;}else{e[t1].a[3]++;e[t2].a[1]+=3;e[t2].a[2]++;}}sort(e+1,e+n+1,cmp);for(int i=1;i<=n;i++){cout<<e[i].s;for(int j=1;j<=6;j++)  cout<<" "<<e[i].a[j];cout<<endl;}cout<<endl;
}
signed main()
{int T;cin>>T;for(int index=1;index<=T;index++){printf("Group %d:\n",index);solve();}return 0;
}

E NIH Budget

题目描述
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 than150million,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.

就是一个分组背包,但是因为只有4个组,依然相当于01背包,所以可以过

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-10
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e3+5;//?????????? 4e8
int n,m;
int indx;
int f[M],w[10][N],v[10][N];
void solve()
{cin>>n>>m;for(int i=1;i<=n;i++){for(int j=1;j<=4;j++)  cin>>v[j][i]>>w[j][i];}memset(f,0xcf,sizeof(f));f[0]=0;for(int i=1;i<=n;i++)  for(int j=m;j>=0;j--)  for(int k=1;k<=4;k++)if(j>=v[k][i])  f[j]=max(f[j],f[j-v[k][i]]+w[k][i]);int ans=0;for(int i=0;i<=m;i++)  ans=max(ans,f[i]);printf("Budget #%d: Maximum of %d lives saved.\n\n",indx,ans);
}
signed main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;for(indx=1;indx<=T;indx++){solve();}return 0;
}

F Interstellar Love

题目描述
After two years of sharing a bedroom with you in a college dorm, Jeff finally has his own room. Excited about inviting girls over to his room, he ponders over what decorations the fairer sex will enjoy.1 He decides upon setting up a “fake” planetarium with a black ceiling and glow in the dark stars that form constellations. Unfortunately, in his haste, he has made several “errors” in setting up his constellations. See, everyone knows that constellations don’t have cycles in them. Instead, whenever we visually connect the stars together with lines, a tree is always formed. (A cycle is formed when you can start at a star and, using connections, go to one or more other stars and then end up at the original star.)

Since you were Jeff’s roommate for two years, you figure you’ll help him fix his constellations. Your job will be twofold: to count the number of constellations Jeff has, and to report how many of them have cycles and need to be fixed. A constellation consists of multiple stars that are all connected to one another (directly or indirectly). A constellation that needs fixing is simply one that has a cycle.

The Problem:

Given several configurations of stars and connections between stars, determine how many constellations are defined in each configuration and how many need fixing.

输入描述:
The first input line contains a positive integer, n (n ≤ 100), indicating the number of night skies to consider. The first line of each night sky contains two positive integers, s (s ≤ 1000), representing the number of stars for this night sky, and c (c ≤ 10000), representing the total number of connections between pairs of stars for this night sky. Each of the following c input lines contains two distinct positive integers representing a single connection between two stars. The stars in each test case will be numbered 1 through s, inclusive. A connection is considered bidirectional, thus, if a is connected to b, b is connected to a. Assume that all connections in a data set are distinct, i.e., no duplicates. Also assume that there will never be a connection from a star to itself.

1 This is based on a true story. The person who is the inspiration for this story did, in fact, major in Planetary Science and make his room’s ceiling a relatively accurate depiction of the night sky, as seen in Boston circa 1995.

输出描述:
For each test case, just output a line with the following format:
Night sky #k: X constellations, of which Y need to be fixed.
where k is the number of the night sky, starting at 1, X is the total number of constellations described in that night sky, and Y is how many of those constellations contain a cycle.
Leave a blank line after the output for each test case.

示例1
输入
复制
3
5 4
1 2
1 3
2 3
4 5
8 5
1 2
3 4
6 7
6 8
8 7
3 2
1 2
1 3
输出
复制
Night sky #1: 2 constellations, of which 1 need to be fixed.

Night sky #2: 3 constellations, of which 1 need to be fixed.

Night sky #3: 1 constellations, of which 0 need to be fixed.
说明
Note:In the second example, star number 5 is not connected to any other stars. This staron its own is NOT counted as a constellation, leaving only {1,2}, {3,4}and {6,7,8} as constellations, of which only the last one needs tobe fixed.

怎么样说呢,找环,和没有环的图,注意

1、一个点不能算作图

2、以下情况为一个环,因此要用dfs来做

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
map < int , int > mp,mp2;
int indx;
int fa[N];
struct node
{int ver,next;
}e[N];
int tot,head[N];
int flag;
int v[N];
int get(int x)
{if(fa[x]==x)  return fa[x];return fa[x]=get(fa[x]);
}
void add(int x,int y)
{e[++tot].ver=y;e[tot].next=head[x];head[x]=tot;
}
void dfs(int x,int pre)
{for(int i=head[x];i;i=e[i].next){int y=e[i].ver;if(y==pre)  continue;if(v[y]){flag=1;continue;}v[y]=1;dfs(y,x);}
}
void solve()
{int ans=0,cnt=0,ret=0;mp.clear();memset(v,0,sizeof(v));tot=0;memset(head,0,sizeof(head));cin>>n>>m;for(int i=1;i<=n;i++)  fa[i]=i;for(int i=1;i<=m;i++){int x,y;scanf("%d%d",&x,&y);if(x==y)  continue;add(x,y);add(y,x);mp[x]=1;mp[y]=1;int xx=get(x);int yy=get(y);if(xx==yy)  mp2[xx]=1;fa[xx]=yy;}for(int i=1;i<=n;i++)  if(fa[i]==i&&mp[i]){flag=0;v[i]=1;dfs(i,i);if(flag)  cnt++;}for(int i=1;i<=n;i++){if(!mp[i])  ret++;if(fa[i]==i)  ans++;}printf("Night sky #%d: %d constellations, of which %d need to be fixed.\n\n",indx,ans-ret,cnt);
}
signed main()
{int T;cin>>T;for(indx=1;indx<=T;indx++){solve();}return 0;
}

G Plate Spinning

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!

就是比较2.5*(n-1)与m大小,但n=1时要特判

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-10
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
void solve()
{cin>>n>>m;if(n==1){puts("Chester can do it!");puts("");return;}n*=10,m*=10;int p=(n-1)*5/2;if(p>m)  puts("Chester will fail!");else  puts("Chester can do it!");puts("");
}
signed main()
{int T;cin>>T;for(int indx=1;indx<=T;indx++){printf("Circus Act %d:\n",indx);solve();}return 0;
}

H The Eternal Quest for Caffeine

Like most engineering students, Jason relies on caffeine, soda in particular, to get him through long nights in the lab. He’s not too picky about the brand; as long as it’s fizzy, loaded with caffeine, and not the “diet” version, he’s happy. When the new Harris Engineering Center opened on the UCF Campus, he was pleased to see a soda machine on every floor. Not just any soda machine, either. These machines are the fancy kind that display all of the soda stock arranged in rows stacked on top of each other (like most snack machines). When a soda is purchased, a conveyor belt rises to the correct row, where the soda is surgically picked up by a robotic clasp that can travel left and right on the conveyor. The conveyor then descends to the vending slot, where the clasp gently deposits the soda. Finally, the slot unlocks and tilts forward, allowing the buyer to retrieve his or her soda. Engineering perfection! And as a bonus, the soda isn’t subjected to all the usual mechanical clatter that causes it to fizz over when it’s opened.

Unfortunately, these elaborate machines seem to have a propensity for component failure. On one soda mission from his lab, Jason discovered that the vending slot was broken on the machine on his floor, which prevented it from working altogether. He went to the next floor down and saw that that machine’s vending slot was fine, but the conveyor was broken. He went down to the ground floor and saw that that machine was in perfect order, but only had caffeine free diet soda! At this point, Jason devised a plan. It’s a simple matter for him to open up the working machine and harvest the parts he needs for the machine upstairs, then to hike back upstairs and repair the machine that houses the soda he needs. Sure, hecouldjust take the soda he wants while the machine is open, but what fun would that be?

The one issue with this plan is that while Jason does enjoy the engineering challenge, he hates the walking between various broken machines each time he goes to get a coke, so he’s asked you, a computer science student and fellow resident of the Harris Engineering Center to help. He can devise a way to monitor each machine in the building and ascertain what parts are working. He needs you to write a program that will allow him to get all the parts he needs from the various machines in the building, traveling up and down as few flights of stairs as possible (he doesn’t trust the elevators because he’s never been allowed to see how they work). Assume he can carry an unlimited number of parts. He also wants this algorithm to work for various kinds of coke machines and various buildings, in case the vendors decide to change out their machines one day, or the administration decides to relocate the EECS department again (you still can assume that there will always be exactly one coke machine on each floor).

The Problem:

Given the number of floors in the building, the number of parts required for a working machine, a description of the working parts in each machine in the building, and whether or not each machine has the desired kind of soda, determine the smallest number of floor changes required to

assemble a working machine that is already stocked with the desired soda. Jason will always start from his lab and return there after getting his soda.

输入描述:
There will be multiple sodamachine arrangements to process. Inputwill begin with three integers,N,F, andP(1 ≤N,F,P≤ 10), each separated by a singlespace with no leading or trailingspaces.Ndescribes the number of floors in the building,Findicates which floor Jason’s lab is on, andPindicates the number of different partsin each of the building’s soda machines.

On the nextNlines will be a set of integersfollowed by a single letter. Eachline describes the soda machine onone floor (starting with the ground floor, and proceeding upward in order). The characterson a line are separated by a single space, with no leading or trailing spaces.The first integers on each line will beS(0 ≤S≤P), indicating the number of workingparts in the machine.Sintegerswill follow, each indicating a working part in the machine (each of these integers will be unique and will bebetween 1 andP). Finally, there willbe a single character “Y” or “N”, where “Y” indicates that themachine has a kind of soda that Jason likes, and “N” indicates that it does not.

End of input will beindicated by a value of 0forN,F, andP. This case should not be processed.

输出描述:
For each soda machinearrangement, print the case number (starting with 1) and a single integer indicating the minimum number of timesJason will have to travel up or down a staircase to collect the parts he needs to repair a soda machine, get a sodathat he wants, and return to his lab. Ifthere is no way for Jason to get a soda, print “Impossible” instead of the integer. Leavea blank line after the outputfor each test case.

示例1
输入
复制
4 2 5
5 1 2 3 4 5 N
4 1 2 3 5 Y
4 1 2 4 5 Y
5 1 2 3 4 5 Y
4 2 6
1 1 Y
2 2 3 Y
3 1 4 5 Y
0 Y
0 0 0
输出
复制
Test case #1: 2

Test case #2: Impossible

怎么说呢模拟题,注意一下细节就行了

比赛的时候因为字太多,没敢做

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-10
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,f,p;
int indx;
int ans;
vector < int > a[N];
int c[N],vis[N];
void init()
{for(int i=1;i<=n;i++)  a[i].clear();memset(c,0,sizeof(c));ans=1<<30;
}
bool check(int l,int r)
{memset(vis,0,sizeof(vis));for(int i=l;i<=r;i++){int sz=a[i].size();for(int j=0;j<sz;j++)  vis[a[i][j]]=1;}for(int i=1;i<=p;i++)  if(!vis[i])  return 0;return 1;
}
void solve()
{indx++;init();for(int i=1;i<=n;i++){int m;scanf("%d",&m);while(m--){int x;scanf("%d",&x);a[i].push_back(x);}char ch;cin>>ch;if(ch=='Y')  c[i]=1;}for(int i=1;i<=f;i++)  for(int j=f;j<=n;j++)  if(check(i,j))  for(int k=i;k<=j;k++)  if(c[k])ans=min(ans,min(f-i+j-i+j-k,j-f+j-i+k-i)+abs(k-f));printf("Test case #%d: ",indx);if(ans==1<<30)  printf("Impossible");else  printf("%d",ans);puts("");puts("");
}
signed main()
{while(cin>>n>>f>>p&&n&&f&&p)  solve();return 0;
}

I Pegasus Circle Shortcut

For the UCF High School Programming Tournament, the judges were located in the Engineering building, and most of the teams were in the Classroom building, which is on the other side of Pegasus Circle.

Chris was walking to the Classroom building for the first time, and was joined by Jeremy, who had made the hike a couple of times already.

“Jeremy, is it faster to stay on the circle, or to cut through the middle using the boardwalks that go to the Student Union?” asked Chris.

“I don’t know.” Jeremy answered. “I think it’s about the same, but it might be slightly faster to use the walkways.”

“Well, if it’s about the same, let’s stick to the circle. I don’t want to be attacked by squirrels.”

The Problem:

Given two points on a circle, and two paths to get from one to the other—one following the perimeter of the circle, and the other by a sequence of connected straight line segments through the interior of the circle—determine the shorter of the two paths.

输入描述:
The input will contain multiple test cases, each consisting of two lines. The first line of each testcase contains six floating-point numbers:xc,yc,xs,ys,xf, andyf, where (xc,yc) is the center point of the circle, (xs,ys) is the start point for both paths (e.g., the Engineering building), and (xf,yf) is the finish point for both paths (e.g., the Classroom building).The circle will always have a radius greater than 1, and the start and finish points are both guaranteed to be at distinct pointson its perimeter, with an accuracy of at least 3 placesafter the decimal.The path along the perimeter is always in the directioncounter-clockwise around the circle.

The second line of each test case will start with an integer,n(1≤n≤ 10), followed by n pairs of floating-point numbers,x1,y1,x2,y2, …xn, and yn, where each pair (xi,yi) is a point inside the circle. The interior path traveled will be from point (xs,ys) to point (x1,y1), then from (x1,y1) to (x2,y2), then from (x2,y2) to (x3,y3), …, then from (xn,yn) to (xf,yf).

The last test case will be followed by a line containing six zeros. All numbers on an input line will beseparated from each other by one space, with no extra spaces at the beginning or end of lines. Assumethat all the input floating point numbers will be less than 1000.0 and greater than

-1000.0, with at most 6 places after the decimal.

输出描述:
For each test case in the input, output a line in either the format

Case #n:Stick to the Circle.

if the perimeter path is shorter,or

Case #n:Watch out for squirrels!

if the interior pathis shorter, where n is the num berof the input test case, starting at 1.

Assume that the two paths will not be equal, i.e., it is guaranteed that the two distances will not be equal. In particular, assume that the two paths will differ in length by 0.001 or more.

Leave a blank line after the output for each test case.

示例1
输入
复制
5.0 5.0 10.0 5.0 5.0 10.0
6 8.5 4.7 6.9 5.0 3.6 6.5 4.2 7.1 4.2 8.3 4.7 8.8
2.0 8.0 0.5 16.87412 7.5 0.8761
2 3.25 9.25 7.0 7.0
0 0 0 0 0 0
输出
复制
Case #1: Stick to the Circle.

Case #2: Watch out for squirrels!

计算几何,比较这样两条路径的长度(一条在圆周,一条是从圆内穿过的折线),说到底就是计算几何推公式,以下两种形式皆可


比赛时候还推了会儿公式,中学数学全还给老师了

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
#define double long double
#define eps 1e-10
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
struct node
{double x,y;
}a[N],o,s,e;
int indx;
double qr(double x1,double y1,double x2,double y2)
{return sqrt((x1-x2)*(x1-x2)+(y2-y1)*(y2-y1));
}
void solve()
{while(1){indx++;double ans=0,cnt=0;cin>>o.x>>o.y;cin>>s.x>>s.y;cin>>e.x>>e.y;double r=qr(o.x,o.y,s.x,s.y);if(fabs(o.x)+fabs(o.y)+fabs(s.x)+fabs(s.y)+fabs(e.x)+fabs(e.y)<1e-9)  return;cin>>n;for(int i=1;i<=n;i++)  scanf("%llf%llf",&a[i].x,&a[i].y);a[0]=s,a[n+1]=e;for(int i=0;i<=n;i++)  ans+=qr(a[i].x,a[i].y,a[i+1].x,a[i+1].y);cnt=2*asin(qr(s.x,s.y,e.x,e.y)/(2.0*r))*r;if(cnt+eps<ans)  printf("Case #%d: Stick to the Circle.\n\n",indx);else  printf("Case #%d: Watch out for squirrels!\n\n",indx);}
}
signed main()
{solve();return 0;
}

J Lowest Common Ancestor

题目描述
Perfect binary trees are one of the coolest structures that computer scientists study. They have a lot of properties that make them very nice to work with. One of the nicest properties is that they can just be described by a single integerngiving the depth of the tree. For instance, the perfect binary tree forn= 3 looks like:

In general, a perfect binary tree with depthnwill have exactly 2n+1 – 1 nodes, and can be numbered by following the pattern seen above (there are of course other ways to number the nodes of the tree, but this is the scheme we will use in this problem).

A common question that arises when dealing with trees is the query of the lowest common ancestor (commonly called LCA) of two nodes in the tree. Formally, the LCA ofxandyis the nodezof greatest depth in the tree such thatzis an ancestor ofxandy. Nodeais an ancestor of nodecifcexists in the sub-tree rooted at nodea. Notice that 1 is trivially a common ancestor of any two nodes in the tree, but is not always thelowestcommon ancestor. For instance, the common ancestors of nodes 7 and 12 are 1 and 3, and 3 is the LCA since it is the node of greatest depth. The LCA of 2 and 13 is node 1, and the LCA of 5 and 11 is node 5. The definition of LCA guarantees that the LCA of any two nodes will always be unique.

The Problem:

Given two nodes in the tree using the numbering scheme shown above, determine the LCA of the two nodes.

输入描述:
Input will begin with apositive integer,T≤ 2∙106,indicating the number of test cases. Thiswill be followed byTtest cases, each on a separate inputline. Each test case will contain twospace separated integers,XandY, represented in hexadecimal.XandYwill each contain at most 1000characters from the set {0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f}, where a-frepresent 10-15, respectively. You are todetermine the LCA ofXandY.

Note: The hexadecimal (base 16) numberdndn-1···d1d0 is converted to a decimal number (base 10) by the followingformula:d0·160 +d1·161 + ··· +dn-1·16n-1 +dn·16n.

输出描述:
For each case, output a singleline:

Case#x:y

wherexis the case number beginning with 1, andyis the LCA in hexadecimal with no leading 0’s. Leave a blankline after the output for each testcase.

示例1
输入
复制
7
7 c
2 d
b 5
10 11
a020fac a030ccf
12afcdb 12afcdc
100000000 fffffffff
输出
复制
Case #1: 3

Case #2: 1

Case #3: 5

Case #4: 8

Case #5: 501

Case #6: 255f9b

Case #7: 1

完满二叉树给定两个节点求最近公共祖先,其中树的节点由十六进制表示

先将十六进制转化为二进制形式储存,再求去掉前导0的最长前缀,求得后,把这个最长前缀转化为十六进制输出(可以添加前导0)

如图,以第五组样例为例
有点类似高精度运算,但细节较多

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=2*1e4+5;//?????????? 4e8
int n,m;
char s1[N],s2[N];
int a1[N],a2[N];
int c[N];
int b1[N],b2[N];
int v[10];
int d1[N],d2[N];
void init()
{memset(a1,0,sizeof(a1));memset(a2,0,sizeof(a2));memset(a1,0,sizeof(d1));memset(a2,0,sizeof(d2));memset(a1,0,sizeof(b1));memset(a2,0,sizeof(b2));memset(c,0,sizeof(c));
}void solve()
{init();int cnt=1,ret=0,ans=0;int t1=0,t2=0;scanf("%s%s",s1+1,s2+1);int sz1=strlen(s1+1);int sz2=strlen(s2+1);for(int i=1;i<=sz1;i++){if(s1[i]>='0'&&s1[i]<='9')  a1[i]=s1[i]-'0';else  a1[i]=s1[i]-'a'+10;}for(int i=1;i<=sz2;i++){if(s2[i]>='0'&&s2[i]<='9')  a2[i]=s2[i]-'0';else  a2[i]=s2[i]-'a'+10;}for(int i=1;i<=sz1;i++){for(int j=1;j<=4;j++){v[j]=a1[i]&1;a1[i]>>=1;}reverse(v+1,v+4+1);for(int j=1;j<=4;j++)  b1[++t1]=v[j];}for(int i=1;i<=sz2;i++){for(int j=1;j<=4;j++){v[j]=a2[i]&1;a2[i]>>=1;}reverse(v+1,v+4+1);for(int j=1;j<=4;j++)  b2[++t2]=v[j];}int s1=1,s2=1;while(!b1[s1])  s1++;while(!b2[s2])  s2++;int n1=0,n2=0;for(int i=s1;i<=t1;i++)  d1[++n1]=b1[i];for(int i=s2;i<=t2;i++)  d2[++n2]=b2[i];int flag=0;for(int i=1;i<=min(n1,n2);i++)  if(d1[i]!=d2[i]){flag=1;cnt=i-1;break;}if(!flag)  cnt=min(n1,n2);reverse(d1+1,d1+cnt+1);while(cnt%4!=0)  d1[++cnt]=0;reverse(d1+1,d1+cnt+1);ans=1;/*for(int i=1;i<=cnt;i++){cout<<d1[i];if(i%4==0)  cout<<" ";}cout<<endl;*/for(int i=1;i<=cnt;i++){if(i%4==1)  c[ans]+=d1[i]*8;else if(i%4==2)  c[ans]+=d1[i]*4;else if(i%4==3)  c[ans]+=d1[i]*2;else{c[ans]+=d1[i];ans++;}}for(int i=1;i<ans;i++)if(c[i]<10)  printf("%d",c[i]);else  printf("%c",c[i]+'a'-10);
}
signed main()
{int T;cin>>T;for(int index=1;index<=T;index++){printf("Case #%d: ",index);solve();puts("");puts("");}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年度训练联盟热身训练赛第二场(ICPC North Central NA Contest 2019,南阳师范学院),签到题ABCDEFGIJ

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

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

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

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

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

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

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

最新文章

  1. 实际工程里的长宽设定
  2. 找不到类型{0} 它在 ServiceHost 指令中提供为 Service 特性值
  3. github使用-知乎的某小姐的一篇文章
  4. 数据挖掘算法_技术分享|大数据挖掘算法之KNNk近邻算法
  5. dedecms 漏洞_dedescan一款织梦漏洞扫描器
  6. 2018-2019-2 20175230 实验三《Java面向对象程序设计》实验报告
  7. Google 已经能用 AI 来预测你的航班是否延误了!
  8. HDU2152 Fruit【母函数】
  9. Dynamics CRM - 不同类型字段在 Plugin 里的赋值方式
  10. 【教程】合成方法的那些事儿(附加练习源文件)
  11. Java高级:面试题-1
  12. 基本知识 100176
  13. 改变世界的webp图片技术,节约你的流量和带宽
  14. 常见机器学习算法适合使用的业务场景汇总(1)
  15. HTML5期末大作业:在线电影网站设计——电影我不是药神响应式页播(4页) HTML+CSS+JavaScript HTML+CSS+JS网页设计期末课程大作业 web前端开发技术 web课程设计
  16. 2017爱创课堂vue.js视频完整版
  17. 利用七牛存储7天远程自动备份LINUX服务器
  18. webp文件怎么打开?webp压缩工具推荐
  19. 2021年Java面经分享:java软件工程师证书多少钱
  20. python通过ssh连接linux,执行命令

热门文章

  1. 微信公众平台错误代码40164的解决方案
  2. 最近公共祖先三种算法详解 + 模板题 建议新手收藏 例题: 信息学奥赛一本通 祖孙询问 距离
  3. 计算机行业的权威奖项
  4. n阶台阶,每次上1阶或者2阶,一共共有多少种
  5. echarts 3d 散点图 颜色条件查询
  6. ps4刷linux,PS4刷新GPU固件有惊喜 可运行Vulkan与Linux
  7. C语言存款利息的计算。有1000元,想存5年,可按以下5种办法存
  8. 大供应链应用与分析之企划
  9. Conda安装本地package
  10. STC89C52系列单片机内部资源——串口通信