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

题意:略

sl:简单模拟

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 const int MAX = 1e6;
 6 char str[];
 7 int a[],b[];
 8 int map[][];
 9 int main()
 {
     int cas,num,ans;
     scanf("%d",&cas);
     while(cas--)
     {
         num=ans=; int flag=;
         scanf("%s",str);
         int n=strlen(str);
         for(int i=;i<n;i++) if(str[i]=='X') num++;
         if(num>=)
         {
             a[ans]=;
             b[ans++]=;
         }
         for(int i=;i<;i++)
         {
             if(str[i]==str[i+]&&str[i]=='X')
             flag=;
         }
         if(flag) a[ans]=,b[ans++]=;
         flag=;
         for(int i=;i<;i++)
         {
             if(str[i]==str[i+]&&str[i]==str[i+]&&str[i]=='X')
             flag=;
         }
         if(flag) a[ans]=,b[ans++]=;
         flag=;
         for(int i=;i<;i++)
         {
             if(str[i]==str[i+]&&str[i]==str[i+]&&str[i]==str[i+]&&str[i]=='X')
                 flag=;
         }
         if(flag) a[ans]=,b[ans++]=;
         flag=;
         for(int i=;i<;i++)
         {
             if(str[i]==str[i+]&&str[i]==str[i+]&&str[i]==str[i+]&&str[i]==str[i+]&&str[i]==str[i+]&&str[i]=='X')
                 flag=;
         }
         if(flag) a[ans]=,b[ans++]=;
         flag=;
         if(num==) a[ans]=,b[ans++]=;
         if(ans)
         {
             printf("%d",ans);
             for(int i=;i<ans;i++)
             {
                 printf(" %dx%d",a[i],b[i]);
             }
             printf("\n");
         }
         else printf("0\n");
     }
     return ;
 }

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 can 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 to simultaneously 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*S
G**S
*G*S
output
2
input
1 3
S*G
output
-1

题意:比赛时猜的题意一发wa然后又猜一发ac,就是要把所有人放到糖里,人只能向右移动,当碰到墙或者碰到糖算是一次移动结束。求移动次数

sl: 直接求一下每行人到糖的最小距离排个序统计一下即可

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 const int MAX = 1e3+;
 6 char map[MAX][MAX];
 7 int ans[MAX],a[MAX],b[MAX];
 8 int main()
 9 {
     int n,m;
     while(scanf("%d %d",&n,&m)==)
     {
         int t=;
         memset(ans,,sizeof(ans));
         memset(b,,sizeof(b));
         int flag=,len=,cur;
         for(int i=;i<n;i++)
         {
             getchar(); int check=; cur=;
             for(int j=;j<m;j++)
             {
                 scanf("%c",&map[i][j]);
                 if(j==m-&&map[i][j]=='G') flag=;
                 if(map[i][j]=='G'&&check)
                 {
                     a[cur++]=j; check=;
                 }
                 else if(map[i][j]=='S'&&cur>)
                 {
                     t=j-a[cur-]-;
                     ans[i]=max(ans[i],t);
                     check=;
                   //  printf("%d %d #%d\n",j,a[cur-1],t);
                 }
             }
             if(!check) flag=;
         }
         int ret=;
         if(!flag) printf("-1\n");
         else
         {
             sort(ans,ans+n);
             for(int i=;i<n;i++)
             {
                 if(ans[i]!=ans[i-]) ret++;
             }
             printf("%d\n",ret);//,printf("%d\n",ans[i]);
         }
 
     }
     return ;

52 }

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 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
output
1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 2
3 1

题意:给出三种对矩阵的操作:1,顺时针旋转90度,2,翻转,3,逆时针旋转90度,再给出一些点的坐标,问操作之后的点的坐标

