Codeforces Round #234 (Div. 2):B. Inna and New Matrix of Candies
1 second
256 megabytes
standard input
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.
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".
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.
3 4
*G*S
G**S
*G*S
2
1 3
S*G
-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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #234 (Div. 2)
A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input st ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #482 (Div. 2) :B - Treasure Hunt
题目链接:http://codeforces.com/contest/979/problem/B 解题心得: 这个题题意就是三个人玩游戏,每个人都有一个相同长度的字符串,一共有n轮游戏,每一轮三个人必 ...
- Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)
F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...
随机推荐
- Qt源码编译
Qt源码编译 eryar@163.com Key words. Qt, 源码编译 1.Introduction 随着Qt版本升级,源码编译出来的库体积越来越大.如果只是用Qt来做GUI,Qt提供的预编 ...
- tomcat 分别在window 和 Linux上配置SSL-安全问题
公司项目收尾后.通过压力測试后的安全測试.安全測试后中,对于网络传输中数据加密问题存在安全隐患. 须要配置SSL. 简介下SSL协议:SSL或者Secure Socket Layer,是一种同意web ...
- mysql异常Lock wait timeout exceeded; try restarting transaction
mysql中使用update语句更新数据报错: Lock wait timeout exceeded; try restarting transaction. 这是由于你要更新的表的锁在其它线程手里. ...
- Array与ArrayList
代码图理解复杂代码 类图 1.抽象动物类Animal using System; using System.Collections.Generic; using System.Linq; using ...
- BZOJ 1355 KMP中next数组的应用
思路: 我们知道 next[i]是失配的i下一步要去哪儿 next[n]就是失配的n要去哪儿 n-next[n]就是答案(即最短周期)啦 //By SiriusRen #include <cst ...
- pix格式的一些摸索
作者:朱金灿 来源:http://blog.csdn.net/clever101 以前因为工作关系研究过PCI的系统格式pix,但是遗留了一些问题,最近又想重新解决这些问题.研究了一天,有些收获,但是 ...
- RGB-D action recognition using linear coding
First, a depth spatial-temporal descriptor is developed to extract the interested local regions in d ...
- c# array arraylist 泛型list
1 array 数组 是存储相同类型元素的固定大小的数据的顺序集合.在内存中是连续存储的,所以索引速度非常快,而且赋值和修改元素也非常简单. //定义字符串数组 大小为3 string[] str1 ...
- 使用Java语言开发微信公众平台(五)——被关注回复与关键词回复
在上一篇文章中,我们实现了文本消息的接收与响应.可以在用户发送任何内容的时候,回复一段固定的文字.本章节中,我们将对上一章节的代码进行适当的完善,同时实现[被关注回复与关键词回复]功能. 一.微信 ...
- C/C++(函数)
函数 函数三要素:函数名,参数,返回值 重点研究函数的输入输出 随机数函数 //产生一组随机数 #include<stdio.h> #include<stdlib.h> #in ...