2017 World Final落下了帷幕,虽然没有机会去现场,但一边看直播,一边场外做题还是 蛮有感觉的,水了两道签到题,感觉挺好。那就让我们来看一下这两道签到题吧
By now you have probably heard that there is a spectacular stone sculpture featuring four famous U.S. presidents at Mount Rushmore. However, very few people know that this monument contains a secret chamber. This sounds like something out of a plot of a Hollywood movie, but the chamber really exists. It can be found behind the head of Abraham Lincoln and was designed to serve as a Hall of Records to store important historical U.S. documents and artifacts. Historians claim that the construction of the hall was halted in 1939 and the uncompleted chamber was left untouched until the late 1990s, but this is not the whole truth.
In 1982, the famous archaeologist S. Dakota Jones secretly visited the monument and found that the chamber actually was completed, but it was kept confidential. This seemed suspicious and after some poking around, she found a hidden vault and some documents inside. Unfortunately, these documents did not make any sense and were all gibberish. She suspected that they had been written in a code, but she could not decipher them despite all her efforts.
Earlier this week when she was in the area to follow the ACM-ICPC World Finals, Dr. Jones finally discovered the key to deciphering the documents, in Connolly Hall of SDSM&T. She found a document that contains a list of translations of letters. Some letters may have more than one translation, and others may have no translation. By repeatedly applying some of these translations to individual letters in the gibberish documents, she might be able to decipher them to yield historical U.S. documents such as the Declaration of Independence and the Constitution. She needs your help.
You are given the possible translations of letters and a list of pairs of original and deciphered words. Your task is to verify whether the words in each pair match. Two words match if they have the same length and if each letter of the first word can be turned into the corresponding letter of the second word by using the available translations zero or more times.
The first line of input contains two integers m (1<=m<=500) and n (1<=n<=50),where m is the number of translations of letters and n is the number of word pairs. Each of the next m lines contains two distinct space-separated letters a and b, indicating that the letter a can be translated to the letter b.Each ordered pair of letters (a,b) appears at most once. Following this are n lines, each containing a word pair to check. Translations and words use only lowercase letters ‘a’–‘z’, and each word contains at least 1 and at most 50 letters.
For each pair of words, display yes if the two words match, and no otherwise.
Sample Input 1 | Sample Output 1 |
---|---|
|
|
Sample Input 2 | Sample Output 2 |
---|---|
|
|
思路:字符串转换问题,已知一些转换方式和原字符串,判断能否转化为现在的字符串。
这就需要先建图,用bool数组存储所有转化能否实现。由于转化是单向的,因此,这是个有向图,不能用并查集处理。于是想到利用Floyd思想,立方遍历求出图内点的可达性,最后一次遍历字符串判断。
最后,注意一下自回路就好了
/*
Author:Owen_Q
*/
#include
using namespace std;
bool com[26][26];
int main()
{
int n,m;
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(com,false,sizeof(com));
for(int i=0;i
最后,附一发ac的图,毕竟WF
Sheila is a student and she drives a typical student car: it is old, slow, rusty, and falling apart. Recently, the needle on the speedometer fell off. She glued it back on, but she might have placed it at the wrong angle. Thus, when the speedometer reads s, her true speed is s+c, where c is an unknown constant (possibly negative).
Sheila made a careful record of a recent journey and wants to use this to compute c. The journey consisted od n segments. In the ith segment she traveled a distance of di and the speedometer read si for the entire segment. This whole journey took time t. Help Sheila by computing c.
Note that while Sheila’s speedometer might have negative readings, her true speed was greater than zero for each segment of the journey.
The first line of input contains two integers n (1<=n<=1000), the number of sections in Sheila’s journey, and t (1<=t<=1e6), the total time. This is followed by n lines, each describing one segment of Sheila’s journey. The ith of these lines contains two integers di (1<=di<=1000) and si (|si|<=1000), the distance and speedometer reading for the ith segment of the journey. Time is specified in hours, distance in miles, and speed in miles per hour.
Display the constant c in miles per hour. Your answer should have an absolute or relative error of less than 10e-6.
Sample Input 1 | Sample Output 1 |
---|---|
|
|
Sample Input 2 | Sample Output 2 |
---|---|
|
|
思路:这题是个简单的数学计算t = sum(si/(di+c))求c,由于每项中都含有c,所以不是很好求。于是,想到二分,就可以从以下三个方面来研究:
1.左端点: si/(di+c)<=t ==> c>=si/t-di, 由于全部满足,因此只要设立左端点st = max(si/t-di)。【注意是最大值哦】
2.右端点:n*d/c>1 ==> c 3.终止条件:浮点数判断大小容易出问题,因此,直接利用循环次数进行判断退出。 #include