zoukankan      html  css  js  c++  java
  • 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
    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

    
    #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 = 0 ;i<n;i++)
        {
            cin>>mtx;
            int x = mtx.find("G");
            int y = mtx.find("S");
            s.insert(y-x);
        }
        if(*s.begin() < 0)
            cout<<-1<<endl;
        else
            cout<<s.size()<<endl;
        return 0;
    }
  • 相关阅读:
    JQuery选择器
    JQuery语法
    数据库分页查询
    webservice开发说明文档
    javaweb项目中的文件上传下载功能的实现
    表单中input的type用法详解
    关于所谓大数据的一些疑惑
    spring boot 常见的第三方集成
    spring boot + apache camel 传输文件
    spring boot 1.x配置,不断完善中
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4138266.html
Copyright © 2011-2022 走看看