山东省第七届ACM省赛 题解

Problem Description

Julyed is preparing for her CET-6. She has N words to remember, but there is only M days left. If she can’t remember all these words, she won’t pass CET-6. If she can’t pass CET-6, she will be unhappy. But if she remember too many words in one day, she will be unhappy, too. If she is unhappy, tomriddly will be unhappy. So she will remember as little words as she can in one day. For the happiness of both tomriddly and Julyed, how many words at most will Julyed remember in one day?

Multiple test cases. The first line is an integer T (T <= 10000), indicating the number of test cases.

Each test case is a line with two integers N, M (1 <= N, M <= 200), indicating the number of words to remember and the number of days left.

One line per case, an integer indicates the answer.

题解:水题
题目大意:小明一天背m个单词,一共n个单词,最少需要几天背完。

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    int n,m;
    while(cin>>t)
    {
        while(t--)
        {
            cin>>n>>m;
            if(m>=n)cout<<"1"<<endl;
            else
            {
                if(n%m==0)cout<<n/m<<endl;
                else cout<<n/m+1<<endl;
            }
        }
    }
    return 0;
}

http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/3561.html

Fibonacci

Problem Description

Fibonacci numbers are well-known as follow:

Now given an integer N, please find out whether N can be represented as the sum of several Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers.

Multiple test cases, the first line is an integer T (T<=10000), indicating the number of test cases.

Each test case is a line with an integer N (1<=N<=109).

One line per case. If the answer don’t exist, output “-1” (without quotes). Otherwise, your answer should be formatted as “N=f1+f2+…+fn”. N indicates the given number and f1, f2, … , fn indicating the Fibonacci numbers in ascending order. If there are multiple ways, you can output any of them.

100=3+8+89

题目大意:给一个数n,判断能否由斐波那契数组成n。

题解:思维题,打表找规律,斐波那契的变形

通过打表找出所有的斐波那契数。可以看出,对于每一个n都可以有斐波那契数组成,找到一个小于n的最大的斐波那契数x,让n减去x,直到n==0.。这个题在比赛的时候也打表了,但是没有找出规律来,最近又翻出来做一做,还是看了大牛的解析才知道的,至于怎么证明只这样的规律自己还是无从知晓的。通过这个题,自己知道罪域一些题还是要大胆的才结论的。

 

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int f[50];
int a[50];

