Codeforces Round #234 (Div. 2) 总结

来源:互联网 发布:1983星星知我心电视剧 编辑:程序博客网 时间:2024/06/16 02:10

A

A. Inna and Choose Options
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:

There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers a and b (a·b = 12), after that he makes a table of size a × b from the cards he put on the table as follows: the first b cards form the first row of the table, the second b cards form the second row of the table and so on, the last b cards form the last (number a) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses.

Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers a and b to choose. Help her win the game: print to her all the possible ways of numbers a, b that she can choose and win.

Input

The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line.

The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th character of the string shows the character that is written on the i-th card from the start.

Output

For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespaces.

Sample test(s)
input
4OXXXOXOOXOOXOXOXOXOXOXOXXXXXXXXXXXXXOOOOOOOOOOOO
output
3 1x12 2x6 4x34 1x12 2x6 3x4 6x26 1x12 2x6 3x4 4x3 6x2 12x10


题意:输入n行12列的字符串,对于每行字符串而言,从i=1-12开始遍历,每个字符串可以分成i行12/i列。若有一列的值全部为x,则输出i*12/i.

模拟皆可

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=50;char s[maxm];int x[maxm],y[maxm];int main(){    int n;    scanf("%d",&n);    while(n--)    {        memset(x,0,sizeof(x));        memset(y,0,sizeof(y));        scanf("%s",s);        int cnt=0;        for(int i=1; i<=12; i++)        {            if(12%i==0)            {                for(int j=0; j<12/i; j++)                {                    int ok=1;                    for(int k=j; k<12; k+=12/i)                    {                        if(s[k]=='O')                        {                            ok=0;                            break;                        }                        else                        {                            continue;                        }                    }                    if(ok)                    {                        x[cnt]=i;                        y[cnt++]=12/i;                        break;                    }                }            }        }        printf("%d ",cnt);        for(int i=0; i<cnt; i++)        {            printf("%dx%d ",x[i],y[i]);        }        printf("\n");    }    return 0;}

B:

B. Inna and New Matrix of Candies
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".

The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start tosimultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:

  • some dwarf in one of the chosen lines is located in the rightmost cell of his row;
  • some dwarf in the chosen lines is located in the cell with the candy.

The point of the game is to transport all the dwarves to the candy cells.

Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 1000; 2 ≤ m ≤ 1000).

Next n lines each contain m characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".

Output

In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.

Sample test(s)
input
3 4*G*SG**S*G*S
output
2
input
1 3S*G
output
-1

题意:说白了就是求有多少种值对于G到S间或者G到末尾,如果位置G>S.输出-1

#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=1e3+10;char s[maxm][maxm];int vis[maxm];int main(){    int m,n;    while(scanf("%d%d",&m,&n)!=EOF)    {        memset(vis,0,sizeof(vis));        int ok=0;        int cnt=0;        for(int i=0;i<m;i++)        {            scanf("%s",s[i]);            int x=0,y=0;            for(int j=0;j<strlen(s[i]);j++)            {                if(s[i][j]=='G')                {                    x=j;                }                if(s[i][j]=='S')                {                    y=j;                }            }            if(x>y)            {                ok=1;            }            else if(!vis[y-x])            {                cnt++;                vis[y-x]=1;            }        }        if(ok)        {            printf("-1\n");            continue;        }        printf("%d\n",cnt);    }    return 0;}

C

C. Inna and Huge Candy Matrix
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk).

The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.

Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

Input

The first line of the input contains fix integers nmxyzp (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105).

Each of the following p lines contains two integers xkyk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.

Output

For each of the p candies, print on a single line its space-separated new coordinates.

Sample test(s)
input
3 3 3 1 1 91 11 21 32 12 22 33 13 23 3
output
1 31 21 12 32 22 13 33 23 1
Note

Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:

QWER      REWQ ASDF  ->  FDSAZXCV      VCXZ
题意:求x,y在矩阵大小为n,m中顺时针转x次,水平转y次,逆时针转z次。求最终x,y的坐标

解:想,对于转x次,没4次回到原点,则x%=4.同理y&=1.z%=4;接下来模拟就可以了

#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;const int maxm=1e5+10;int a[maxm];int b[maxm];int main(){    int n,m,x,y,z,p;    while(scanf("%d%d%d%d%d%d",&m,&n,&x,&y,&z,&p)!=EOF)    {        x%=4;        y&=1;        z%=4;        for(int i=0;i<p;i++)        {            int temp1=m,temp2=n;            scanf("%d%d",&a[i],&b[i]);            for(int j=0;j<x;j++)            {                swap(a[i],b[i]);                b[i]=temp1+1-b[i];                swap(temp1,temp2);            }            if(y)            {                b[i]=temp2+1-b[i];            }            for(int j=0;j<z;j++)            {                swap(a[i],b[i]);                a[i]=temp2+1-a[i];                swap(temp1,temp2);            }        }        for(int i=0;i<p;i++)        {            printf("%d %d\n",a[i],b[i]);        }    }    return 0;}


0 0
原创粉丝点击