1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include <stdlib.h> #include <iostream> #include <fstream> #include <sstream> #include <string> #include <utility> #include <vector>
using namespace std;
typedef long long ll; typedef double db;
long flag = 2; long START = flag;
int recursion(ll i, ll j, vector<vector<ll> > &data, vector<pair<ll,ll> > &position); int launch( vector<vector<ll> > &data, vector<vector<db> > &data2);
int main(int argc, char * argv[]) { if (argc != 3) { cout<<"Enter two file"<<endl; return -1; } ifstream fin(argv[1]); ifstream fin2(argv[2]);
vector<vector<ll> > data; vector<vector<db> > data2; vector<ll> temp; ll v; vector<db> temp2; db d;
string line; string value; while (getline(fin,line)) { stringstream ss(line); while (getline(ss,value,' ')) { v = atoi(value.c_str()); temp.push_back(v); } data.push_back(temp); temp.clear(); }
while (getline(fin2,line)) { stringstream ss(line); while (getline(ss,value,' ')) { d = atoi(value.c_str()); temp2.push_back(d); } data2.push_back(temp2); temp2.clear(); }
launch(data,data2);
for (vector<vector<ll> >::iterator it = data.begin(); it != data.end(); ++it) { for (vector<ll>::iterator i = (*it).begin(); i != (*it).end(); ++i) cout<<*i<<" "; cout<<endl; }
}
int launch(vector<vector<ll> > &data, vector<vector<db> > &data2) { vector<vector<pair<ll,ll> > > result; vector<pair<ll,ll> > temp; for (int i = 0; i < data.size(); ++i) { for (int j = 0; j < data[0].size(); ++j) { if (data[i][j] == 1) { temp.push_back(make_pair(i,j)); data[i][j] = flag; recursion(i,j,data,temp); flag++; result.push_back(temp); temp.clear(); } } }
pair<ll,ll> pos; db inten = 0; for (vector<vector<pair<ll,ll> > >::iterator it = result.begin(); it != result.end(); ++it) { for (vector<pair<ll, ll> >::iterator jt = (*it).begin(); jt != (*it).end(); ++jt) { if (inten <= data2[(*jt).first][(*jt).second]) { inten = data2[(*jt).first][(*jt).second]; pos.first = (*jt).first; pos.second = (*jt).second; } } printf("The %d points's max intensity is: %d\n", int(START), int(inten)); START ++; inten = 0; }
return 0; }
int recursion(ll i, ll j, vector<vector<ll> > &data, vector<pair<ll,ll> > &position) { for (int x = i - 1; x <= i + 1; x++) { for (int y = j - 1; y <= j + 1; y++) { if (x == i && y == j) continue; if (x >= 0 && x < data.size() && y >= 0 && y < data[0].size() && data[x][y] == 1) { position.push_back(make_pair(x, y)); data[x][y] = flag; recursion(x,y,data,position); } } } return 0; }
|