Click to open the link
At the beginning, the understanding was wrong. Then constantly tangled in that, the Internet to see other people's blog, did not see the idea said very clearly, there is a translation of particularly funny.
Here is a careful word:
In a matrix of n rows m columns, each row has a dwarf statue and a candy, the purpose of which is to make every dwarf statue get candy. Now, let each line of dwarf statues go right at the same time, and stop when a dwarf statue encounters a candy bar.
This is called a move, note, note that a moving can take more steps ah ... PS: The title of the right end of this condition, can completely remove Qaq.
So this is a very clear question.
1: If there is a line with a dwarf statue on the right side of the candy, direct output-1
2: Each line of the dwarf statue to Candy has a distance, put this distance into the array, also n, and then find out how many different values in the array OK.
Foreigners really can play, this is the same problem, originally as long as the C language on the line, must be engaged to get, forced to show English, is also drunk.
Code:
#include <iostream> #include <algorithm> using namespace std;
Char a[1010][1010];
int dis[1010];//is used to keep the distance of int main () {int n,m,count,flag;
while (cin>>n>>m) {int temp1,temp2;
for (int i=0;i<=n-1;i++) for (int j=0;j<=m-1;j++) cin>>a[i][j];
count=0; flag=1;//flag number, just do it. for (int i=0;i<=n-1;i++) {for (int j=0;j<=m-1;j++) {if (a[
i][j]== ' G ') temp1=j;
if (a[i][j]== ' S ') temp2=j;
} if (temp2-temp1<0) {flag=0;
Break
else {dis[count]=temp2-temp1;
count++;
} if (flag==0) {cout<<-1<<endl;
Continue
Sort (dis,dis+count);
int Res=1;
for (int i=1;i<=count-1;i++)//order, and then count {if (dis[i]!=dis[i-1]) res++; } cout<<res<< Endl;
return 0; }