【20160327】"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛A.B.C.D.E.G题解

纪念今年3月27日的个人校赛(QAQ接下来是流水账)。

一开始只是为了抢最佳新人,后来莫名其妙打了亚军

A题读题加敲题再加上提交只用了2分37秒,和FB相差25秒........................

B题当时模拟好难啊,只是一个字符串翻转的问题,敲了20多分钟.............................(今天补题好像5分钟就够了啊...........)

C题当时模拟也好难啊,迷迷糊糊的一边调试一遍搞,敲了好久好久好久啊.........................(今天补题好像十分钟就够了啊............)

D题是一个传递闭包,记得寒假的时候有一道并查集的题因为点比较少,我用Floyd算法的思想过的啊.当时还不知道这个叫求传递闭包,只是感觉自己对一个算法的掌握度有所提升,当时好有成就感......(正式赛上看到这个题并且读完之后心想,这尼玛不就是给我粗的题嘛QWQ).............................(记得当时还是敲了很久,九个月相差的代码实现程度也是很大的啊)

E题是一个递归分形的问题,队长非常喜欢这种题啊,当时看到这个题的时候我是一脸懵逼,不过推一推还是搞出来了.(这个题是当时唯一罚了时的题啊.PE了一发.......)

G题是一个煞笔题啊...............问构成一颗树要最少画几笔,记得寒假也是搞了并查集相关的欧拉路问题啊,这尼玛统计起点个数/2不就可以了嘛.

然后就没有然后了......................搞完G之后还剩下23分钟看了看之后的题,好像也没有自己能粗的题了.............

然后刷新榜单.................尼玛我第二啊!最佳新人是保住了,这尼玛第二的排名让我自己都有点猝不及防...............

再之后就安安静静的等待结束.............................

九个月之后现在想想当时的情景都是历历在目啊...................

-----------------------------------------------------------------------------------------------------------------------------------纪念20160327个人校赛人品爆发


Julyed
Time Limit: 1000 MS Memory Limit: 131072 K
Total Submit: 12(6 users) Total Accepted: 6(6 users) Rating:  Special Judge: No
Description
Julyed is a smart pretty girl and tomriddly is her boyfriend. Now tomriddly is on the bus to the airport to see Julyed. He still needs X minutes to get the airport. But Julyed will arrive in Y minutes. What’s worse is that the terrible traffic! The bus will have to stop here for Z minutes! Julyed will happily wait for tomriddly at most 10 minutes, but will be mad after waiting at least 30 minutes. What will happened when they meet?
Input

Multiple test cases. The first line contains a positive integer T (T <= 100), indicates the number of test cases.

Each test case contains three non-negative integers X, Y, Z (X, Y, Z <= 60) descripted as above in one line.

Output

One line per case.

If Julyed will be happy, output “memeda”(without quotes).

If Julyed will be mad, output “QAQ”(without quotes).

Otherwise output how long will Julyed wait.

Sample Input

4

10 10 0

10 10 10

10 5 10

60 10 60

Sample Output

memeda

memeda

15

QAQ


Source
"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛

A.题目大意:主人公要去约会,妹子会在Y时刻到,主人公还需要X单位时间才能到达站点,因为堵车,车还要等待Z单位时间。如果妹纸等待时间小于等于10分钟,输出memeda,如果大于等于30分钟,那么输出QAQ,否则输出妹纸总共需要等待的时间(包括堵车时间)。


思路:模拟即可。


Ac代码:

#include
#include
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        if(x+z-y<=10)printf("memeda\n");
        else if(x+z-y<30)printf("%d\n",x+z-y);
        else printf("QAQ\n");
    }
}

Reversed Word
Time Limit: 1000 MS Memory Limit: 131072 K
Total Submit: 11(6 users) Total Accepted: 6(6 users) Rating:  Special Judge: No
Description

Some aliens are learning English. They have a very strange way in writing that they revered every word in the sentence but keep all the words in common order. For example when they want to write “one two three”, they will write down “eno owt eerht”.

Now we’ve got some sentence written by these aliens, translate them! And maybe we will know some of their secrets!

Input

Multiple test cases. The first line contains a positive integer T (T <= 1000), indicates the number of test cases.

For each test cases, there will be one line contains only lower case letters and spaces. The length of each line will be no more than 10000. Test cases which are longer than 5000 will be less than 50. Continuous letters are seen as a word, words are separated by spaces. There won’t be two adjacent spaces in the input. Space won’t be the first or the last character.

Output
One line per case, the translated sentence.
Sample Input

2

eno owt eerht

abcde

Sample Output

one two three

edcba

Source
"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛

B.题目大意:给你一个字符串,将其中的单词都翻转。


