One Day One Step 之Codeforce(2014.03.06)
来源:互联网 发布:保健品网络销售好做吗 编辑:程序博客网 时间:2024/05/18 00:44
其实这是我第二次打CF,不过,上一次打的时候,CF就挂了。不过,由于我感冒了,只是做了第一道题而已!
想说一句的是,题目题意一定要看清楚,不然像我一样,理解错题意,一直就在那里纠结中,真是不该!
第一道题,算是简单的!就是要求把一个有12个字符的字符串按照a x b 的形式排, 如果某一列(我当时以为是某一行 )都为“X”,则满足题意。最后要输出所有满足题意的个数,并且输出 a x b 的形式!
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 sizea × b from the cards he put on the table as follows: the firstb cards form the first row of the table, the secondb cards form the second row of the table and so on, the lastb cards form the last (numbera) 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 numbersa andb to choose. Help her win the game: print to her all the possible ways of numbersa, b that she can choose and win.
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 thet tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". Thei-th character of the string shows the character that is written on thei-th card from the start.
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 paira, b. Next, print on this line the pairs in the formataxb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespaces.
4OXXXOXOOXOOXOXOXOXOXOXOXXXXXXXXXXXXXOOOOOOOOOOOO
3 1x12 2x6 4x34 1x12 2x6 3x4 6x26 1x12 2x6 3x4 4x3 6x2 12x10
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>#define N 13bool isallthesame( char * str, int len, int col ){ int first_bit; int cur_position; int sametimes; int i; for( i = 0; i < col; i++ ) { first_bit = i; cur_position = i; sametimes = 0; while( sametimes < len / col ) { if( str[ first_bit ] == 'X' && str[ first_bit ] == str[ cur_position ] ) { sametimes++; cur_position += col; } else { break; } } if( sametimes == ( len / col ) ) { break; } } return sametimes == len / col ? true : false;}int main( void ){ int num; scanf( "%d", &num ); getchar(); while( num-- ) { int win_times = 0; char game[ N ] = {0}; bool which_win[ N ] = { false }; int win[ 6 ] = {12, 6, 4, 3, 2, 1}; int len = 0; int i; gets( game ); len = strlen( game ); for( i = 0; i < 6; i++ ) { if( isallthesame( game, len, win[ i ] ) == true ) { which_win[ win[ i ] ] = true; win_times++; } } if( win_times == 0 ) { printf( "0\n" ); } else { printf( "%d", win_times ); for( i = 0; i < 6; i++ ) { if( which_win[ win[ i ] ] == true ) { printf( " %dx%d", 12 / win[ i ], win[ i ] ); } } putchar( '\n' ); } } return 0;}
- One Day One Step 之Codeforce(2014.03.06)
- One Day One Step 之贪心算法(1)
- One Day One Step之图论(1)
- One Day One Step 之 nothing
- One Day One Step 之大数阶乘
- One Day One Step 之Milking Cows
- One Day One Step 之Palindromic Squares
- One Day One Step 之Dual Palindromes
- One Day One Step之平面分割问题
- One Day One Step 之全错位排序
- One Day One Step 之Greedy Gift Givers
- one step one step...
- One day, One week!
- O..One..One...Day
- O..One..One...Day
- One day
- ONE DAY
- one day
- 教你如何美化Ubuntu桌面
- struts(2)----工作流程图简述
- Linux配置Oracle 11g自动启动
- MyEclipse修改j2ee Libraries版本
- Android Intent详解
- One Day One Step 之Codeforce(2014.03.06)
- HashTable和HashMap的区别(三点)
- RAC安装时需要执行4个脚本及意义
- RAC 的一些概念性和原理性的知识
- 编译inkscape
- 12计算机毕业设计
- 使用Navicat for Oracle新建表空间、用户及权限赋予
- RESTful 的webservice
- 开源项目:3D旋转动画Rotate3dAnimation.java