sl:简单矩阵旋转操作。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 const int MAX = 1e6;
 6 int a[MAX],b[MAX];
 7 int n,m,x,y,z,p;
 8 void get1()
 9 {
     int t;
     for(int i=;i<p;i++)
     {
         t=a[i];
         a[i]=b[i];
         b[i]=n-t+;
     }
     swap(n,m);
 }
 void get2()
 {
     int t;
     for(int i=;i<p;i++)
     {
         t=b[i];
         b[i]=a[i];
         a[i]=m-t+;
     }
     swap(n,m);
 }
 void get3()
 {
     int t;
     for(int i=;i<p;i++)
     {
         b[i]=m-b[i]+;
     }
 }
 int main()
 {
     int xx,yy,zz;
     while(scanf("%d %d %d %d %d %d",&n,&m,&x,&y,&z,&p)==)
     {
         for(int i=;i<p;i++)
         {
             scanf("%d %d",&a[i],&b[i]);
         }
         xx=x%;
         for(int i=;i<xx;i++)
         get1();
         yy=y%;
         for(int i=;i<yy;i++) get3();
         zz=z%;
         for(int i=;i<zz;i++) get2();
         for(int i=;i<p;i++)
         {
             printf("%d %d\n",a[i],b[i]);
         }
 
     }
     return ;

61 }

D. Dima and Bacteria
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type ci are numbered from  to .

With the help of special equipment Dima can move energy from some bacteria into some other one. Of course, the use of such equipment is not free. Dima knows m ways to move energy from some bacteria to another one. The way with number i can be described with integers uivi and ximean that this way allows moving energy from bacteria with number ui to bacteria with number vi or vice versa for xi dollars.

Dima's Chef (Inna) calls the type-distribution correct if there is a way (may be non-direct) to move energy from any bacteria of the particular type to any other bacteria of the same type (between any two bacteria of the same type) for zero cost.

As for correct type-distribution the cost of moving the energy depends only on the types of bacteria help Inna to determine is the type-distribution correct? If it is, print the matrix d with size k × k. Cell d[i][j] of this matrix must be equal to the minimal possible cost of energy-moving from bacteria with type i to bacteria with type j.

Input

The first line contains three integers n, m, k (1 ≤ n ≤ 105; 0 ≤ m ≤ 105; 1 ≤ k ≤ 500). The next line contains k integers c1, c2, ..., ck (1 ≤ ci ≤ n). Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ 105; 0 ≤ xi ≤ 104). It is guaranteed that .

Output

If Dima's type-distribution is correct, print string «Yes», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k] (d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print «No».

Sample test(s)
input
4 4 2
1 3
2 3 0
3 4 0
2 4 1
2 1 2
output
Yes
0 2
2 0
input
3 1 2
2 1
1 2 0
output
Yes
0 -1
-1 0
input
3 2 2
2 1
1 2 0
2 3 1
output
Yes
0 1
1 0
input
3 0 2
1 2
output
No

题意:给出一些集合,然后给出集合中元素之间的距离,判断单个集合中是不是满足任意两点都有长度为0的路径。并输出集合到集合的最短路。

sl:可以用并查集判断是不是存在长度为0的路径,求最短路可以使用弗洛伊德算法,因为k只有500.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int MAX = 1e5+;
 6 const int inf = 0x3f3f3f3f;
 7 int dist[][],fa[MAX],check[MAX];
 8 int c[MAX],sum[MAX];
 9 void make(int n)
 {
     for(int i=;i<=n;i++) fa[i]=i;
 }
 int find(int x)
 {
     if(fa[x]!=x)
     fa[x]=find(fa[x]);
     return fa[x];
 }
 void Union(int a,int b)
 {
     int x=find(a),y=find(b);
     if(x!=y) fa[x]=y;
 }
 int main()
 {
     int n,m,k,flag;
     int u,v,x;
     while(scanf("%d %d %d",&n,&m,&k)==)
     {
         memset(sum,,sizeof(sum));
         memset(check,,sizeof(check));
         make(n);
         for(int i=;i<=k;i++) for(int j=;j<=k;j++)
         dist[i][j]=inf;
         for(int i=;i<=k;i++) scanf("%d",&c[i]);
         for(int i=;i<=k;i++) sum[i]=sum[i-]+c[i];
         for(int i=;i<m;i++)
         {
             scanf("%d %d %d",&u,&v,&x);
             int uu=lower_bound(sum+,sum+k+,u)-sum; //二分枚举所在的集合
             int vv=lower_bound(sum+,sum+k+,v)-sum;
             dist[uu][vv]=dist[vv][uu]=min(dist[uu][vv],x);
             if(x==) Union(u,v);
         }
         flag=;
         for(int i=;i<=n;i++)
         {
             int pos=lower_bound(sum+,sum+k+,i)-sum;
             int u=find(i);
             if(check[pos]&&u!=check[pos]) //判断相应的集合元素是不是距离为0
             {
                 flag=;
                 break;
             }
             else check[pos]=u;
         }
         if(flag)
         {
             for(int i=;i<=k;i++) dist[i][i]=;
             for(int m=;m<=k;m++)
             for(int i=;i<=k;i++)
             for(int j=;j<=k;j++)
             dist[i][j]=min(dist[i][m]+dist[m][j],dist[i][j]);
             printf("Yes\n");
             for(int i=;i<=k;i++)
             {
                 for(int j=;j<=k;j++)
                 {
                     if(dist[i][j]==inf) dist[i][j]=-;
                     if(j==) printf("%d",dist[i][j]);
                     else printf(" %d",dist[i][j]);
                 }
                 printf("\n");
             }
         }
         else printf("No\n");
     }
     return ;

79 }