int main()
{
    f[1]=1;
    f[2]=2;
    const int m=45;
    for(int i=3;i<=m;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    int t,n,k;
    cin>>t;
    while(t--)
    {
        cin>>n;
        k=n;
        int top=0;
        for(int i=m;i>=1;i--)
        {
            if(f[i]<=n)
            {
                a[top++]=f[i];
                n=n-f[i];
            }
        }
        if(n==0)
        {
            cout<<k<<"=";
            for(int i=top-1;i>=0;i--)
            {
                if(i==top-1)cout<<a[i];
                else cout<<"+"<<a[i];
            }
            cout<<endl;
        }
        else cout<<"-1"<<endl;
    }
    return 0;
}
///思维题,需要大胆的猜想结论,打表,规律

sdut-3562-proxy:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/3562.html

Because of the GFW (Great Firewall), we cannot directly visit many websites, such as Facebook, Twitter, YouTube, etc. But with the help of proxy and proxy server, we can easily get to these website.
You have a list of several proxy servers, some of them can be connected directly but others can’t. But you can visit proxy servers through other proxy server by a one-way connection. 
As we all know, the lag of internet visit will decide our feelings of the visit. You have a very smart proxy software which will find the least lag way to reach the website once you choose a directly reachable proxy server. 
You know the lag of every connection. The lag of your visit is the all the lags in your whole connection. You want to minimize the lag of visit, which proxy server you will choose?

Multiple test cases, the first line is an integer T (T <= 100), indicating the number of test cases.
The first line of each test case is two integers N (0 <= N <= 1000), M (0 <= M <= 20000). N is the number of proxy servers (labeled from 1 to N). 
0 is the label of your computer and (N+1) is the label of the server of target website.
Then M lines follows, each line contains three integers u, v, w (0 <= u, v <= N + 1, 1 <= w <= 1000), means u can directly connect to v and the lag is w.

An integer in one line for each test case, which proxy server you will choose to connect directly. You can only choose the proxy server which can be connected directly from your computer.
If there are multiple choices, you should output the proxy server with the least label. If you can’t visit the target website by any means, output “-1” (without quotes). If you can directly visit the website and the lag is the least, output “0” (without quotes).

0 1 10
1 2 1
2 4 4
0 3 2
3 2 1
3 4 7
0 2 10
0 1 5
1 2 4
2 1 7
0 2 1
0 1 2
1 2 1
0 2 10
0 1 2
1 2 1

题目大意:翻墙服务器的使用,有一台电脑0,想访问n这台电脑,但是有可能不能直接访问,需要间接的服务器,但是间接的服务器需要费用。那么问题来了,从0到n需要的最小花费是多少呢?输出最小花费的那条路径的和0相连的编号最小的那个点。如果最小的花费的路径时直接从0到n的话就输出0.

题解:两个条件的最短路问题

直接套用最短路的知识加上另一个条件就行,那么另一个条件怎么加的?先说另一个条件是当前点来自于哪一个和0相连的点。如果路径费用相同的话,当前点就赋值为和0肚的小的编号。

#include <iostream>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f

using namespace std;

int mp[1005][1005];
int dist[1005],vis[1005],pos[1005];
void spfa(int s,int e)
{
    for(int i=s; i<=e; i++)
    {
        dist[i]=INF;
        vis[i]=0;
    }
    queue<int>q;
    while(!q.empty())q.pop();
    dist[s]=0;
    vis[s]=1;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(int i=s; i<=e; i++)
        {
            if(mp[u][i]<INF&&u!=i)
            {
                if(dist[i]>dist[u]+mp[u][i])
                {
                    dist[i]=dist[u]+mp[u][i];
                    if(u!=s)pos[i]=pos[u];
                    if(!vis[i])
                    {
                        vis[i]=1;
                        q.push(i);
                    }
                }
                else if(dist[i]==dist[u]+mp[u][i]&&u!=s)
                {
                    if(pos[i]>pos[u])
                    {
                        pos[i]=pos[u];
//                        if(!vis[i])
//                        {
//                            vis[i]=1;
//                            q.push(i);
//                        }
                    }
                }
            }
        }
    }
    if(dist[e]<INF)
    {
        if(dist[e]==mp[s][e])printf("0\n");
        else
            printf("%d\n",pos[e]);
    }
    else printf("-1\n");
}
int main()
{
    int t;
    int s,e,n,m;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            int u,v,w;
            scanf("%d%d",&n,&m);
            s=0;
            e=n+1;
            for(int i=0; i<=n+1; i++)
            {
                for(int j=0; j<=n+1; j++)
                {
                    if(i==j)mp[i][j]=0;
                    else mp[i][j]=INF;
                }
            }
            for(int i=0; i<m; i++)
            {
                scanf("%d%d%d",&u,&v,&w);
                mp[u][v]=min(mp[u][v],w);///有向边
            }
            for(int i=1; i<=n+1; i++)
            {
                if(mp[s][i]<INF)
                {
                    pos[i]=i;
                }
            }
            spfa(s,e);
        }
    }
    return 0;
}
///稍微变形的最短路,注意建图的条件,有向边

 

sdut-3563-Swiss-system tournament:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/3563.html

A Swiss-system tournament is a tournament which uses a non-elimination format. The first tournament of this type was a chess tournament in Zurich in 1895, hence the name "Swiss system". The tournament will be held based on following rules.

2*N contestants (indexed 1, 2, ..., 2*N) will have R rounds matches. Before the first round, every contestant has an origin score. After every match, winner will get 1 score and loser will get 0 score. Before and after every round, contestants will be sorted by their scores in descending order. Two contestants with the same score will be sorted by their index with ascending order.

