原poj 2713(基础题)

来源:互联网 发布:百衲本二十四史 知乎 编辑:程序博客网 时间:2024/06/04 18:45

计算区域内像素点个数

vector<vector<int> >  必须在>和>之间空一个格

未分配区域前不能下表访问vector

#include <iostream>#include <fstream>#include <string>#include <algorithm>#include <vector>using namespace std;#define _debbug//全局数据int main(){//重定向#ifdef _debbugstreambuf *backup1;ifstream  fin;fin.open ("F:\\input.txt" ,ios::in  );backup1 = cin.rdbuf() ;    // back up cin's streambufcin.rdbuf( fin.rdbuf() ) ; // assign file's streambuf to cin#endif    //vector<vector<int> >    graph1 ;int n ;int i,j ;cin >> n ;graph1.resize(n) ;for (i = 0 ; i < n ; ++i){graph1[i].resize(n) ;for (j = 0 ; j < n ; ++j){int val ;cin >> val ;graph1[i][j] = val   ;}}int leftx,lefty,rightx,righty,flag = 0;for (i = 0 ; i < n ; ++i){if (flag == 1)break;for (j = 0 ; j < n ; ++j){if (graph1[i][j] == 255)continue ;else{leftx = j ;lefty = i ;flag = 1;break ;}}}for (i = lefty ,j = leftx ; i < n ; ++i){if (graph1[i][j] == 0)continue ;else break ;}if (i < n)rightx = i - 1 ;elserightx = n - 1 ;for (i = lefty ,j = rightx ; j < n ; ++j){if (graph1[i][j] == 0)continue ;else break ;}if (j < n)righty = j - 1 ;elserighty = n - 1 ;cout << (rightx - leftx - 1) * (righty - lefty - 1) << endl ;//解除重定向关闭文件#ifdef _debbugcin.rdbuf(backup1) ;     // restore cin's original streambuffin.close();#endifreturn 0 ;}


 

原创粉丝点击