Codeforces Round #234 (Div. 2)的更多相关文章

  1. Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies

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

  2. Codeforces Round #234 (Div. 2) :A. Inna and Choose Options

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

  3. Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies SET的妙用

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

  4. Codeforces Round #234 (Div. 2) A. Inna and Choose Options 模拟题

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

  5. Codeforces Round #234 (Div. 2) A. Inna and Choose Options

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

  6. Codeforces Round #234 (Div. 2):B. Inna and New Matrix of Candies

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

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. bzoj 1705: [Usaco2007 Nov]Telephone Wire 架设电话线【dp】

    i的初始化写成2了于是成功查错2h--怕不是个傻子 设f[i][j]为第i根高为j,转移是 \[ f[i][j]=min(f[i-1][k]+abs(k-j)*c+(j-h[i])^2)(j>= ...

  2. 01-vue指令

    什么是Vue.js Vue.js 是目前最火的一个前端框架,React是最流行的一个前端框架(React除了开发网站,还可以开发手机App, Vue语法也是可以用于进行手机App开发的,需要借助于We ...

  3. 【转】mysql中select用法

    转自:http://blog.sina.com.cn/s/blog_a74f39a201013c3b.html 1.选择所有的记录 select * from table_name; 其中*表示表中的 ...

  4. [译]libcurl_tutorial

    Handle the Easy libcurl To use the easy interface, you must first create yourself an easy handle. Yo ...

  5. Java 8 (11) 新的日期和时间API

    在Java 1.0中,对日期和时间的支持只能依赖java.util.Date类.这个类只能以毫秒的精度表示时间.这个类还有很多糟糕的问题,比如年份的起始选择是1900年,月份的起始从0开始.这意味着你 ...

  6. 不讲CRUSH的Ceph教程是不完整的

    前面我们提到了Ceph是一个支持统一存储架构的分布式存储服务.简单介绍了Ceph的基本概念和基础架构包含的组件,其中最重要的就是底层的RADOS和它的两类守护进程OSD and Monitor.上篇文 ...

  7. Python学习日记之忽略删除字符串空白

    使用Python自带的函数strip可以剔除字符串开头.结尾.两端的空白 使用场景:用户输入验证 strip : 去除字符串两端的空白 rstrip : 去除字符串末尾(右端)的空白 lstrip : ...

  8. Linux系统命令及文件的浏览、管理和维护

    在linux中什么是一个文件的路径呢,说白了就是这个文件存在的地方,例如在上一章提到的/root/.ssh/authorized_keys 这就是一个文件的路径.如果你告诉系统这个文件的路径,那么系统 ...

  9. 小知识~清除系统盘的Hiberfil.sys

    Hiberfil.sys这个文件是系统休眠用的,时间长了你可能会占用几个G的磁盘空间,有时我们并不需要它,而又无法直接删除,这时,你可以使用CMD命令来关闭这个功能,关闭后,这个文件自动被删除. 1 ...

  10. Mac上简单常用Terminal命令

    方案1 SSH是一个非常伟大的工具,如果你要在互联网上远程连接到服务器,那么SSH无疑是最佳的候选.SSH是加密的,OpenSSH加密所有通信(包括密码),有效消除了窃听,连接劫持和其它攻击.本文将为 ...