In every round, contestants will have match based on the sorted list. The first place versus the second place, the third place versus the forth place, ..., the Kth place versus the (K + 1)th place, ..., the (2*N - 1)th place versus (2*N)th place.

Now given the origin score and the ability of every contestant, we want to know the index of the Qth place contestant. We ensured that there won’t be two contestants with the same ability and the contestant with higher ability will always win the match.

Multiple test cases. The first line contains a positive integer T (T<=10) indicating the number of test cases.

For each test case, the first line contains three positive integers N (N <= 100,000), R (R <= 50), Q (Q <= 2*N), separated by space.

The second line contains 2*N non-negative integers, s1, s2, ..., s2*N, si (si<= 108) indicates the origin score of constant indexed i.

The third line contains 2*N positive integers, a1, a2, ..., a2*N, ai (ai<= 108) indicates the ability of constant indexed i.

One line per case, an integer indicates the index of the Qth place contestant after R round matches.

2 4 2
7 6 6 7
10 5 20 15

题目大意:题意很简单,就是有n个人,每个人有能力值和分数值,每次根据分数值从小到大排序,然后0和1战斗,2和3战斗,,,,,以此类推。战斗时能力值大的一方获胜,获胜的一方加1分,输的一方加0分。然后在排序,重复上述。进行r轮。求最后的排序中第Q大的人的编号。

题解:归并排序。

这个题都死在TLE上了,毕竟考察的就是归并。那么为什么是归并呢。先进行sort一遍后就是有序的了,然后赢得一方+1,放到一个数组中;输的一方+0放到一个数组中,此时这两个数组都是有序的,很显然的这是。然后进行归并一次仍然有序。时间大大缩减了。

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

struct node
{
    int id;
    int ab;
    int so;
} s[200200],a[200200],b[200200];
bool cmp(node x,node y)
{
    if(x.so!=y.so)return x.so>y.so;
    return x.id<y.id;
}
int main()
{
    int t;
    scanf("%d",&t);
    int n,r,q;
    int aa,bb,ss;
    while(t--)
    {
        scanf("%d%d%d",&n,&r,&q);
        for(int i=0; i<2*n; i++)
        {
            scanf("%d",&s[i].so);
            s[i].id=i+1;
        }
        for(int i=0; i<2*n; i++)
        {
            scanf("%d",&s[i].ab);
        }
        sort(s,s+2*n,cmp);
        while(r--)
        {
            ss=aa=bb=0;
            for(int i=0; i<2*n; i=i+2)
            {
                if(s[i].ab>s[i+1].ab)
                {
                    s[i].so++;
                    a[aa++]=s[i];
                    b[bb++]=s[i+1];
                }
                else
                {
                    s[i+1].so++;
                    a[aa++]=s[i+1];
                    b[bb++]=s[i];
                }
            }
            int i,j;
            i=j=0;
            while(i<aa&&j<bb)
            {
                if(a[i].so>b[j].so)
                {
                    s[ss++]=a[i];
                    i++;
                }
                else if(a[i].so==b[j].so)
                {
                    if(a[i].id<b[j].id)
                    {
                        s[ss++]=a[i];
                        i++;
                    }
                    else
                    {
                        s[ss++]=b[j];
                        j++;
                    }
                }
                else
                {
                    s[ss++]=b[j];
                    j++;
                }
            }
            while(i<aa)
            {
                s[ss++]=a[i];
                i++;
            }
            while(j<bb)
            {
                s[ss++]=b[j];
                j++;
            }
        }
        printf("%d\n",s[q-1].id);
    }
    return 0;
}

 

sdut-3564

Ok, now I will introduce this game to you...

Isaac is trapped in a maze which has many common rooms…

Like this…There are 9 common rooms on the map.

And there is only one super-secret room. We can’t see it on the map. The super-secret room always has many special items in it. Isaac wants to find it but he doesn’t know where it is.Bob 
tells him that the super-secret room is located in an empty place which is adjacent to only one common rooms. 
Two rooms are called adjacent only if they share an edge. But there will be many possible places.

Now Isaac wants you to help him to find how many places may be the super-secret room.