思路:模拟即可。


Ac代码:

#include
#include
#include
using namespace std;
char a[100500];
char ans[100500];
int main()
{
    int t;
    scanf("%d",&t);
    getchar();
    while(t--)
    {
        gets(a);
        int f=0;
        int n=strlen(a);
        int flag=0;
        int cont=0;
        for(int i=0;i

Calendar
Time Limit: 1000 MS Memory Limit: 131072 K
Total Submit: 3(2 users) Total Accepted: 2(2 users) Rating:  Special Judge: No
Description

Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:

Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.

Input

In the first line, the is a integer T (1T100), which means there T cases of this problem.

In every case, the input has two format:

1):yyyy1:mm1:dd1 yyyy2:mm2:dd2

2):yyyy1:mm1:dd1 day

If the format is the 1) type, your task is to calculate how many days are between yyyy1:mm1:dd1 and yyyy2:mm2:dd2.

Others, your task is output the date after the date yyyy1:mm1:dd1, and the days between them is day. The format of the answer is yyyy:mm:dd.

1000  yyyy  9999 and yyyy:mm:dd is a legal date.

0day, we can ensure the answer of the second type is satisfied with 1000  yyyy  9999.

Output
For every case, display the answer of this question per line.
Sample Input

4

1900:01:01 2038:12:31

1900:01:01 50768

1996:03:09 1991:11:12

1991:11:12 1579

Sample Output

50768

2038:12:31

1579

1996:03:09

Source
"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛

C.题目大意:给你两个字符串,第一个保证是一个时间,第二个字符串如果是一个整数contz,那么对应求出第一个时间之后contz天的时间表示。如果第二个也是时间,那么对应求出两个时间相差了多少天。


思路:模拟即可,注意闰年的处理。


Ac代码:

#include
#include
#include
using namespace std;
int month[13]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char a[50000];
int main()
{
    int t;
    scanf("%d",&t);

    while(t--)
    {
        int year;
        int yue;
        int ri;
        scanf("%d:%d:%d",&year,&yue,&ri);
        scanf("%s",a);
        if(a[4]==':')
        {
            int year2=(a[0]-'0')*1000+(a[1]-'0')*100+(a[2]-'0')*10+(a[3]-'0')*1;
            int yue2=(a[5]-'0')*10+(a[6]-'0')*1;
            int ri2=(a[8]-'0')*10+a[9]-'0';
            if(year2<=year)
            {
                if(year2month[yue])
                {
                    if(ri==29&&yue==2&&(year%4==0&&year%100!=0||year%400==0))
                    {
                        continue;
                    }
                    yue++;
                    ri=1;
                }
                if(yue>12)
                {
                    year++;
                    yue=1;
                }
                if(year==year2&&yue==yue2&&ri==ri2)
                {
                    printf("%d\n",i);
                    break;
                }
            }
        }
        else
        {
            int contz=0;
            int n=strlen(a);
            for(int i=0;imonth[yue])
                {
                    if(ri==29&&yue==2&&(year%4==0&&year%100!=0||year%400==0))
                    {
                        continue;
                    }
                    yue++;
                    ri=1;
                }
                if(yue>12)
                {
                    year++;
                    yue=1;
                }
            }
            printf("%d:%02d:%02d\n",year,yue,ri);
        }
    }
}

Find Your Teacher
Time Limit: 1000 MS Memory Limit: 131072 K
Total Submit: 2(2 users) Total Accepted: 2(2 users) Rating:  Special Judge: No
Description
You just finished your exam, you felt terrible because you might fail the exam. But your teacher was so kind that he might let you pass the lesson if you called him and begged for passing. Unfortunately, you didn’t have your teacher’s phone number! You began to ask whoever probably had the number, if they didn’t have, they would ask their classmates. Would you finally get the number?
Input

The first line contains an integer T (1 <= T <= 20), indicates the number of test cases.

For each test case, the first line is two positive integers, n (n <= 50), m (m <= 2000). n is the number of people who will appear in the problem, you are indexed as 1 and your teacher is indexed as n.

Then m lines follows, each line contains two integers x, y (1 <= x, y <= n), means x have the phone number of y.

Output
For each test case, if you could finally got your teacher’s number, output “^_^”, “T_T” the otherwise.
Sample Input

2

5 5

1 2

1 3

2 3

2 4

4 5

4 3

1 2

3 4

4 1

Sample Output

^_^

T_T

Source
"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛


D.题目大意:我是编号1的人,老师是编号n的人,一共有m个有向关系,表示编号为x的人有编号为y的人的电话号码,问我能否要到老师的电话号码。


思路:


1、观察到n并不大,那么我们直接求一个传递闭包即可。传递闭包直接用Floyd实现即可。


2、核心思想:如果j有i的电话号码,i有k的电话号码,那么j就能有k的电话号码。


Ac代码:

#include
#include
using namespace std;
int a[55][55];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        memset(a,0,sizeof(a));
        scanf("%d%d",&n,&m);
        for(int i=0;i

Invitations
Time Limit: 1000 MS Memory Limit: 131072 K
Total Submit: 1(1 users) Total Accepted: 1(1 users) Rating:  Special Judge: No
Description

interesting party. Almost everyone in the world wants to take part in his party. Now, he needs to draw some beautiful invitations for the people who will take part in his party. PY is so busy that he gives this mission to you. Plenty of girls wait to receive PY’s invitations, so you’d better to draw them quickly.

You should only use ‘o’ or ‘ ’ to print the triangle just like this:

 o

o o

And just as the recursion depth increased, the triangle that you need to output will be bigger and bigger. More details please to see the sample output.

Input
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. The only line of each test case contains an integer N (1 <= N <= 10) indicates the recursion depth.
Output
For each test case draw an outline of the triangle. Align your output to the left, that is, print the bottom leftmost slash into the first column. The output must not contain any trailing blanks. Print an empty line after each test case.
Sample Input

3

1

2

3

Sample Output

 o

o o

   o

  o o

 o   o

o o o o

       o

      o o

     o   o

    o o o o

   o       o

  o o     o o

 o   o   o   o

o o o o o o o o
Source
"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛

E.题目大意:给你一个数n,输出对应规模的图形。


思路:对应我们考虑一个点的递归规律,因为同理,所以我们就能处理三个点的递归规律。

相当于原题的题解(介个很详细):http://blog.csdn.net/mengxiang000000/article/details/50999115?locationNum=2&fps=1

Ac代码:(注意数组别开小了)

#include
#include
#include
#include
using namespace std;
char ans[3005][3005];
void Dfs(int x,int y,int cur)
{
    ans[x][y]='o';
    if(cur==1)return ;
    Dfs(x,y,cur-1);
    Dfs(x+(int)pow(2,cur-1),y-(int)pow(2,cur-1),cur-1);
    Dfs(x+(int)pow(2,cur-1),y+(int)pow(2,cur-1),cur-1);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        memset(ans,' ',sizeof(ans));
        Dfs(0,(int)pow(2,n)-1,n);
        Dfs(1,(int)pow(2,n)-2,n);
        Dfs(1,(int)pow(2,n),n);
        int r;
        for(int i=0;i<3002;i++)
        {
            int flag=0;
            for(int j=3002;j>=0;j--)
            {
                if(ans[i][j]=='o')
                {
                    flag=1;
                    ans[i][j+1]='\0';
                    break;
                }
            }
            if(flag==0)
            {
                r=i;
                break;
            }
        }
        for(int i=0;i


Tree Painting
Time Limit: 1000 MS Memory Limit: 131072 K
Total Submit: 1(1 users) Total Accepted: 1(1 users) Rating:  Special Judge: No
Description
Give you a tree, can you draw the tree with minimum strokes without overlapping? Noted that it is ok if two strokes intersect at one point. Here we define a tree as a connected undirected graph with N points and N-1 edges.
Input

The input data has several test cases. The first line contains a positive integer T (T<=20), indicates the number of test cases.

For each case:

The first line contains an integers N (2<=N<=10^5), indicates the number of points on the tree numbered from 1 to N.

Then follows N-1 lines, each line contains two integers Xi, Yi means an edge connected Xi and Yi (1<=Xi, Yi<=N).

Output
For each test case, you should output one line with a number K means the minimum strokes to draw the tree.
Sample Input

2

2

1 2

5

1 2

1 5

2 3

2 4

Sample Output

1

2

Source
"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛

G.题目大意:给你N个点构成的一颗树,对应有N-1条边,我们最少画几笔就能将这个图画出来。


思路:


1、考虑到一条无向欧拉路径的特点:

①起点和终点的度数为1

②除起点和终点外的度数都是2


2、一颗树可以抽象的看成一堆欧拉路径堆叠到一起的图形,那么对应其起点和终点无论怎样堆叠一定保证其是奇数度.

那么我们只要统计出有几个起点/终点那么就能确定一共有多少条欧拉路径。

那么ans=奇数度的点的个数/2.


Ac代码:

#include
#include
using namespace std;
int degree[545405];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(degree,0,sizeof(degree));
        int n;
        scanf("%d",&n);
        for(int i=0;i







你可能感兴趣的:(水题,模拟,搜索,最短路及其拓展)