8VC Venture Cup 2016 - Elimination Round 总结

来源:互联网 发布:网络直销是什么 编辑:程序博客网 时间:2024/05/03 18:38
A. Robot Sequence
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.

Input

The first line of the input contains a single positive integer, n (1 ≤ n ≤ 200) — the number of commands.

The next line contains n characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code.

Output

Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square.

Examples
input
6URLLDR
output
2
input
4DLUU
output
0
input
7RLRLRLR
output
12
Note

In the first case, the entire source code works, as well as the "RL" substring in the second and third characters.

Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.


题意:

某机器人可以按上下左右移动。。。现给出一串指令,机器人所处空间无限大,问有多少该指令的某一连续子串,使得机器人执行后回原位

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=1e3+10;char s[maxm];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        scanf("%s",s);        int sum=0;        for(int i=0; i<strlen(s); i++)        {            for(int j=i+1; j<strlen(s); j++)            {                int x=0,y=0;                for(int k1=i; k1<=j; k1++)                {                    if(s[k1]=='U')                    {                        y++;                    }                    if(s[k1]=='R')                    {                        x++;                    }                    if(s[k1]=='L')                    {                       x--;                    }                    if(s[k1]=='D')                    {                        y--;                    }                }                if(x==0&&y==0)                {                    sum++;                }            }        }        printf("%d\n",sum);    }    return 0;}

B. Cards
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:

  • take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color;
  • take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.

She repeats this process until there is only one card left. What are the possible colors for the final card?

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards.

The next line contains a string s of length n — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.

Output

Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.

Examples
input
2RB
output
G
input
3GRG
output
BR
input
5BBBBB
output
B
Note

In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.

In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.

In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.


题意:

Catherine有n张卡片,每张卡片分别是蓝绿红的其中一种颜色每次可以执行两种操作中的一种:

1:将两张同色卡片换成一张该颜色卡

2:将两张异色卡片换成一张第三种颜色卡

问:最后剩的一张卡可能是什么颜色


所有情况都讨论一遍就好。。。


#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=1e3+10;char s[maxm];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        scanf("%s",s);        int b=0,r=0,g=0;        for(int i=0;i<n;i++)        {            if(s[i]=='B')                b++;            else if(s[i]=='R')                r++;            else                g++;        }        if(b&&g&&r)        {            printf("BGR\n");            continue;        }        if(!b&&!g)        {            printf("R\n");            continue;        }        if(!b&&!r)        {            printf("G\n");            continue;        }        if(!r&&!g)        {            printf("B\n");            continue;        }        if(!b)        {            if(g>1&&r>1)            {                printf("BGR\n");                continue;            }            else if(g==1&&r==1)            {                printf("B\n");                continue;            }            else if(g==1)            {                printf("BG\n");                continue;            }            else            {                printf("BR\n");                continue;            }        }        if(!g)        {            if(b>1&&r>1)            {                printf("BGR\n");                continue;            }            else if(b==1&&r==1)            {                printf("G\n");                continue;            }            else if(b==1)            {                printf("BG\n");                continue;            }            else            {                printf("GR\n");                continue;            }        }        if(!r)        {            if(g>1&&b>1)            {                printf("BGR\n");                continue;            }            else if(g==1&&b==1)            {                printf("R\n");                continue;            }            else if(g==1)            {                printf("GR\n");                continue;            }            else            {                printf("BR\n");                continue;            }        }    }    return 0;}
C. Block Towers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.

The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

Input

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Output

Print a single integer, denoting the minimum possible height of the tallest tower.

Examples
input
1 3
output
9
input
3 2
output
8
input
5 0
output
10
Note

In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 36, and 9 blocks. The tallest tower has a height of 9 blocks.

In the second case, the students can make towers of heights 24, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.


题意:

好多小孩在玩建塔游戏。。。其中一队只有高度为2的积木,另一队只有高度为3的积木,他们都不喜欢自己建的塔的高度和其他小孩一样,问满足条件情况下最高的塔的高度最低是多少


对于任意i,记

a1:小于等于i的所有数中是2的倍数但不是6的倍数的数

a2:小于等于i的所有数中是3的倍数但不是6的倍数的数

a3:小于等于i的所有数中是6的倍数的数

若a1+a2+a3 >= n+m 则i是解

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){    int n,m;    while(scanf("%d%d",&n,&m)!=EOF)    {        for(int i=1;;i++)        {            int a1=max(n-(i/2-i/6),0);            int a2=max(m-(i/3-i/6),0);            int a3=i/6;            if(a1+a2<=a3)            {                printf("%d\n",i);                break;            }        }    }    return 0;}


1 0
原创粉丝点击