Multiple test cases. The first line contains an integer T (T<=3000), indicating the number of test case.
Each test case begins with a line containing two integers N and M (N<=100, M<=100) indicating the number
of rows and columns. N lines follow, “#” represent a common room. “.” represent an empty place.Common rooms 
maybe not connect. Don’t worry, Isaac can teleport.

题解:水题

 

 

#include <iostream>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f

using namespace std;

char mp[105][105];

int main()
{
    int t;
    int n,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
        {
            scanf("%s",mp[i]);
        }
        int sum=0;
        for(int i=0;i<m;i++)
        {
            if(mp[0][i]=='#')sum++;
        }
        for(int i=0;i<m;i++)
        {
            if(mp[n-1][i]=='#')sum++;
        }
        for(int i=0;i<n;i++)
        {
            if(mp[i][0]=='#')sum++;
        }
        for(int i=0;i<n;i++)
        {
            if(mp[i][m-1]=='#')sum++;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(mp[i][j]=='.')
                {
                    int num=0;
                    if(i-1>=0&&mp[i-1][j]=='#')num++;
                    if(i+1<n&&mp[i+1][j]=='#')num++;
                    if(j-1>=0&&mp[i][j-1]=='#')num++;
                    if(j+1<m&&mp[i][j+1]=='#')num++;
                    if(num==1)sum++;
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

 

 

sdut-3565

Alice has a monkey, she must feed fruit to the monkey every day.She has three kinds of fruits, bananas, 
peaches and apples. Every day, she chooses one in three, and pick one of this to feed the monkey. 
But the monkey is picky, it doesn’t want bananas for more than D1 consecutive days, peaches for more than D2 
consecutive days, or apples for more than D3 consecutive days. Now Alice has N1 bananas, N2 peaches and N3 
apples, please help her calculate the number of schemes to feed the monkey.

Multiple test cases. The first line contains an integer T (T<=20), indicating the number of test case.
Each test case is a line containing 6 integers N1, N2, N3, D1, D2, D3 (N1, N2, N3, D1, D2, D3<=50).

One line per case. The number of schemes to feed the monkey during (N1+N2+N3) days.
The answer is too large so you should mod 1000000007.

题目大意:有一个猴子,每天要吃一个苹果或者梨子或者香蕉,但是对于每种水果都有连续吃它的限制,比如有n1个苹果,不能连续d1天都吃苹果。然后给出三种水果的数量和连续吃的限制天数。求有多少种给猴子吃水果的方案。

ps:看这个dp也是看的比较费劲,以前在hiho上做过种连续数量的限制求方案数的dp题。可以说是一类的dp题吧。总算是在遇到这种题能知道怎么去想吧。

令dp[a][b][c][k]表示苹果剩余a个,梨子剩余b个,香蕉剩余c个,以第k种水果结尾时的方案数。

那么当定住a,b,c时,遍历min(di,a||b||c),先让一种水果连续放j个,(拿苹果来举例)那么就是dp[a-j][b][c][苹果]+=dp[a][b][c][梨子]+dp[a][b][c][香蕉],最后计算dp[0][0][0][苹果]+dp[0][0][0][梨子]+dp[0][0][0][香蕉]就可以了。(表示都剩余0时以不同水果结尾时的方案数)

 

#include <iostream>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

long long dp[55][55][55][5];
int main()
{
    int t;
    int n1,n2,n3,d1,d2,d3;
    scanf("%d",&t);
    while(t--)
    {
        memset(dp,0,sizeof(dp));
        scanf("%d%d%d%d%d%d",&n1,&n2,&n3,&d1,&d2,&d3);
        for(int i=n1;i>=0;i--)
        {
            for(int j=n2;j>=0;j--)
            {
                for(int k=n3;k>=0;k--)
                {
                    for(int s=1;s<=min(i,d1);s++)
                    {
                        if(i==n1&&j==n2&&k==n3)
                        {
                            dp[i-s][j][k][0]=(dp[i][j][k][0]+1)%MOD;
                        }
                        else
                        {
                            dp[i-s][j][k][0]=((dp[i-s][j][k][0]+dp[i][j][k][1])%MOD+(dp[i][j][k][2]))%MOD;
                        }
                    }
                    for(int s=1;s<=min(j,d2);s++)
                    {
                        if(i==n1&&j==n2&&k==n3)
                        {
                            dp[i][j-s][k][1]=(dp[i][j][k][1]+1)%MOD;
                        }
                        else
                        {
                            dp[i][j-s][k][1]=((dp[i][j-s][k][1]+dp[i][j][k][0])%MOD+(dp[i][j][k][2]))%MOD;
                        }
                    }
                    for(int s=1;s<=min(k,d3);s++)
                    {
                        if(i==n1&&j==n2&&k==n3)
                        {
                            dp[i][j][k-s][2]=(dp[i][j][k][2]+1)%MOD;
                        }
                        else
                        {
                            dp[i][j][k-s][2]=((dp[i][j][k-s][2]+dp[i][j][k][0])%MOD+(dp[i][j][k][1]))%MOD;
                        }
                    }
                }
            }
        }
        long long ans=((dp[0][0][0][0]+dp[0][0][0][1])%MOD+dp[0][0][0][2])%MOD;
        printf("%lld\n",ans);
    }
    return 0;
}
///关于组合数的连续放与不放问题的DP,也是比较经典的DP了
///主要在于找他的状态,对某一物件物品在条件下进行连续放

sdut-3566

Alice and Bob are always playing all kinds of Nim games and Alice always goes first. Here is the rule of Nim game:

There are some distinct heaps of stones. On each turn, two players should remove at least one stone from just one heap. Two player will remove stone one after another. The player who remove the last stone of the last heap will win.

Alice always wins and Bob is very unhappy. So he decides to make a game which Alice will never win. He begins a game called “Triple Nim”, which is the Nim game with three heaps of stones. He’s good at Nim game but bad as math. With exactly N stones, how many ways can he finish his target? Both Alice and Bob will play optimally.

Multiple test cases. The first line contains an integer T (T <= 100000), indicating the number of test case. Each case contains one line, an integer N (3 <= N <= 1000000000) indicating the number of stones Bob have.

题解:(这个自己反正想不出来,对于二进制几乎不怎么敏感,自己只想到了NIM游戏的方法。转一下他人的解释吧)

题意,就是有一堆石子,一共有n个,把n个石子分成三堆,求有多少种分配的方式能够使得bob win?

很容易就能够明白题目是让干什么的,这道题目就是一道尼姆博弈的题目,先来讲下尼姆博弈,其实很简单,有n堆石子,如果n堆石子的异或和是0,则先手必败,否则先手胜。尼姆博弈是利用二进制的思想,那么本题也可以利用二进制的思想,可知,如果要使得Alice输并且Alice为先手,只需要使得三堆石子异或等于0 即可,首先共有n个石子,把n转化成二进制来表示,假设其中有k个1存在,如果要使得三堆石子异或为0,则在三堆石子数的二进制数的每位上1的个数都要是偶数位,又可知,在二进制中,高位的1是由低位进位而得到的,也就是说高位的1可以分解成两个低位的1,当n是奇数的时候,最低位为1且没有办法分解,所以输出0,所以当n为偶数的时候,就有(3^k - 3)/6个,减去3是去掉一个为0的情况,除6是应为本题求得是排列。。。

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long n;
        cin>>n;
        if(n%2)cout<<"0"<<endl;
        else
        {
            int num=0;
            while(n)
            {
                if(n%2)num++;
                n=n/2;
            }
            long long ans=(pow(3,num)-3)/6;
            cout<<ans<<endl;
        }
    }
    return 0;
}

 

sdut-3567

Memory Leak is a well-known kind of bug in C/C++. When a string is longer than expected, it will visit the memory of next array which will cause the issue and leak some information. You can see a simple example bellow:

As we see, if the length of the input string is equal to or larger than the limit length of array, the extra part won’t be stored and the information of next array will be leaked out while outputting. The output will stop until a ‘\0’ character (the symbol of end of a string) is found. In this problem, there will never be unexpected end of the program and the last array won’t leak other information.

Source code given as follow:

Now a simpler source code will be given. What will the output be?

Multiple test cases, the first line is an integer T (T <= 20), indicating the number of test cases.

The first line of each test case contains a non-empty string, the definition of strings, formatted as “char s1[s1_len], s2[s2_len]...;”. “char ” is the type of the array which will never change. s1, s2... is the name of the array. s1_len, s2_len... is the length limit. If nothing goes wrong, the array should be able to store the input string and a ‘\0’. The definitions of different arrays will be separated by a comma and a space. The length limits are positive and the Sum of length limit will be less than 10000.

Then, there will be several lines of string which consists two or three parts.

The first part is “gets” or “cout”, the second part will a string s, indicates the name of the array. s will contains only lower case letters and number digits and start with letters. s will be different in one case. If the first part is “gets”, then there will be the third part, a string which should be input into array s, the length of input string will be less than 1000 and contains only visible ASCII characters. “gets” operation will rewrite the array no matter what was in the array before and add a ‘\0’ after the string. Different parts are separated by a space.

Case ends with “return 0;”

The whole input file is less than 10MB.

For each “cout”, you should output a line contains what will actually output, which means you should consider the issue of memory leak. If the requested array is empty, you should output an empty line.

3char a[5], b[5], c[5];gets a C++gets b Hello, world!gets c guyscout acout bcout creturn 0;char a[5];cout agets a 233gets a 2333cout agets a 12345cout areturn 0;char str1[7], str2[2], str3[5];gets str1 welcomegets str2 togets str3 Shandongcout str1return 0;

 

#include<bits/stdc++.h>

using namespace std;

struct node
{
    int l,r;
}q[100005];
char s[100005];
char ch[100005];
char name[100005][1000];

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(s,0,sizeof(s));
        int num=0;
        int pos=0;
        scanf("%s",ch);
        while(1)
        {
            scanf("%s",ch);
            int len=strlen(ch);
            int i;
            for(i=0;i<len;i++)
            {
                if(ch[i]=='[')break;
                name[num][i]=ch[i];
            }
            name[num][i]='\0';
            int sum=0;
            i++;
            for(;i<len;i++)
            {
                if(ch[i]==']')break;
                sum=sum*10+(ch[i]-'0');
            }
            q[num].l=pos;
            q[num].r=pos+sum;
            pos=pos+sum;
            num++;
            if(getchar()=='\n')break;
        }
        while(1)
        {
            scanf("%s",ch);
            if(ch[0]=='r')
            {
                scanf("%s",ch);
                break;
            }
            if(ch[0]=='g')
            {
                scanf("%s",ch);
                for(int i=0;i<num;i++)
                {
                    if(strcmp(ch,name[i])==0)
                    {
                        getchar();
                        gets(ch);
                        int le=strlen(ch);
                        int j,k;
                        for(j=q[i].l,k=0;k<le&&j<q[i].r;j++,k++)
                        {
                            s[j]=ch[k];
                        }
                        if(j<q[i].r)
                        {
                            s[j]='\0';
                        }
                        break;
                    }
                }
            }
            else
            {
                scanf("%s",ch);
                for(int i=0;i<num;i++)
                {
                    if(strcmp(ch,name[i])==0)
                    {
                        for(int j=q[i].l;j<pos;j++)
                        {
                            if(s[j]=='\0')break;
                            printf("%c",s[j]);
                        }
                        printf("\n");
                        break;
                    }
                }
            }
        }
    }
    return 0;
}
///模拟

 

