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. 利用gradle加入构建版本

    在java的程序中,貌似都没有这个构建版本的概念.用的诸如eclipse. idea和android studio的IDE也没有直接提供构建版本的选项.只是我却想在android程序的版本其中加入一个 ...

  2. Unityclient通信測试问题处理(一)

    Unityclient通信測试问题处理(一) 近期在測试程序的通信模块时.遇到了一个问题:Unity的API函数仅仅能在主线程中调用.而作为client程序,我单独启用了一个监听线程来接收服务端发送的 ...

  3. 基于TI Davinci架构的多核/双核开发高速扫盲(以OMAP L138为例),dm8168多核开发參考以及达芬奇系列资料user guide整理

    基于TI Davinci架构的双核嵌入式应用处理器OMAPL138开发入门 原文转自http://blog.csdn.net/wangpengqi/article/details/8115614 感谢 ...

  4. 九度 题目1154:Jungle Roads

    题目描写叙述: The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid mon ...

  5. Android 採用HTML设计界面

    由于Android软件开发分工眼下还没有细化,程序猿往往须要负责软件界面的开发,尽管软件的界面图片已经由美工设计好了.可是假设使用layout技术把软件做成美丽的界面确实非常困难,而是也比較耗时.An ...

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

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

  7. 第一个WPF

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. Android 学习笔记进阶14之像素操作

    在我们玩的游戏中我们会经常见到一些图像的特效,比如半透明等效果.要实现这种半透明效果其实并不难,需要我们懂得图像像素的操作. 不要怕,其实在Android中Bitmap为我们提供了操作像素的基本方法. ...

  9. ShareSDk的使用

    效果: 具体操作参考Mob官网shareSdk的文档 调用方法 public class MainActivity extends Activity { @Override protected voi ...

  10. MyBatis自动生成代码之generatorConfig配置文件及其详细解读

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...