3/5/2014 cfb 小心

During each move the player can choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!"

 这个 看成是 选其所有干行  我却看成是选其中 若干 行 水一下自己

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
char map[1005][1005];
int N[1005],L[1005];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)==2){
            bool flag=0;
        for(int i=0;i<n;i++){
             scanf("%s",map[i]);
             for(int j=0;j<m;j++)
             if(map[i][j]=='G'){ L[i]=j;break; }
        }
       for(int i=0;i<n;i++){
         int j;
        for(  j=L[i];j<m;j++)if( map[i][j]=='S'){ N[i]=j-L[i];break; }
         if(j==m){ flag=1;break;}
       }
       if(flag){ printf("-1
"); }
       else {
            int num=1;
            sort(N,N+n);
            for(int i=0;i<n-1;i++)
                if(N[i]!=N[i+1])
                   num++;
             printf("%d
",num);
         }

       }


    return 0;
}



原文地址:https://www.cnblogs.com/Opaser/p/3662027.html