sdut-3569

Murloc is a powerful race in Hearthstone. In the set League of Explorers, a new Paladin ability card called Anyfin Can Happen is released with the ability to summon 7 Murlocs that died this game. If there aren’t enough dead Murlocs, it may summon less than 7 Murlocs.

There are many different minions in Murloc race, here are four of them:

Coldlight Oracle: 3 MANA, 2 ATTACK, 2 HP. Battlecry: Each player draws 2 cards.

Murloc Warleader: 3 MANA, 3 ATTACK, 3 HP. ALL other Murlocs have +2/+1.

Bluegill Warrior: 2 MANA, 2 ATTACK, 3 HP. Charge.

Old Murk-Eye: 4 MANA, 2 ATTACK, 3 HP. Charge. Has +1 Attack for each other Murloc on the Battlefield.

Here are some explanations:

MANA: The cost of summon the minion. Minions summoned by ability cards cost no mana besides the cost of the ability cards. Every player has 10 MANAs at most.

ATTACK: How many damage can the minion make once.

HP: How many attacks can the minion or heroes take.

Battlecry: An ability where a particular effect activates when the card with the Battlecry is played directly from the hand. The minions summoned by ability won’t activate their Battlecry.

Charge: Minions cannot attack at once when they are summoned unless they have Charge description. They will have to wait until next turn.

