Codeforces 400 A. Inna and Choose Options 【Codeforces Round #234 (Div. 2)】

简介:
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
4
OXXXOXOOXOOX
OXOXOXOXOXOX
XXXXXXXXXXXX
OOOOOOOOOOOO
output
3 1x12 2x6 4x3
4 1x12 2x6 3x4 6x2
6 1x12 2x6 3x4 4x3 6x2 12x1
0

题目大意:
给定一个T.表示有T组数据,然后每行有一个长度为12的字符串,求有多少种方式可以满足至少有一列
全是X的情况 然后输出有多少种并且将组成什么样的矩阵 m x n,将m 和 n 输出

解题思路:

挨个枚举,吧每一个可能出现的情况写出来。。。

上代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 15;
const int mod = 1000000007;
const double eps = 1e0-7;
char s[15];
int num[15];
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int ans = 0;
        scanf("%s", s);
        if(s[0]=='X'||s[1]=='X'||s[2]=='X'||s[3]=='X'||s[4]=='X'||s[5]=='X'||s[6]=='X'||s[7]=='X'||s[8]=='X'||s[9]=='X'||s[10]=='X'||s[11]=='X')
            num[ans++] = 1;

        if((s[0]=='X'&&s[6]=='X')||(s[1]=='X'&&s[7]=='X')||(s[2]=='X'&&s[8]=='X')||(s[3]=='X'&&s[9]=='X')||(s[4]=='X'&&s[10]=='X')||(s[5]=='X'&&s[11]=='X'))
            num[ans++] = 2;

        if((s[0]=='X'&&s[4]=='X'&&s[8]=='X')||(s[1]=='X'&&s[5]=='X'&&s[9]=='X')||(s[2]=='X'&&s[6]=='X'&&s[10]=='X')||(s[3]=='X'&&s[7]=='X'&&s[11]=='X'))
            num[ans++] = 3;

        if((s[0]=='X'&&s[3]=='X'&&s[6]=='X'&&s[9]=='X')||(s[1]=='X'&&s[4]=='X'&&s[7]=='X'&&s[10]=='X')||(s[2]=='X'&&s[5]=='X'&&s[8]=='X'&&s[11]=='X'))
            num[ans++] = 4;

        if((s[0]=='X'&&s[2]=='X'&&s[4]=='X'&&s[6]=='X'&&s[8]=='X'&&s[10]=='X')||(s[1]=='X'&&s[3]=='X'&&s[5]=='X'&&s[7]=='X'&&s[9]=='X'&&s[11]=='X'))
            num[ans++] = 6;

        if(s[0]=='X'&&s[1]=='X'&&s[2]=='X'&&s[3]=='X'&&s[4]=='X'&&s[5]=='X'&&s[6]=='X'&&s[7]=='X'&&s[8]=='X'&&s[9]=='X'&&s[10]=='X'&&s[11]=='X')
            num[ans++] = 12;

        cout<<ans;
        for(int i=0; i<ans; i++)
            printf(" %dx%d",num[i],12/num[i]);
        cout<<endl;
    }
}


目录
相关文章
Codeforces Round #192 (Div. 2) (330B) B.Road Construction
要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目。 要求两个城市之间不超过两条道路,那么所有的城市应该是连在一个点上的,至于这个点就很好找了,只要找到一个没有和其他点有道路限制的即可。
57 0
Codeforces Round #186 (Div. 2)A、B、C、D、E
Ilya得到了一个礼物,可以在删掉银行账户最后和倒数第二位的数字(账户有可能是负的),也可以不做任何处理。
52 0
|
人工智能 算法 BI
Codeforces Round #179 (Div. 2)A、B、C、D
我们每次加进来的点相当于k,首先需要进行一个双重循环找到k点和所有点之间的最短路径;然后就以k点位判断节点更新之前的k-1个点,时间复杂度降到O(n^3),而暴力解法每次都要进行floyd,时间复杂度为O(n^4);相比之下前述解法考虑到了floyd算法的性质,更好了运用了算法的内质。
63 0
Codeforces Round 799 (Div. 4)
Codeforces Round 799 (Div. 4)
127 0
|
人工智能 BI
Codeforces Round 827 (Div. 4)
Codeforces Round 827 (Div. 4)A~G题解
117 0
Codeforces Round #675 (Div. 2) A~D
Codeforces Round #675 (Div. 2) A~D
165 0
Equidistant Vertices-树型dp-Codeforces Round #734 (Div. 3)
Description A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words,
154 0
|
机器学习/深度学习 算法 C++