Inna and New Matrix of Candies (codeforces-400b) __code

Source: Internet
Author: User

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; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.