Battlefield: The battlefield (or game board) is where the action takes place, representing the board on which each game is played out.

+2/+1: +2 ATTACK and +1 HP.

Now, it is your turn. You have 10 MANAs and only one card: Anyfin Can Happen. There are nothing on the Battlefield, which means your minions can directly attack enemy hero. You can remember the list of dead Murlocs. You know how many HP the enemy hero remains. Will you win this game through this only card you have?

Multiple test cases. The first line contains an integer T (T<= 22000), indicating the number of test case.

The first line of each test contains two integers, n (the number of dead Murlocs, 0 <= n <= 7) and h (the HP of enemy hero, 0 < h <= 30).

Then n lines follows, each line contains a string, indicates the name of dead Murloc. The string will only be “Coldlight Oracle”, “Murloc Warleader”, “Bluegill Warrior” or “Old Murk-Eye”.

One line per case. If you can win the game in this turn, output “Mrghllghghllghg!”(Without quotes). Otherwise, output “Tell you a joke, the execution of Paladin.” You will win the game if you attack enemy hero with your minions and make his/her HP less or equal than 0.

3
3 1
Coldlight Oracle
Coldlight Oracle
Murloc Warleader
3 8
Old Murk-Eye
Old Murk-Eye
Coldlight Oracle
7 30
Old Murk-EyeBlue
gill Warrior
Bluegill Warrior
Murloc Warleader
Murloc Warleader
Coldlight Oracle
Coldlight Oracle

