Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies SET的妙用
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
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
string mtx;
int n,m;
set<int> s;
int main()
{
cin>>n>>m;
for(int i = ;i<n;i++)
{
cin>>mtx;
int x = mtx.find("G");
int y = mtx.find("S");
s.insert(y-x);
}
if(*s.begin() < )
cout<<-<<endl;
else
cout<<s.size()<<endl;
return ;
}
Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies SET的妙用的更多相关文章
- 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) 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 #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)
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 #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...
- Codeforces Round #220 (Div. 2) D - Inna and Sequence
D - Inna and Sequence 线段数维护区间有几个没有被删除的数,利用线段树的二分找第几个数在哪里,然后模拟更新就好啦. #include<bits/stdc++.h> #d ...
- Codeforces Round #223 (Div. 2) A
A. Sereja and Dima time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- Flask:使用Eclipse+PyDev插件编辑基于package的项目
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2,Eclipse Oxygen.1a Release (4.7.1a),PyDev 6.3.2 本文记录了 使用Ecli ...
- 序列化 json和pickle
序列化 1. 什么叫序列化 将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 2. json dumps loads 一般对字典和列表序列化 dump load 一般对 ...
- XShell安装
Xshell就是一个远程控制Centos的软件:(用XShell比较方便,试用的都知道,界面也人性化) 详细介绍请看 百度百科 下面我们来安装下这个工具: 双击exe 点下一步: 选 免费的 然后下一 ...
- Python模块Pygame安装
一.使用pip安装Python包 大多数较新的Python版本都自带pip,因此首先可检查系统是否已经安装了pip.在Python3中,pip有时被称为pip3. 1.在Linux和OS X系统中检查 ...
- bzoj 4034(DFS序+线段树)
这个题多了一个操作难度直线上升,看完题解才会写 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种:操作 1 :把某个节点 x 的点权增加 a .操作 2 :把某个节点 ...
- HBase 入门笔记-数据落地篇
一.前言 关于数据落地方面,HBase官网也有相关介绍.本文主要介绍一下实际工作中涉及的数据存储方面的一些经验和技巧,主要涉及表rowkey设计.数据落地方案 二.表设计 相对于MySQL等关系型数据 ...
- spark java API 实现二次排序
package com.spark.sort; import java.io.Serializable; import scala.math.Ordered; public class SecondS ...
- 聊一聊FE面试那些事【原创】
最近公司由于业务的扩展.技术的延伸需要招一批有能力的小伙伴加入,而我有幸担任"技术面试官"的角色前前后后面试了不下50多位候选人,如同见证了50多位前端开发者的经历一样,在面试的过 ...
- jquery最精简的全选反选功能
RT代码: function selallno(){ $('#form2 input[name=sel]:checkbox:not(:checked)').attr('checked',$('#for ...
- Abstract Factory 抽象工厂
意图 提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类. 适用性 一个系统要独立于它的产品的创建.组合和表示时 结构 参与者 AbstractFactory:声明一个创建抽象产品对象 ...