Help Victoria the Wise + Friends + Hockey

【题目】

2174: Help Victoria the Wise

Time Limit: 2 Sec   Memory Limit: 256 MB
Submit: 16   Solved: 6
[ Submit][ Status][ Web Board]

Description

A. Help Victoria the Wise
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.

The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube)

Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem.

Input

The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} − they are the colors of gems with which the box should be decorated.

Output

Print the required number of different ways to decorate the box.

Examples
Input
YYYYYY
Output
1
Input
BOOOOB
Output
2
Input
ROYGBV
Output
30

【题解】

说实在的一开始我题都没读懂。

立方体的六个面分配所给的颜色,问有多少种分配方法,注意可转动立方体达到的状态算一种方法。

总共十一种情况

1. 6 - 1

2. 1 5 - 1

3. 2 4 - 2

4. 3 3 - 2

5. 1 1 4 - 2

6. 1 2 3 - 3

7. 1 1 1 3 - 5

8. 2 2 2 - 6

9. 1 1 2 2 - 8

10.  1 1 1 1 2 - 15

11. 1 1 1 1 1 1 - 30

【代码】

#include<bits/stdc++.h>
using namespace std;
main()
{
    int a[10],i;
    char b[10];
    while(~scanf("%s",b))
    {
        memset(a,0,sizeof(a));
        for(i=0;i<6;i++)
        {
            if(b[i]=='R')
               a[0]++;
            else if(b[i]=='O')
                a[1]++;
            else if(b[i]=='Y')
                a[2]++;
            else if(b[i]=='G')
                a[3]++;
            else if(b[i]=='B')
                a[4]++;
            else
                a[5]++;
        }
        sort(a,a+6);
        if(a[5]==6||a[5]==5)
            printf("1\n");
        else if(a[5]==4||(a[5]==3&&a[4]==3))
            printf("2\n");
        else if(a[5]==3&&a[4]==2)
            printf("3\n");
        else if(a[5]==3&&a[4]==1)
            printf("5\n");
        else if(a[5]==2&&a[4]==2&&a[3]==2)
            printf("6\n");
        else if(a[5]==2&&a[4]==2&&a[3]==1)
            printf("8\n");
        else if(a[5]==2&&a[4]==1)
            printf("15\n");
        else
            printf("30\n");
    }
}

【题目】

2184: Friends

Time Limit: 2 Sec   Memory Limit: 256 MB
Submit: 12   Solved: 3
[ Submit][ Status][ Web Board]

Description

B. Friends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.

The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"

Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" − he kept on repeating in his mind. − "Let's take, say, Max, Ilya, Vova − here, they all know each other! And now let's add Dima and Oleg to Vova − none of them is acquainted with each other! Now, that math is just rubbish!"

Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people.

Input

The first line contains an integer m (0≤m≤10), which is the number of relations of acquaintances among the five friends of Igor's.

Each of the following m lines contains two integers ai and bi (1≤ai,bi≤5;aibi), where (ai,bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x.

Output

Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN".

Examples
Input
4
1 3
2 3
1 4
5 3
Output
WIN
Input
5
1 2
2 3
3 4
4 5
5 1
Output
FAIL

【题解】

题意:若存在三个人互不相识或者互相认识则输出WIN,否则输出FALL.

思路:易得只有形成五元环时才不存在三个人互不相识,存在三个人互相认识即形成三元环,因此只需要判断是否形成五元环即可。

【代码】

#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,u,v,a[7],i;
    memset(a,0,sizeof(a));
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d%d",&u,&v);
        a[u]++,a[v]++;
    }
    int f=1;
    for(i=1;i<=5;i++)
        if(a[i]!=2)
          f=0;
    if(f)
        printf("FALL\n");
    else
        printf("WIN\n");
}

【题目】

2183: Hockey

Time Limit: 2 Sec   Memory Limit: 256 MB
Submit: 2   Solved: 1
[ Submit][ Status][ Web Board]

Description

A. Hockey
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1,s2,...,sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.

First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.

After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l,r (1≤lir≤|w|) such that substring w[l...r] is contained in the collection s1,s2,...,sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.

Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.

Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.

Input

The first line contains the only integer n (1≤n≤100) − the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n+1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.

Output

Output the only line − Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.

The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1≤i≤|a|), that ai<bi, and for any j (1≤j<i) aj=bj. |a| stands for the length of string a.

Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba

【题解】

题意:第一行输入一个n,接下来n行输入n个禁用字符串,接下来输入原始字符串,最后一行输入一个小写字母用于替换禁用字符串。需注意以下几点:

1.禁用字符串与原始字符串匹配时不区分大小写

2.替换时若原始字符为大写字母,替换后也要为大写字母

3.替换时若原始字符与给定替换字符相同,则选择字典序最小的字符替换

4.已经替换为给定替换字符的位置在后续判断中不做改动

思路:

考虑到1,设置整型数组c[][],d[]用于存放大写字母-'A'或小写字母-'a'的值,便于进行后续的不区分大小写比较。

考虑到2和3,在替换时进行判断。

考虑到4,设置vis[]用于记录是否已做替换操作。

最后输出结果字符串。over!!

【代码】

#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,i,j,k;
    char a[105][105],b[105],t;
    int c[105][105],d[105],vis[105];
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(i=0;i<n;i++)
        scanf(" %s",a[i]);
    scanf(" %s %c",b,&t);
    for(i=0;i<n;i++)
        for(j=0;j<strlen(a[i]);j++)
            if(a[i][j]>='a')
               c[i][j]=a[i][j]-'a';
            else
                c[i][j]=a[i][j]-'A';
    for(i=0;i<strlen(b);i++)
        if(b[i]>='a')
           d[i]=b[i]-'a';
        else
            d[i]=b[i]-'A';
    for(k=0;k<n;k++)
    {
        for(i=0;i<strlen(b);i++)
        {
            int m=i,f=1;
            for(j=0;j<strlen(a[k]);j++,m++)
            {
                if(c[k][j]!=d[m])
                {
                    f=0;
                    break;
                }

            }
            if(f)
                for(j=i;j<i+strlen(a[k]);j++)
                {
                    if(vis[j]==0)
                    {
                        vis[j]=1;
                        if(b[j]>='a')
                        {
                           if(b[j]!=t)
                              b[j]=t;
                           else
                           {
                               if(b[j]=='a')
                                  b[j]++;
                               else
                                  b[j]='a';
                           }
                        }
                        else
                        {
                             if(b[j]!=t-'a'+'A')
                                b[j]=t-'a'+'A';
                             else
                             {
                                 if(b[j]=='A')
                                    b[j]++;
                                 else
                                    b[j]='A';
                             }
                        }
                    }
                }
        }
    }
    printf("%s\n",b);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值