输出:
Tell you a joke, the execution of Paladin.

Mrghllghghllghg!
Tell you a joke, the execution of Paladin.

题解:根据炉石的玩法求解就行了。

//英语题
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

char s[111];

int main()
{
    int t,n,m;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        getchar();
        int O,W,B;
        O=W=B=0;
        for(int i=0;i<n;i++)
        {
            gets(s);
            if(s[0]=='O')O++;
            else if(s[0]=='B')B++;
            else if(s[0]=='M')W++;
        }
        int ans=(n-1)*O+2*(O+B)+2*W*(O+B);
        if(ans>=m)printf("Mrghllghghllghg!\n");
        else printf("Tell you a joke, the execution of Paladin.\n");
    }
    return 0;
}

 

 

sdut-3570

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!

Multiple test cases. The first line contains a positive integer T (T <= 1000), indicating 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.

2eno owt eerhtabcde
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

char s[10005];
stack<char>q;
int main()
{
    int t;
    scanf("%d",&t);
    getchar();
    while(t--)
    {
        while(!q.empty())q.pop();
        gets(s);
        int len=strlen(s);
        int i=0;
        while(i<len)
        {
            //if(i>7)break;
            if(s[i]==' ')
            {
                printf("%c",s[i]);
                i++;
            }
            else
            {
                while(s[i]!=' '&&s[i]!='\0')
                {
                    q.push(s[i]);
                    i++;
                }
                while(!q.empty())
                {
                    printf("%c",q.top());
                    q.pop();
                }

            }
        }
        printf("\n");
    }
    return 0;
}

 

题解:

 

转载于:https://www.cnblogs.com/upstart/p/8982380.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值