Posts

Showing posts from April, 2017

uva 10507 Waking up brain Solution

Waking up brain Solution uva id : erfan05 Accepted Time : 0.000 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<string> #include<set> #include<map> using namespace std; typedef set<char> set_char; typedef map<char, set_char> map_char_set_char; typedef map_char_set_char::iterator map_char_set_char_iterator; typedef set_char::iterator set_char_iterator; int main(){ map_char_set_char mymap; set_char_iterator sit,it; map_char_set_char_iterator mit; set_char life,life_progress; string str; char ch1, ch2; int i, n, year, row; while (cin >> n >> row){ cin >> str; life.clear(); life_progress.clear(); mymap.clear(); life.insert(str[0]); life.insert(str[1]); life.insert(str[2]); for (i = 0; i < row; i++){ cin >> str; ch1 = str[0]; ch2 = str[1]; sit = life.find(ch1); if (sit == life.end()){ mit = mymap.find(ch1); if (mit == mymap....

uva 10895 Matrix Transpose Solution

  Matrix Transpose Solution uva id : erfan05 Accepted Time : 0.000 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<queue> #include<vector> #include<map> #include<set> #include<string> using namespace std; typedef vector<int> vector_int; typedef map<int, vector_int> map_int_vector_int; int main(){ freopen("input.txt", "r", stdin); map_int_vector_int index_map,value_map; vector_int index, value; int i, j, m, n, val, pos, x; while (cin >> m >> n){ index_map.clear(); value_map.clear(); for (i = 1; i <= n; i++){ vector_int v1,v2; index_map[i] = v1; value_map[i] = v2; } for (i = 1; i <= m; i++){ cin >> x; if (x == 0) continue; index.clear(); for (j = 1; j <= x; j++){ cin >> pos; index_map[pos].push_back(i); index.push_back(pos); } for (j = 0; j < x; ...

uva - 599 The Forrest for the Trees Solution

The Forrest for the Trees  #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<queue> #include<vector> #include<map> #include<set> #include<string> using namespace std; typedef vector<char> vector_char; typedef map<char, vector_char> map_vector_char; typedef set<char> set_char; typedef map_vector_char::iterator map_vector_char_iterator; typedef set_char::iterator set_char_iterator; int main(){ freopen("input.txt", "r", stdin); int i,test,forest,acorn; string str; char ch1,ch2; map_vector_char mymap; map_vector_char_iterator mit; set_char myset; set_char_iterator sit; queue<char> q; cin >> test; getchar(); while (test--){ mymap.clear(); while (true){ getline(cin, str); if (str[0] == '*') break; ch1 = str[1]; ch2 = str[3]; mit = mymap.find(ch1); if (mit == mymap.end()){ vector_c...

uva 11503 Virtual Friends Solution

uva 11503 Virtual Friends #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<map> #include<string> using namespace std; map<string, int> mymap; map<string, int> ::iterator mit; int val[100005], parent[100005]; int findParent(int x){ if (parent[x] == x) return x; else return findParent(parent[x]); } int main(){ int i, x, y, n, test; string str1, str2; cin >> test; while (test--){ cin >> n; for (i = 0; i < 100005; i++){ parent[i] = i; val[i] = 1; } mymap.clear(); for (i = 0; i < n; i++){ cin >> str1 >> str2; mit = mymap.find(str1); if (mit == mymap.end()){ x = mymap.size(); mymap[str1] = x; } else{ x = mit->second; } mit = mymap.find(str2); if (mit == mymap.end()){ y = mymap.size(); mymap[str2] = y; } else{ y = mit->second; } x = findParent(x); y = findParent(y); if (...