SRM211 div1 500pt 搜尋應用

來源:互聯網
上載者:User

題意是給出400X600的矩陣,不斷在矩陣400X600內劃矩陣,第一次被划過的矩陣地區顏色改變,問的是經過多次劃矩陣後,400X600矩陣內沒有改變顏色的地區,連通地區的塊數和連通地區大小,按照連通地區大小從小到大排序;

思路就是:每次划過的矩陣地區顏色改變(已經變過的不用改變);然後循環圖表;依次搜尋顏色沒變的點;

其中學到了把字串轉化為整數可以用 istringstream;

#include <cstdlib>#include <cctype>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <iostream>#include <sstream>#include <set>#include <queue>#include <stack>#include <ctime>using namespace std;typedef long long ll;#define clr(x,a) memset(x,a,sizeof(x))#define sz(x) (int)x.size()#define see(x) cerr<<#x<<" "<<x<<endl#define se(x) cerr<<" "<<x #define pb push_back#define mp make_pairbool map[400][600];int dx[]={1,-1,0,0},dy[]={0,0,1,-1};int n,m;class grafixMask{        public:        vector <int> sortedAreas(vector <string> rectangles)        {               clr(map,0);            int i,j,k;            int x1,x2,y1,y2;            n=rectangles.size();              for(k=0;k<n;k++)              {                   istringstream L(rectangles[k]);                    L>>x1>>y1>>x2>>y2;                   for(i=x1;i<=x2;i++)                   for(j=y1;j<=y2;j++)                   {                    map[i][j]=1;                   }              } vector<int>num;                 for(i=0;i<400;i++)                 for(j=0;j<600;j++)                  if(map[i][j]==0)  {   int con=0;         map[i][j]=1;      queue<pair<int,int> >Q;  Q.push(make_pair(i,j));     while(!Q.empty()) {con++; int x=Q.front().first,y=Q.front().second; Q.pop();      for(k=0;k<4;k++)   {      int xx=x+dx[k],yy=y+dy[k];  if(xx>=0&&xx<400&&yy>=0&&yy<600&&map[xx][yy]==0)  {     map[xx][yy]=1; Q.push(make_pair(xx,yy));   }   } } num.push_back(con);  }   sort(num.begin(),num.end());             return num;        }                 };


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.