2017World Final 签到题

来源:互联网 发布:软件开发咨询 编辑:程序博客网 时间:2024/06/05 11:49

2017 World Final落下了帷幕,虽然没有机会去现场,但一边看直播,一边场外做题还是 蛮有感觉的,水了两道签到题,成就满满,毕竟我也是ac了World Final的人了。那就让我们来看一下这两道签到题吧


I.Secret Chamber at Mount Rushmore


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.

Input

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.

Output

For each pair of words, display yes if the two words match, and no otherwise.

Sample Input 1Sample Output 1
9 5c ti rk po cr ot et fu hw pwe wecan thework peopleit ofout the
yesnonoyesyes
Sample Input 2Sample Output 2
3 3a cb aa baaa abcabc aaaacm bcm
yesnoyes

思路:字符串转换问题,已知一些转换方式和原字符串,判断能否转化为现在的字符串。

这就需要先建图,用bool数组存储所有转化能否实现。由于转化是单向的,因此,这是个有向图,不能用并查集处理。于是想到利用Floyd思想,立方遍历求出图内点的可达性,最后一次遍历字符串判断。

最后,注意一下自回路就好了


#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>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<m;i++)        {            char a,b;            getchar();            scanf("%c %c",&a,&b);            com[(int)(a-'a')][(int)(b-'a')] = true;        }        for(int i=0;i<26;i++)        {            com[i][i] = true;        }        /*for(int i=0;i<26;i++)        {            for(int j=0;j<26;j++)            {                cout << com[i][j];            }            cout << endl;        }*/        for(int u=0;u<26;u++)        {           for(int v=0;v<26;v++)            {                for(int w=0;w<26;w++)                {                    if(com[v][u]&&com[u][w])                    {                        com[v][w] = true;                    }                }            }        }        /*for(int i=0;i<26;i++)        {            for(int j=0;j<26;j++)            {                cout << com[i][j];            }            cout << endl;        }*/        while(n--)        {            char a1[55],a2[55];            scanf("%s%s",a1,a2);            int l = strlen(a1);            if(l != (int)(strlen(a2)))            {                printf("no\n");                continue;            }            int i;            for(i=0;i<l;i++)            {                if(!com[(int)(a1[i]-'a')][(int)(a2[i]-'a')])                {                    break;                }            }            if(i==l)            {                printf("yes\n");            }            else            {                printf("no\n");            }        }    }    return 0;}


最后,附一发ac的图,毕竟WF




E.Need for Speed


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.

Input

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.

Output

Display the constant c in miles per hour. Your answer should have an absolute or relative error of less than 10e-6.

Sample Input 1Sample Output 1

3 54 -14 010 3
3.000000000
Sample Input 2Sample Output 2
4 105 32 23 63 1
-0.508653377
思路:这题是个简单的数学计算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<n*d=1e6, 于是可以直接将右端点fi设为1e7

3.终止条件:浮点数判断大小容易出问题,因此,直接利用循环次数进行判断退出。


#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>#include <cmath>using namespace std;const int maxn = 1e3+10;double d[maxn],s[maxn];int main(){    int n;    double t;    while(scanf("%d%lf",&n,&t)!=EOF)    {        double st = -1e7;        double fi = 1e7;        for(int i=0;i<n;i++)        {            scanf("%lf%lf",&d[i],&s[i]);            if(st < d[i]/t - s[i])            {                st = d[i]/t - s[i] ;            }            /*if(st > s[i])            {                st = s[i];            }*/        }        //st = -st + 1e-10;        int ti = 0;        while(ti < 200)        {            ti ++;            double mid = (fi + st)/2;            //cout << st << "*" << mid << "*" << fi << endl;            double tempt = 0.0;            for(int i=0;i<n;i++)            {                /*if(s[i]+mid < 1e-6)                {                    st = mid;                    break;                }*/                tempt += d[i]/(s[i] + mid);            }            /*if(fabs(tempt-t) < 1e-12)            {                fi = mid;                break;            }*/            if(tempt > t)            {                st = mid;            }            else            {                fi = mid;            }        }        printf("%.9f\n",st);    }    return 0;}


原创粉丝点击