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 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

開始题意理解错了,以为仅仅要一行有个G到了S就停止,记录经过多少个S。。。额。

。

英语渣真心无脑脑补。。

2333333。

。。

题目意思:
给n*m的方格,每行中都且仅有一个方格含S和G。每一步能够使全部的G向右移,仅仅到发生下列情况: 1、某个G已到了最后一列。 2、某个G已到了S。 求把全部的G已到S须要的最少的步数。 解题思路: 统计S-G差出现的个数。 由于两个差相等的话,他们会一起到达S。也就不要算额外的步数。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector> using namespace std; const int N = 1020;
int n , m;
int a, b;
int s[N];
char str[N][N];
int flag;
int ans; int main()
{
while( scanf("%d%d", &n, &m)!=EOF )
{
int flag = 0;
memset( s, 0, sizeof(s) );
ans = 0;
for(int i=0; i<n; i++)
{
scanf("%s", str[i]);
for(int j=0; j<m; j++)
{
if( str[i][j]=='G' )
a = j;
if( str[i][j]=='S' )
b = j;
}
if( a<b )
s[ b-a ]++;
else
flag=1;
}
for( int i=0; i<m; i++ )
{
if( s[i] )
ans++;
}
if( flag )
printf("-1\n");
else
printf("%d\n", ans);
} return 0;
}

Codeforces Round #234 (Div. 2):B. Inna and New Matrix of Candies的更多相关文章

  1. 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 ...

  2. 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 ...

  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 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) A. Inna and Choose Options 模拟题

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

  7. Codeforces Round #482 (Div. 2) : Kuro and GCD and XOR and SUM (寻找最大异或值)

    题目链接:http://codeforces.com/contest/979/problem/D 参考大神博客:https://www.cnblogs.com/kickit/p/9046953.htm ...

  8. Codeforces Round #482 (Div. 2) :B - Treasure Hunt

    题目链接:http://codeforces.com/contest/979/problem/B 解题心得: 这个题题意就是三个人玩游戏,每个人都有一个相同长度的字符串,一共有n轮游戏,每一轮三个人必 ...

  9. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

随机推荐

  1. 怎样借助log4j把日志写入数据库中

            log4j是一个优秀的开源日志记录项目.我们不仅能够对输出的日志的格式自定义,还能够自定义日志输出的目的地,比方:屏幕.文本文件,数据 库,甚至能通过socket输出.本节使用MySQ ...

  2. [当我在研究Cocos-2dx的源代码时,我在想什么]-Ref类,一切的起源

    [名词解释]      引用计数:引用计数是现代内存管理中常常使用到的一个概念.它的基本思想是通过计数方式实现多个不同对象同一时候引用一个共享对象,详细地讲,当创建一个对象的实例并在堆上分配内存时,对 ...

  3. 第二天,导出文件sql,查询,视图view,聚合函数,反模式,字符串处理函数

    //把数据库导出到脚本文件mysqldump -uroot -p1234 --databases abc > d:/a/abc.sql CREATE TABLE stud( id INT PRI ...

  4. vim 技巧之用宏命令批量处理文件

    今天遇到了一种情况,就是我需要同时修改34个文件中的某些字符串的内容,如果一个个打开需改的话,那也太麻烦了.后来就想着能不能通过vim的宏命令来修改呢?现在就总结下关于宏在文件列表中的应用1.首先,我 ...

  5. 你如何理解 HTML5 的 section?会在什么场景使用?为什么这些场景使用 section 而不是 div?

    section元素表示文档或应用的一个部分.所谓“部分”,这里是指按照主题分组的内容区域,通常会带有标题.[也就是每个section对应不同的主题.注意是内容本身的主题,而不是其他人为设定的划分标准. ...

  6. 【Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) C】 Travelling Salesman and Special Numbers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 会发现. 进行一次操作过后. 得到的数字肯定是<=1000的 然后1000以下可以暴力做的. 则我们枚举第1步后得到的数字x是 ...

  7. Mysql学习总结(18)——Mysql主从架构的复制原理及配置详解

    一.复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重 ...

  8. Android Cordova 插件开发之编写自己定义插件

    前言 本文适合Android+web的复合型人才,由于cordova本身就是混合开发,所以在Android开发的基础上,还要懂web相关技术(HTML+CSS+JS).可是也有例外,比方我.仅仅需负责 ...

  9. ps的入门

    ps的入门 http://www.cnblogs.com/qingci/archive/2012/09/20/2694728.html

  10. var、let和const的区别

    var 首先var有变量提升 console.log(a); // undefined var a = 1; function也存在提升现象 console.log(b); //function b( ...