├── .gitignore ├── BedirT ├── Chapter 2 │ ├── UVa - 10038.cpp │ ├── UVa - 10258.cpp │ ├── UVa - 10954.cpp │ ├── UVa - 11286.cpp │ ├── UVa - 11581.cpp │ ├── UVa - 11933.cpp │ ├── UVa - 11988.cpp │ ├── UVa - 12532.cpp │ ├── UVa - 599.cpp │ ├── UVa - 793.cpp │ └── UVa - 978.cpp ├── Chapter 3 │ ├── UVa - 10337.cpp │ ├── UVa - 1047.cpp │ ├── UVa - 10487.cpp │ ├── UVa - 10660.cpp │ ├── UVa - 10755.cpp │ ├── UVa - 10819.cpp │ ├── UVa - 11085.cpp │ ├── UVa - 11157.cpp │ ├── UVa - 11389.cpp │ ├── UVa - 11951.cpp │ ├── UVa - 12032.cpp │ ├── UVa - 12192.cpp │ ├── UVa - 12210.cpp │ ├── UVa - 1237.cpp │ ├── UVa - 12455.cpp │ ├── UVa - 1262.cpp │ ├── UVa - 183.cpp │ ├── UVa - 357.cpp │ ├── UVa - 441.cpp │ ├── UVa - 481.cpp │ └── UVa - 524.cpp ├── Chapter 4 │ ├── UVa - 10004.cpp │ ├── UVa - 10171.cpp │ ├── UVa - 10305.cpp │ ├── UVa - 10350.cpp │ ├── UVa - 10369.cpp │ ├── UVa - 10557.cpp │ ├── UVa - 1056.cpp │ ├── UVa - 1103.cpp │ ├── UVa - 1112.cpp │ ├── UVa - 11487.cpp │ ├── UVa - 11492.cpp │ ├── UVa - 11747.cpp │ ├── UVa - 12442.cpp │ ├── UVa - 247.cpp │ ├── UVa - 924.cpp │ └── UVa - 988.cpp ├── Chapter 5 │ ├── UVa - 10586.cpp │ ├── UVa - 10751.cpp │ ├── UVa - 11231.cpp │ ├── UVa - 11254.cpp │ ├── UVa - 11723.cpp │ ├── UVa - 11879.cpp │ ├── UVa - 12036.cpp │ ├── UVa - 1210.cpp │ ├── UVa - 1225.cpp │ ├── UVa - 377.cpp │ ├── UVa - 389.cpp │ └── UVa - 443.cpp └── README.md ├── Contests ├── README.md └── September_16 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── F.cpp ├── Quyen ├── Chap 2 │ ├── UVa 10038 - Jolly Jumber.cpp │ ├── Uva 00599 - The Forest For The Tree.cpp │ ├── Uva 00987 - Lemmings Battle.cpp │ ├── Uva 10258 - Contest Scoreboard.cpp │ ├── Uva 10954 - Add All.cpp │ ├── Uva 11286 - Conformity.cpp │ ├── Uva 11933 - Splitting Number.cpp │ ├── Uva 11988 Broken Keyboard.cpp │ ├── Uva 12532 - Interval Product.cpp │ └── Uva793 Network Connection.cpp ├── Chap 3 │ ├── UVa 12455 - Bars.cpp │ ├── Uva 01237 - Expert Enough.cpp │ ├── Uva 10487 - Closest Sum.cpp │ ├── Uva 11085 - Back to the 8 Queen.cpp │ ├── Uva 12032 - The Monkey.cpp │ ├── Uva 12192 - Grapevine.cpp │ └── Uva 441 - Lotto.cpp └── README.md ├── README.md ├── iRasuna ├── Chapter 2 │ ├── UVa 10038.cpp │ ├── UVa 10258.cpp │ ├── UVa 1062.cpp │ ├── UVa 11933.cpp │ └── UVa 11988.cpp └── README.md └── nadide ├── Chapter2 ├── UVa-00599.cpp ├── UVa-00793.cpp ├── UVa-10038.cpp ├── UVa-1062.cpp ├── UVa-11286.cpp ├── UVa-11581.cpp └── UVa-12532.cpp ├── Chapter3 ├── 00183-Bit-Maps.cpp ├── UVa-00357.cpp ├── UVa-00441.cpp ├── UVa-01237.cpp ├── UVa-10487.cpp └── UVa-10660.cpp └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | *.smod 19 | 20 | # Compiled Static libraries 21 | *.lai 22 | *.la 23 | *.a 24 | *.lib 25 | 26 | # Executables 27 | *.exe 28 | *.out 29 | *.app 30 | 31 | # For Mac: 32 | *.DS_Store 33 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 10038.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | int vc[3001]; 7 | int main () { 8 | int n, a, b; 9 | while(cin >> n){ 10 | cin >> a; 11 | for(int i = 1; i < n ; ++i){ 12 | cin >> b; 13 | vc[abs(b-a)] = 1; 14 | a = b; 15 | } 16 | bool flag = true; 17 | for(int i = 1; i < n ; ++i){ 18 | if(!vc[i]){ 19 | flag = false; 20 | break; 21 | } 22 | } 23 | if(flag) cout << "Jolly" << endl; 24 | else cout << "Not jolly" << endl; 25 | memset(vc, 0, sizeof(vc)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 10258.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | // #define fin cin 10 | // #define fout cout 11 | 12 | using namespace std; 13 | 14 | int main () { 15 | 16 | // ifstream fin; 17 | // ofstream fout; 18 | // fin.open("input.txt"); 19 | // fout.open("output.txt"); 20 | int t; 21 | string s; 22 | cin >> t; 23 | // cout << t << endl; 24 | getline(cin , s); 25 | // cout << s << endl; 26 | getline(cin , s); 27 | // cout << s << endl; 28 | while(t--){ 29 | // cout << "IN\n"; 30 | int team, prob, time; 31 | char stat; 32 | int ar[101][10][2]; // 100 Teams, 9 Questions, 1 Spot for penalty 1 for if solved 33 | int iftried[101]; 34 | memset(ar, 0, sizeof(ar)); // 0 initialized 35 | memset(iftried, 0, sizeof(iftried)); 36 | while(getline(cin , s)){ 37 | if(s == "") break; 38 | 39 | istringstream ss(s); 40 | ss >> team >> prob >> time >> stat; 41 | //cout << stat << endl; 42 | iftried[team] = 1; 43 | // cout << team << endl; 44 | if(ar[team][prob][1] == 0){ 45 | if(stat == 'I'){ // If incorrect 46 | ar[team][prob][0] += 20; 47 | } else if(stat == 'C'){ // If correct 48 | ar[team][prob][1] = 1; 49 | ar[team][prob][0] += time; 50 | } else; // Otherwise 51 | } // close if 52 | } // close while -cin- 53 | /* for(int i = 1; i < 101; ++i){ 54 | cout << iftried[i] << " "; 55 | }cout << endl; 56 | */ vector > vc; 57 | vector nonSolved; 58 | for(int i = 9; i > 0; --i){ 59 | vc.clear(); 60 | 61 | for(int j = 1; j <= 100; ++j){ 62 | bool flag = false; 63 | int num = 0, penalty = 0; 64 | for(int k = 1; k <= 9; ++k) { 65 | if(ar[j][k][1] == 1){ 66 | num++; 67 | penalty += ar[j][k][0]; 68 | flag = true; 69 | } 70 | } 71 | if(!flag && iftried[j]){ 72 | nonSolved.push_back(j); 73 | iftried[j] = 0; 74 | } 75 | else if(num == i) vc.push_back(make_pair(penalty,j)); 76 | } 77 | sort(vc.begin(), vc.end()); 78 | // cout << "IM HERE\n"; 79 | for(vector >::iterator it = vc.begin(); it != vc.end(); ++it){ 80 | cout << (*it).second << " " << i << " " << (*it).first << endl; 81 | } 82 | } 83 | for(int i = 0; i < nonSolved.size(); ++i) cout << nonSolved[i] << " 0 0" << endl; 84 | nonSolved.clear(); 85 | if(t) cout << endl; 86 | 87 | } // close while -t- 88 | // fin.close(); 89 | // fout.close(); 90 | } 91 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 10954.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | // #include 6 | // #define fin cin 7 | // #define fout cout 8 | using namespace std; 9 | 10 | int main (){ 11 | // ifstream fin; 12 | // ofstream fout; 13 | // fin.open("input.txt"); 14 | // fout.open("output.txt"); 15 | 16 | int t, k; 17 | while(1){ 18 | cin >> t; 19 | vector vc; 20 | vc.clear(); 21 | if(!t) break; 22 | for(int i = 0; i < t; ++i){ 23 | cin >> k; vc.push_back(k); 24 | } 25 | int tot = 0; 26 | while(vc.size() > 1){ 27 | sort(vc.begin(), vc.end()); 28 | tot += vc[0] + vc[1]; 29 | vc.push_back(vc[0] + vc[1]); 30 | vc.erase(vc.begin(), vc.begin()+2); 31 | } 32 | cout << tot << endl; 33 | } 34 | // fin.close(); 35 | // fout.close(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 11286.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | 9 | while(1){ 10 | int n; 11 | cin >> n; 12 | if(n == 0) break; 13 | map, int> mp; 14 | int mx = 1; 15 | for(int i = 0 ; i < n; ++i){ 16 | vector v(5); 17 | for(int j = 0; j < 5; ++j) cin >> v[j]; 18 | sort(v.begin(), v.end()); 19 | mp[v]++; 20 | } 21 | int counter = 0; 22 | for(map, int>::iterator it = mp.begin(); it != mp.end(); ++it){ 23 | int a = it->second; 24 | if(a == mx){ 25 | counter += a; 26 | } 27 | if(a > mx){ 28 | mx = a; 29 | counter = mx; 30 | } 31 | } 32 | cout << counter << endl; 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 11581.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 11581 3 | Related Topic: - 4 | Author: BedirT 5 | Date: 05/27/2017 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | int g[2][3][3]; string s; 13 | 14 | void f() { 15 | 16 | g[1][0][0] = (g[0][0][1] + g[0][1][0]) % 2; 17 | g[1][0][1] = (g[0][0][0] + g[0][1][1] + g[0][0][2]) % 2; 18 | g[1][0][2] = (g[0][0][1] + g[0][1][2]) % 2; 19 | 20 | g[1][1][0] = (g[0][0][0] + g[0][1][1] + g[0][2][0]) % 2; 21 | g[1][1][1] = (g[0][0][1] + g[0][1][0] + g[0][1][2] + g[0][2][1]) % 2; 22 | g[1][1][2] = (g[0][1][1] + g[0][0][2] + g[0][2][2]) % 2; 23 | 24 | g[1][2][0] = (g[0][2][1] + g[0][1][0]) % 2; 25 | g[1][2][1] = (g[0][2][0] + g[0][1][1] + g[0][2][2]) % 2; 26 | g[1][2][2] = (g[0][2][1] + g[0][1][2]) % 2; 27 | 28 | for (int i=0; i < 3; i++) 29 | for (int j=0; j < 3; j++) 30 | g[0][i][j] = g[1][i][j]; 31 | } 32 | 33 | bool done(){ 34 | for(int i = 0;i < 3; ++i) 35 | for(int j = 0; j < 3; ++j) 36 | if(g[0][i][j] != 0) return false; 37 | return true; 38 | } 39 | 40 | int main (){ 41 | int t; cin >> t; 42 | while(t--) { 43 | scanf("\n"); 44 | for (int i = 0; i < 3; ++i) { 45 | cin >> s; 46 | for (int j = 0; j < 3; ++j) 47 | g[0][i][j] = s[j]-'0'; 48 | } 49 | 50 | int res = -1; 51 | while (!done()) { 52 | f(); 53 | res++; 54 | } 55 | cout << res << endl; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 11933.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | 9 | int n; 10 | cin >> n; 11 | while(n != 0){ 12 | string bin = bitset<32>(n).to_string(); 13 | int a = 0, b = 0; 14 | bool flag = true; 15 | for(int i = 0 ; i < 32; ++i){ 16 | if(bin[31-i] == '1' && flag){ 17 | a += pow(2, i); 18 | flag = false; 19 | }else if(bin[31-i] == '1'){ 20 | b += pow(2, i); 21 | flag = true; 22 | } 23 | } 24 | cout << a << " " << b << endl; 25 | cin >> n; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 11988.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main () { 9 | string s; 10 | list str; 11 | while(cin >> s){ 12 | str.clear(); 13 | list::iterator it = str.begin(); 14 | for(int i = 0; i < s.size() ; ++i){ 15 | // cout << str << endl; 16 | if(s[i] == '['){ 17 | it = str.begin(); 18 | } else if(s[i] == ']'){ 19 | it = str.end(); 20 | } else{ 21 | str.insert(it ,s[i]); 22 | } 23 | } 24 | for(it = str.begin() ; it != str.end(); ++it) cout << *it; 25 | cout << endl; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 12532.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | // #include 5 | // #define fin cin 6 | // #define fout cout 7 | using namespace std; 8 | int tree[1000001]; 9 | 10 | int RMQ(int L, int R){ 11 | int ans = 1; 12 | while(L <= R){ 13 | if(L % 2 == 1) ans *= tree[L]; 14 | if(R % 2 == 0) ans *= tree[R]; 15 | L = (L+1)/2; 16 | R = (R-1)/2; 17 | } 18 | return ans; 19 | } 20 | 21 | void update(int x){ 22 | for (int i = x; i >= 1; i /= 2) 23 | tree[i] *= -1; 24 | } 25 | 26 | int sign(int i){ 27 | if(i < 0) return -1; 28 | else if(i > 0) return 1; 29 | else return 0; 30 | } 31 | 32 | int main () { 33 | 34 | // ifstream fin; 35 | // ofstream fout; 36 | // fin.open("input.txt"); 37 | // fout.open("output.txt"); 38 | 39 | int n, sz = 1, res, k, a, b, jj; 40 | char op; 41 | 42 | while(cin >> n >> k){ 43 | while (n > sz) sz *= 2; 44 | for(int i = 0; i < 2*sz ; ++i) tree[i] = 1; 45 | for(int i = sz; i <= sz+n-1; ++i){ 46 | cin >> jj; 47 | tree[i] = sign(jj); 48 | } 49 | for(int i = sz-1; i >= 1; --i) 50 | tree[i] = sign(tree[2*i]) * sign(tree[2*i+1]); 51 | 52 | // for (int i = 1; i <= sz+n-1; ++i) { 53 | // cout << tree[i] << " " ; 54 | // }cout << endl << endl; 55 | 56 | while(k--){ 57 | cin >> op >> a >> b; 58 | if(op == 'C'){ 59 | if(sign(tree[sz+a-1])==sign(b)); 60 | else{ 61 | tree[sz+a-1] = sign(b); 62 | for(int i = sz-1; i >= 1; --i) 63 | tree[i] = sign(tree[2*i]) * sign(tree[2*i+1]); 64 | } 65 | } 66 | else{ 67 | int res = RMQ(a+sz-1 , b+sz-1); 68 | // cout << res << endl; 69 | if(res > 0) cout << "+"; 70 | else if(res < 0) cout << "-"; 71 | else cout << "0"; 72 | } 73 | } 74 | cout << endl; 75 | } 76 | // fin.close(); 77 | // fout.close(); 78 | } 79 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 599.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | // #include 5 | // #define fin cin 6 | // #define fout cout 7 | using namespace std; 8 | 9 | int res[30]; 10 | int size[30]; 11 | int root(int i) { 12 | while(res[i] != i){ 13 | res[i] = res[res[i]]; 14 | i = res[i]; 15 | } 16 | return i; 17 | } 18 | void Union(int a, int b) { 19 | int r1 = root(a); 20 | int r2 = root(b); 21 | // cout << r1 << " | " << r2 << endl; 22 | if(r1 == r2) return; 23 | else if(size[r1] < size[r2]){ 24 | res[r1] = res[r2]; 25 | size[r2] += size[r1]; 26 | }else{ 27 | res[r2] = res[r1]; 28 | size[r1] += size[r2]; 29 | } 30 | } 31 | 32 | int main () { 33 | 34 | // ifstream fin; 35 | // ofstream fout; 36 | // fin.open("input.txt"); 37 | // fout.open("output.txt"); 38 | 39 | int t; 40 | cin >> t; 41 | while(t--){ 42 | string s; 43 | set nodes; 44 | for(int i = 0; i < 30; ++i){ 45 | res[i] = i; 46 | size[i] = 1; 47 | } 48 | while(1){ 49 | cin >> s; 50 | if(s[0] == '*') break; 51 | Union(s[1]-65,s[3]-65); 52 | } 53 | cin >> s; 54 | for(int i = 0; i < s.size(); i+=2){ 55 | // cout << s[i] << " | res= " << size[s[i]-65] << endl; 56 | nodes.insert(res[s[i]-65]); 57 | } 58 | int acorn = 0, tree = 0; 59 | for(set::iterator it = nodes.begin(); it != nodes.end() ; ++it){ 60 | // cout << *it << " "; 61 | if(size[*it] == 1){ 62 | acorn++; 63 | } 64 | else{ 65 | tree++; 66 | } 67 | } 68 | cout << "There are " << tree << " tree(s) and " << acorn << " acorn(s)." << endl; 69 | } 70 | // fin.close(); 71 | // fout.close(); 72 | } 73 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 793.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int res[10005]; 6 | int size[10005]; 7 | 8 | int root(int i){ 9 | while(res[i] != i){ 10 | res[i] = res[res[i]]; 11 | i = res[i]; 12 | } 13 | return i; 14 | } 15 | void Union(int a, int b){ 16 | int r1 = root(a); 17 | int r2 = root(b); 18 | if(r1 == r2) return; 19 | else if(size[r1] < size[r2]){ 20 | res[r1] = res[r2]; 21 | size[r2] += size[r1]; 22 | }else{ 23 | res[r2] = res[r1]; 24 | size[r1] += size[r2]; 25 | } 26 | } 27 | bool find(int a, int b){ 28 | if(root(a) == root(b)) return true; 29 | else return false; 30 | } 31 | 32 | int main () { 33 | int t, n, a, b; 34 | char q; 35 | cin >> t; 36 | string s; 37 | while(t--){ 38 | scanf("\n%d\n",&n); 39 | int plus = 0, minus = 0; 40 | for(int i = 0; i <= n ; ++i){ 41 | res[i] = i; 42 | size[i] = 1; 43 | } 44 | 45 | 46 | while(1){ 47 | if(!getline(cin,s) || s.empty()) break; 48 | sscanf(s.c_str(),"%c %d %d",&q,&a,&b); 49 | if (q == 'c') Union(a, b); 50 | else if(find(a, b)) plus++; 51 | else minus++; 52 | } 53 | 54 | cout << plus << "," << minus << endl; 55 | if(t) cout << endl; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /BedirT/Chapter 2/UVa - 978.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main (){ 9 | int t, k; 10 | cin >> t; 11 | while(t--){ 12 | int a,b,g; 13 | cin >> a >> g >> b; 14 | vector sG, sB; 15 | multiset blue, green; 16 | multiset::iterator bIt, gIt; 17 | for(int i = 0; i < g; ++i){ 18 | cin >> k; 19 | green.insert(k); 20 | } 21 | for(int i = 0; i < b; ++i){ 22 | cin >> k; 23 | blue.insert(k); 24 | } 25 | while(blue.size() && green.size()){ 26 | // cout << "CHECK\n"; 27 | for(int i = 0; i < a && green.size() && blue.size() ; ++i){ 28 | // FIGHT 29 | bIt = blue.end(); 30 | gIt = green.end(); 31 | bIt--; gIt--; 32 | if(*bIt > *gIt){ 33 | sB.push_back(*bIt-*gIt); 34 | green.erase(gIt); 35 | blue.erase(bIt); 36 | } 37 | else if(*bIt < *gIt){ 38 | sG.push_back(*gIt-*bIt); 39 | blue.erase(bIt); 40 | green.erase(gIt); 41 | } 42 | else{ 43 | blue.erase(bIt); 44 | green.erase(gIt); 45 | } 46 | } 47 | for(int i = 0; i < sG.size(); ++i) green.insert(sG[i]); 48 | sG.clear(); 49 | for(int i = 0; i < sB.size(); ++i) blue.insert(sB[i]); 50 | sB.clear(); 51 | } 52 | // cout << "SAFE\n"; 53 | if(!blue.size() && !green.size()) cout << "green and blue died" << endl; 54 | else if(!blue.size()){ 55 | cout << "green wins" << endl; 56 | gIt = green.end() ; 57 | do{ 58 | gIt--; 59 | cout << *gIt << endl; 60 | }while (gIt != green.begin()); 61 | }else{ 62 | cout << "blue wins" << endl; 63 | bIt = blue.end() ; 64 | do{ 65 | bIt--; 66 | cout << *bIt << endl; 67 | }while (bIt != blue.begin()); 68 | 69 | } 70 | blue.clear(); 71 | green.clear(); 72 | if(t) cout << endl; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 10337.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int n , t, ar[10][10001], d[10][10001]; 5 | 6 | int main (){ 7 | cin >> t; 8 | while(t--){ 9 | 10 | scanf("\n%d", &n); 11 | 12 | memset(ar, 0, sizeof ar); 13 | 14 | for(int i = 9; i >= 0; --i) 15 | for(int j = 0; j < n/100; ++j){ 16 | cin >> ar[i][j]; 17 | } 18 | // Input array constructed 19 | // Initial values added to d 20 | 21 | for(int i = 0; i < 10; ++i){ 22 | d[i][0] = 0; 23 | for(int j = 1; j <= n/100+1; ++j) 24 | d[i][j] = 0xfffffff; 25 | } 26 | 27 | 28 | for(int j = 0; j <= n/100+1; ++j) 29 | for(int i = 0; i < 10; ++i){ 30 | d[i][j+1] = min(d[i][j+1], d[i][j] - ar[i][j+1] + 30); 31 | if(i != 9) d[i+1][j+1] = min(d[i+1][j+1], d[i][j] - ar[i+1][j+1] + 20); 32 | if(i != 0) d[i-1][j+1] = min(d[i-1][j+1], d[i][j] - ar[i-1][j+1] + 60); 33 | } 34 | 35 | // for(int i = 0; i < 10; ++i){ 36 | // for(int j = 0; j <= n/100+1; ++j){ 37 | // cout << d[i][j] << " "; 38 | // }cout << endl; 39 | // } 40 | 41 | int res = 0; 42 | for(int i = 0; i < 10; ++i) res = min(res, d[i][n/100]); 43 | cout << res << endl; 44 | if(t) cout << endl; 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 1047.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main (){ 8 | int n, t, m, num, ins, val; 9 | int ar[20]; 10 | while(1){ 11 | cin >> n >> t; 12 | if(n == 0 && t == 0) return 0; 13 | for(int i = 0; i < n ; ++i) cin >> ar[i]; 14 | cin >> m; 15 | for(int i = 0; i < m ; ++i){ 16 | cin >> num; 17 | for(int j = 0; j < num; ++j){ 18 | cin >> ins; 19 | } 20 | cin >> val; 21 | } 22 | 23 | // TOOK THE INPUT, STARTING TO COMPUTE 24 | 25 | 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 10487.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define INF 0xfffffff 4 | using namespace std; 5 | int ar[1005]; 6 | 7 | int main (){ 8 | int a, n, m, k =1; 9 | while(cin >> n){ 10 | if (n == 0) return 0; 11 | for(int i = 0; i < n; ++i){ 12 | cin >> ar[i]; 13 | } 14 | cout << "Case " << k++ << ":\n"; 15 | cin >> m; 16 | while(m--){ 17 | cin >> a; 18 | cout << "Closest sum to " << a; 19 | int close = -INF; 20 | for(int i = 0; i < n; ++i){ 21 | for(int j = i+1; j < n; ++j){ 22 | if(abs(a - ar[i] - ar[j]) < abs(a - close)){ 23 | close = ar[i] + ar[j]; 24 | if(close == 0) break; 25 | } 26 | } 27 | } 28 | cout << " is " << close << ".\n"; 29 | } 30 | memset(ar, 0, n); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 10660.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 10660 3 | Related Topic: Math 4 | Author: BedirT 5 | Date: May 25, 2017 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | int cityVal[25], minDist; 13 | 14 | int distanceYY(int target, int a){ 15 | int targetX = target % 5 , targetY = target / 5; 16 | int checkX = a % 5 , checkY = a / 5; 17 | return abs(targetX - checkX) + abs(targetY - checkY); 18 | } 19 | 20 | int distance(int target, int a, int b, int c, int d, int e){ 21 | int mn = distanceYY(target, a); 22 | mn = min(mn , distanceYY(target, b)); 23 | mn = min(mn , distanceYY(target, c)); 24 | mn = min(mn , distanceYY(target, d)); 25 | mn = min(mn , distanceYY(target, e)); 26 | return mn; 27 | } 28 | 29 | void solve(){ 30 | int o1 = 0, o2 = 1, o3 = 2, o4 = 3, o5 = 4; 31 | for(int i = 0; i < 21; ++i){ 32 | for(int j = i+1; j < 22; ++j){ 33 | for(int k = j+1; k < 23; ++k){ 34 | for(int ii = k+1; ii < 24; ++ii){ 35 | for(int jj = ii+1; jj < 25; ++jj){ 36 | int totalDist = 0; 37 | for(int eachCity = 0; eachCity < 25; ++eachCity) 38 | totalDist += distance(eachCity, i, j, k, ii, jj) * cityVal[eachCity]; 39 | if(totalDist < minDist){ 40 | minDist = totalDist; 41 | o1 = i, o2 = j, o3 = k, o4 = ii, o5 = jj; 42 | } 43 | } 44 | } 45 | } 46 | } 47 | } 48 | cout << o1 << " " << o2 << " " << o3 << " " << o4 << " " << o5 << endl; 49 | } 50 | 51 | int main () { 52 | int t, pollNum, x, y; 53 | cin >> t; 54 | while(t--){ 55 | cin >> pollNum; 56 | memset(cityVal, 0, sizeof(cityVal)); 57 | for(int i = 0; i < pollNum; ++i) 58 | cin >> x >> y >> cityVal[5 * x + y]; 59 | minDist = 0xfffffff; 60 | solve(); 61 | } 62 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 10755.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | long long ar[21][21][21], d[21][21][21], sum; 6 | int main (){ 7 | 8 | int t, A, B, C; 9 | cin >> t; 10 | 11 | while(t--){ 12 | cin >> A >> B >> C; 13 | memset(d, 0, sizeof d); 14 | 15 | for(int i = 1; i <= A; ++i) 16 | for(int j = 1; j <= B; ++j) 17 | for(int k = 1; k <= C; ++k){ 18 | cin >> sum; 19 | sum += d[i][j-1][k] + d[i][j][k-1] + d[i-1][j][k]; 20 | if(d[i][j-1][k] && d[i][j][k-1]) sum -= d[i][j-1][k-1]; 21 | if(d[i-1][j][k] && d[i][j][k-1]) sum -= d[i-1][j][k-1]; 22 | if(d[i][j-1][k] && d[i-1][j][k]) sum -= d[i-1][j-1][k]; 23 | if(d[i][j-1][k] && d[i][j][k-1] && d[i-1][j][k]) 24 | sum += d[i-1][j-1][k-1]; 25 | d[i][j][k] = sum; 26 | } 27 | 28 | long long res = -99999999999; 29 | for(int i1 = 1; i1 <= A; ++i1) 30 | for(int i2 = i1; i2 <= A; ++i2) 31 | for(int j1 = 1; j1 <= B; ++j1) 32 | for(int j2 = j1; j2 <= B; ++j2) 33 | for(int k1 = 1; k1 <= C; ++k1) 34 | for(int k2 = k1; k2 <= C; ++k2){ 35 | sum = d[i2][j2][k2]; 36 | if (i1) sum -= d[i1-1][j2][k2]; 37 | if (j1) sum -= d[i2][j1-1][k2]; 38 | if (k1) sum -= d[i2][j2][k1-1]; 39 | if (i1 && j1) sum += d[i1-1][j1-1][k2]; 40 | if (j1 && k1) sum += d[i2][j1-1][k1-1]; 41 | if (i1 && k1) sum += d[i1-1][j2][k1-1]; 42 | if (i1 && j1 && k1) sum -= d[i1-1][j1-1][k1-1]; 43 | res = max(res, sum); 44 | } 45 | 46 | cout << res << endl; 47 | if(t) cout << endl; 48 | } 49 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 10819.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 10819 3 | Related Topic: Knapsack, DP 4 | Author: BedirT 5 | Date: May 28, 2017 6 | */ 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | int knapsack(int C, int n, int * p, int * val){ // C is capacity, n is size 13 | // p is prices, and val is value 14 | int d[15000], res = 0; 15 | bool was[15000]; 16 | 17 | memset(d, 0, sizeof d); 18 | memset(was, 0, sizeof was); 19 | 20 | was[0] = true; // Initial starting point 21 | 22 | for(int i = 1; i <= n; ++i) 23 | for(int j = C+200; j >= 0; --j) 24 | if(was[j]){ 25 | was[j + p[i]] = true; 26 | d[j + p[i]] = max(d[j + p[i]], d[j] + val[i]); 27 | } 28 | 29 | 30 | for(int i = 0 ; i <= C ; ++i) 31 | res = max(res, d[i]); 32 | 33 | if(C > 1800) // Since 1800 - 2000 Doesn't matter, because we will have at least 2001$ 34 | for (int i = 2001; i <= C+200; ++i) // We start the loop from 2001 35 | res = max(res, d[i]); 36 | 37 | return res; 38 | 39 | } 40 | 41 | int main (){ 42 | int m, n, price[200], fav[200]; 43 | 44 | while(cin >> m >> n){ // EOF 45 | 46 | for(int i = 1; i <= n; ++i) 47 | cin >> price[i] >> fav[i]; // Input 48 | 49 | cout << knapsack(m, n, price, fav) << endl; 50 | 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 11085.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 11085 3 | Related Topic: Backtracking 4 | Author: BedirT 5 | Date: May 25, 2017 6 | */ 7 | #include 8 | using namespace std; 9 | 10 | int q[9], past[9], t = 1; 11 | 12 | bool check(int x, int y){ 13 | for(int i = 1; i < y; ++i) 14 | if(past[i] == x || abs(i - y) == abs(past[i] - x)) return false; 15 | return true; 16 | } 17 | 18 | int backtrack(int y){ 19 | 20 | if(y == 9) return 0; 21 | int tot = 10; 22 | for(int i = 1; i <= 8; ++i){ 23 | if(check(i, y)){ 24 | past[y] = i; 25 | tot = min(tot, (i == q[y]) ? backtrack(y + 1) : 1 + backtrack(y + 1)); 26 | } 27 | } 28 | return tot; 29 | } 30 | 31 | int main () { 32 | while(cin >> q[1] >> q[2] >> q[3] >> q[4] >> q[5] >> q[6] >> q[7] >> q[8]){ 33 | printf("Case %d: %d\n",t++, backtrack(1)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 11157.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 11157 3 | Related Topic: Greedy 4 | Author: BedirT 5 | Date: May 27, 2017 6 | */ 7 | #include 8 | #include 9 | using namespace std; 10 | int main (){ 11 | vector vc; 12 | int t, d, n, value, ct = 1; 13 | char type, trash; 14 | cin >> t; 15 | while(t--){ 16 | cin >> n >> d; 17 | vc.push_back(0); vc.push_back(0); 18 | for(int i = 0; i < n; ++i){ 19 | cin >> type >> trash >> value; 20 | vc.push_back(value); 21 | if(type == 'B') 22 | vc.push_back(value); 23 | } 24 | vc.push_back(d); vc.push_back(d); 25 | int mx = 0; 26 | for(int i = 2; i < vc.size(); ++i) 27 | mx = max(mx, vc[i] - vc[i-2]); 28 | vc.clear(); 29 | printf("Case %d: %d\n",ct++, mx); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 11389.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 11389 3 | Related Topic: Sorting 4 | Author: BedirT 5 | Date: May 25, 2017 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | // #define debugE true 12 | 13 | using namespace std; 14 | int main (){ 15 | #ifdef debugE 16 | freopen("output.txt", "w", stdout); 17 | #endif 18 | int n, d, r; 19 | int morning[101], evening[101]; 20 | cin >> n >> d >> r; 21 | while(n != 0 && d != 0 && r != 0){ 22 | memset(morning, 0, sizeof(morning)); 23 | memset(evening, 0, sizeof(evening)); 24 | for(int i = 0; i < n; ++i) cin >> morning[i]; 25 | for(int i = 0; i < n; ++i) cin >> evening[i]; 26 | sort(morning, morning+n); 27 | reverse(morning, morning+n); 28 | sort(evening, evening+n); 29 | int tot = 0; 30 | for(int i = 0; i < n; ++i){ 31 | if(morning[i] + evening[i] > d) 32 | tot += (morning[i] + evening[i] - d); 33 | } 34 | cout << tot*r << endl; 35 | cin >> n >> d >> r; 36 | } 37 | #ifdef debugE 38 | fclose(stdout); 39 | #endif 40 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 11951.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | long long d[101][101]; 7 | int main (){ 8 | 9 | // freopen("output.txt" , "w", stdout); 10 | 11 | int t, n, m, k, ct = 1; 12 | cin >> t; 13 | 14 | while(t--){ 15 | cin >> n >> m >> k; 16 | memset(d, 0, sizeof d); 17 | 18 | for(int i = 0; i < n; ++i){ 19 | for(int j = 0; j < m; ++j){ 20 | cin >> d[i][j]; 21 | if(i) d[i][j] += d[i-1][j]; 22 | if(j) d[i][j] += d[i][j-1]; 23 | if(i && j) d[i][j] -= d[i-1][j-1]; 24 | } 25 | } 26 | 27 | long long res, mx = 0, d1 = 0, d2 = 0; 28 | for(int i1 = 0; i1 < n; ++i1) 29 | for(int j1 = 0; j1 < m; ++j1) 30 | for(int i2 = i1; i2 < n; ++i2) 31 | for(int j2 = j1; j2 < m; ++j2){ 32 | mx = d[i2][j2]; 33 | if(j1) mx -= d[i2][j1-1]; 34 | if(i1) mx -= d[i1-1][j2]; 35 | if(i1 && j1) mx += d[i1-1][j1-1]; 36 | if(mx <= k && (i2-i1+1)*(j2-j1+1) >= d1*d2){ 37 | if((i2-i1+1)*(j2-j1+1) == d1*d2 && res < mx); 38 | else res = mx; 39 | d1 = i2-i1+1, d2 = j2-j1+1; 40 | } 41 | } 42 | printf("Case #%d: %lld %lld\n", ct++, d1*d2, res); 43 | } 44 | 45 | // fclose(stdout); 46 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 12032.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // #define debug 4 | using namespace std; 5 | int ar[1000005]; 6 | int main () { 7 | int t, n; 8 | cin >> t; 9 | #ifdef debug 10 | freopen("output.txt", "w", stdout); 11 | #endif 12 | for(int ct = 1; ct <= t; ++ct){ 13 | cin >> n; int k = 0; n++; // for computing first step too 14 | ar[0] = 0; 15 | for(int i = 1; i < n; ++i) cin >> ar[i]; 16 | for(int i = n-1; i >= 1; --i){ 17 | int gap = ar[i] - ar[i-1]; 18 | if(gap > k) k = gap; 19 | else if(k == gap) k++; 20 | } 21 | printf("Case %d: %d\n", ct, k); 22 | } 23 | #ifdef debug 24 | fclose(stdout); 25 | #endif 26 | } 27 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 12192.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question Name: 12192 - Grapevine 3 | Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3344 4 | Topic: Divide & Conquer 5 | Algo Used: Binary Search (lower_bound) 6 | Author: BedirT 7 | Date: 2016 ... 8 | */ 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | int n, m, q, arr[501][501], low, high, maxx, mIdx; 15 | 16 | int main () { 17 | 18 | cin >> n >> m; 19 | while(n != 0 && m != 0){ 20 | for(int i = 0 ; i < n ; ++i) 21 | for(int j = 0 ; j < m ; ++j) 22 | cin >> arr[i][j]; 23 | 24 | cin >> q; 25 | while(q--){ 26 | cin >> low >> high; 27 | maxx = -1; 28 | for (int i = 0; i < n; ++i){ 29 | mIdx = lower_bound(arr[i] , arr[i]+m, low) - arr[i]; 30 | for (int j = 0; j < n; ++j){ 31 | if(arr[i+j][mIdx+j] > high || i+j >= n || mIdx+j >= m) break; 32 | if(j >= maxx) maxx = j; 33 | } 34 | } 35 | cout << maxx+1 << endl; 36 | } 37 | cout << "-" << endl; 38 | cin >> n >> m; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 12210.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 12210 3 | Related Topic: - 4 | Author: BedirT 5 | Date: May 27, 2017 6 | */ 7 | #include 8 | using namespace std; 9 | int main (){ 10 | int k, a , b, ct= 1; 11 | while(cin >> a >> b && a+b != 0){ 12 | printf("Case %d: ", ct++); 13 | int mn = 99999; 14 | for(int i = 0; i < a; ++i){ 15 | cin >> k; 16 | mn = min(k, mn); 17 | } 18 | for(int j = 0; j < b; ++j){ 19 | cin >> k; 20 | } 21 | if(b - a >= 0) cout << "0" << endl; 22 | else{ 23 | cout << a-b << " " << mn << endl; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 1237.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct { 4 | int l, h; 5 | string name; 6 | }cars[100001]; 7 | 8 | int main (){ 9 | int t, n, a, b, q, ask; string s; 10 | cin >> t; 11 | while(t--){ 12 | cin >> n; 13 | for(int i = 0; i < n; ++i){ 14 | cin >> cars[i].name >> cars[i].l >> cars[i].h; 15 | } 16 | cin >> q; 17 | while(q--){ 18 | cin >> ask; 19 | int point = 0; 20 | for(int i = 0; i < n; ++i){ 21 | if(cars[i].l <= ask && ask <= cars[i].h){ 22 | point++; s = cars[i].name; 23 | if(point > 1) break; 24 | } 25 | } 26 | if(point == 1) cout << s << endl; 27 | else cout << "UNDETERMINED" << endl; 28 | } 29 | if(t) cout << endl; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 12455.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main (){ 7 | int n, t, a, k; 8 | vector vc; 9 | cin >> t; 10 | while(t--){ 11 | cin >> k >> n; 12 | bool ok = false; 13 | for(int i = 0; i < n; ++i){ 14 | cin >> a; 15 | if(vc.size() == 0 || vc.back() != k){ 16 | vc.push_back(a); 17 | int sz = vc.size(); 18 | for(int j = 0; j < sz-1 ; ++j){ 19 | if(a + vc[j] <= k) vc.push_back(a + vc[j]); 20 | if(vc.back() == k){ 21 | ok = true; break; 22 | } 23 | } 24 | } 25 | } 26 | if(!ok && k != 0) cout << "NO\n"; 27 | else cout << "YES\n"; 28 | vc.clear(); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 1262.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 1262 3 | Related Topic: DS / Set-Map 4 | Author: BedirT 5 | Date: May 14, 2017 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | int main () { 13 | int t, k; 14 | string s; ostringstream hold; 15 | set vc[6]; 16 | int mp[6][150]; 17 | cin >> t; 18 | while(t--){ 19 | for(int i = 0; i < 6; ++i) vc[i].clear(); 20 | memset(mp, 0, sizeof(mp)); 21 | cin >> k; 22 | for(int i = 0; i < 12; ++i){ 23 | cin >> s; 24 | if(i < 6){ 25 | for(int j = 0; j < 5; ++j) 26 | mp[j][s[j]] = 1; 27 | }else{ 28 | for(int j = 0; j < 5; ++j) 29 | if(mp[j%5][s[j]] == 1) 30 | vc[j%5].insert(s[j]); 31 | } 32 | } 33 | set::iterator it, jt, kt, lt, mt; 34 | for(it = vc[0].begin() ; it != vc[0].end() ;++it){ 35 | for(jt = vc[1].begin() ; jt != vc[1].end() ;++jt){ 36 | for(kt = vc[2].begin() ; kt != vc[2].end() ;++kt){ 37 | for(lt = vc[3].begin() ; lt != vc[3].end() ;++lt){ 38 | for(mt = vc[4].begin() ; mt != vc[4].end() ;++mt){ 39 | hold.str(string()); 40 | hold << (char)*it << (char)*jt << (char)*kt << (char)*lt << (char)*mt; 41 | if(!(--k)) break; 42 | }if(!k) break; 43 | }if(!k) break; 44 | }if(!k) break; 45 | }if(!k) break; 46 | } 47 | if(k)cout << "NO\n"; 48 | else cout << hold.str() << endl; 49 | } 50 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 183.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | // #define debug 7 | using namespace std; 8 | int row, col; 9 | string bit, s; 10 | char ch; 11 | 12 | bool all(int left, int top, int right, int bottom, char check){ 13 | for(int i = left; i < right; ++i) 14 | for(int j = top; j < bottom; ++j) 15 | if(bit[j*row + i] == check) return false; 16 | return true; 17 | } 18 | 19 | void bToD(int left, int top, int right, int bottom){ 20 | if(left == right || top == bottom) 21 | return; 22 | if(all(left, top, right, bottom, '1')){ 23 | cout << "0"; 24 | return; 25 | } 26 | else if(all(left, top, right, bottom, '0')){ 27 | cout << "1"; 28 | return; 29 | } 30 | else{ 31 | cout << "D"; 32 | 33 | int midcol = (left + right + 1) / 2; 34 | int midrow = (top + bottom + 1) / 2; 35 | bToD(left, top, midcol, midrow); // Left top 36 | bToD(midcol, top, right, midrow); // Right top 37 | bToD(left, midrow, midcol, bottom); // Left bottom 38 | bToD(midcol, midrow, right, bottom); // Right bottom 39 | } 40 | } 41 | 42 | void dToB(int left, int top, int right, int bottom){ 43 | if(left == right || top == bottom) 44 | return; 45 | 46 | int ch = cin.get(); 47 | if(ch == '0' || ch == '1'){ 48 | for(int i = left; i < right; ++i) 49 | for (int j = top; j < bottom; ++j) 50 | bit += ch; 51 | return; 52 | } 53 | else{ 54 | int midcol = (left + right + 1) / 2; 55 | int midrow = (top + bottom + 1) / 2; 56 | dToB(left, top, midcol, midrow); // Left top 57 | dToB(midcol, top, right, midrow); // Right top 58 | dToB(left, midrow, midcol, bottom); // Left bottom 59 | dToB(midcol, midrow, right, bottom); // Right bottom 60 | } 61 | } 62 | 63 | int main (){ 64 | 65 | #ifdef debug 66 | freopen("output.txt", "w", stdout); 67 | #endif 68 | while(cin >> ch && ch != '#'){ 69 | cin >> col >> row; 70 | if(ch == 'B'){ 71 | while(row*col > bit.size()){ 72 | getline(cin , s); 73 | bit += s; 74 | } 75 | printf("D %d %d\n", col, row); 76 | bToD(0, 0, row, col); 77 | cout << endl; 78 | } 79 | else if(ch == 'D'){ 80 | bit = ""; 81 | printf("B %d %d\n", col, row); 82 | dToB(0, 0, row, col); 83 | int bg = 0; 84 | while(bg < bit.size()){ 85 | cout << bit.substr(bg,bg+50) << endl; 86 | bg += 50; 87 | } 88 | } 89 | } 90 | #ifdef debug 91 | fclose(stdout); 92 | #endif 93 | } 94 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 357.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 357 3 | Related Topic: Dynamic, Coin Change 4 | Author: BedirT 5 | Date: May 29, 2017 6 | */ 7 | 8 | #include 9 | using namespace std; 10 | long long d[30001]; 11 | int coins[] = {1, 5, 10, 25, 50}, n = 30000; 12 | 13 | int main () { 14 | 15 | // Coin Change algo... 16 | d[0] = 1; 17 | for(int i = 0; i < 5; ++i) 18 | if(coins[i] <= n) 19 | for(int j = coins[i]; j <= n; ++j) 20 | d[j] += d[j-coins[i]]; 21 | 22 | while(cin >> n){ 23 | if(n < 5) printf("There is only 1 way to produce %d cents change.\n", n); 24 | else printf("There are %lld ways to produce %d cents change.\n", d[n], n); 25 | } 26 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 441.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define INF 0xfffffff 4 | using namespace std; 5 | int ar[50]; 6 | int main (){ 7 | int n; 8 | cin >> n; 9 | while(1){ 10 | if(n == 0) return 0; 11 | memset(ar, 0, n); 12 | for(int i = 0; i < n; ++i) cin >> ar[i]; 13 | for(int i = 0; i < n-5; ++i){ 14 | for(int j = i+1; j < n-4; ++j){ 15 | for(int k = j+1; k < n-3; ++k){ 16 | for(int l = k+1; l < n-2; ++l){ 17 | for(int m = l+1; m < n-1; ++m){ 18 | for(int f = m+1; f < n; ++f){ 19 | printf("%d %d %d %d %d %d\n", ar[i],ar[j],ar[k],ar[l],ar[m],ar[f]); 20 | } 21 | } 22 | } 23 | } 24 | } 25 | } 26 | cin >> n; 27 | if(n != 0) cout << endl; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 481.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Name: 481 - What Goes Up 3 | Link: https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=422 4 | Topic: Dynamic 5 | Algo Used: Longest Increasing Subsequence, Binary Search 6 | */ 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | int BinarySearch(vector vc,int * small ,int high, int key) { 13 | int low = 0, mid; 14 | while (low < high){ 15 | mid = low + ((high - low) / 2); 16 | if (vc[small[mid]] >= key) high = mid; 17 | else low = mid + 1; 18 | } 19 | return low; 20 | } 21 | 22 | int main () { 23 | 24 | int a; 25 | vector vc; 26 | while(cin >> a) vc.push_back(a); 27 | 28 | int small[vc.size()+1], parent[vc.size()+1]; 29 | 30 | int size = 0; small[0] = 0; parent[0] = -1; 31 | 32 | for(int i = 1 ; i < vc.size() ; i++){ 33 | if(vc[i] <= vc[small[size]]){ 34 | int pos = BinarySearch(vc,small,size,vc[i]); 35 | small[pos] = i; 36 | if(pos != 0) parent[i] = small[pos-1]; 37 | } 38 | else{ 39 | small[++size] = i; 40 | parent[i] = small[size-1]; 41 | } 42 | } 43 | 44 | int pos = small[size]; 45 | vector st; 46 | while(size--){ 47 | st.push_back(vc[pos]); 48 | pos = parent[pos]; 49 | } 50 | 51 | cout << st.size() << endl << "-" << endl; 52 | for (int i = st.size()-1; i >= 0; --i) 53 | cout << st[i] << endl; 54 | 55 | } -------------------------------------------------------------------------------- /BedirT/Chapter 3/UVa - 524.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Question: UVa - 00524 3 | Related Topic: Backtrack 4 | Author: BedirT 5 | Date: 05/25/2017 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | // #define debug 12 | using namespace std; 13 | int primes[11] = {2,3,5,7,11,13,17,19,23,29,31}, n, cycle[20]; 14 | bitset<20> used; 15 | 16 | bool isPrime (int num) { 17 | for(int i = 0; i < 11; ++i) 18 | if(num == primes[i]) return true; 19 | return false; 20 | } 21 | 22 | bool beans (int pos, int x) { 23 | if(pos == n-1 && isPrime(x + cycle[0]) && isPrime(x + cycle[pos-1])) return true; 24 | else if(pos != n-1 && isPrime(x + cycle[pos-1])) return true; 25 | else return false; 26 | } 27 | 28 | void backtrack (int x) { 29 | if(x == n){ 30 | for(int i = 0; i < n; ++i){ 31 | cout << cycle[i] << (i == n-1 ? "\n" : " "); 32 | } return; 33 | } 34 | for(int i = 2; i <= n; ++i){ 35 | if(!used[i] && beans(x, i)){ 36 | used[i] = 1; 37 | cycle[x] = i; 38 | backtrack(x+1); 39 | used[i] = 0; 40 | } 41 | } 42 | } 43 | 44 | int main () { 45 | int t = 1; 46 | #ifdef debug 47 | freopen("output.txt", "w", stdout); 48 | #endif 49 | while(cin >> n){ 50 | if(t != 1) cout << endl; 51 | printf("Case %d:\n", t++); 52 | used[0] = cycle[0] = 1; 53 | backtrack(1); 54 | } 55 | #ifdef debug 56 | fclose(stdout); 57 | #endif 58 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 10004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | vector > ways; 7 | 8 | int colored[201]; 9 | int n, m, a, b; 10 | 11 | bool paint(int x, int c, int parent){ 12 | 13 | if(colored[x] == -1){ 14 | colored[x] = (c+1) % 2; 15 | } 16 | if(ways[x].size() > 0){ 17 | int myColor = colored[x]; 18 | for (vector::iterator i = ways[x].begin(); i != ways[x].end(); ++i) { 19 | if(colored[*i] == -1){ 20 | if(parent != *i && !paint(*i, myColor, x)){ 21 | return false; 22 | } 23 | } 24 | else if(colored[*i] == myColor){ 25 | return false; 26 | } 27 | } 28 | } 29 | return true; 30 | } 31 | 32 | int main(){ 33 | 34 | // freopen("out.txt", "w", stdout); 35 | while(cin >> n && n != 0){ 36 | cin >> m; 37 | ways.clear(); ways.resize(n); 38 | for (int i = 0 ; i < m ; ++i) { 39 | cin >> a >> b; 40 | ways[a].push_back(b); 41 | ways[b].push_back(a); 42 | } 43 | 44 | memset(colored, -1, sizeof colored); 45 | 46 | if(paint(0, 1, -1)) cout << "BICOLORABLE.\n"; 47 | else cout << "NOT BICOLORABLE.\n"; 48 | } 49 | // fclose(stdout); 50 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 10171.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define inf 0xfffffff 5 | using namespace std; 6 | int cost, n; 7 | char age, dir, a, b; 8 | vector > city[2][26]; // 2 dimension : 1 for first graph one for the other 9 | int d[2][26]; // 2D again for same reason 10 | char s[2]; // 2 size again for same reason 11 | 12 | void addToGraph(int x, int y){ 13 | city[x][y].push_back(make_pair(cost, b - 65)); 14 | if(dir == 'B') // If the graph is bidirectional 15 | city[x][b - 65].push_back(make_pair(cost, y)); 16 | } 17 | 18 | void fordBellman(int x){ // Ford Bellman 19 | 20 | for(int i = 0; i < 26 ; ++i) d[x][i] = inf; 21 | 22 | d[x][s[x] - 65] = 0; 23 | 24 | vector >::iterator it; 25 | for(int i = 0; i < 25; ++i) 26 | for(int j = 0; j < 26; ++j) 27 | for(it = city[x][j].begin(); it != city[x][j].end() ; ++it){ 28 | int k = (*it).first; // cost 29 | int dest = (*it).second; // destination city 30 | d[x][dest] = min(d[x][dest], d[x][j] + k); 31 | } 32 | } 33 | 34 | int main(){ 35 | 36 | // freopen("out.txt", "w" , stdout); 37 | while(cin >> n && n){ 38 | 39 | for(int i = 0; i < 26; ++i) 40 | city[0][i].clear(), city[1][i].clear(); 41 | 42 | for(int i = 0; i < n; ++i){ 43 | cin >> age >> dir >> a >> b >> cost; 44 | if(age == 'Y') addToGraph(0, a - 65); 45 | if(age == 'M') addToGraph(1, a - 65); 46 | } 47 | 48 | cin >> s[0] >> s[1]; // start, end 49 | 50 | fordBellman(0); 51 | fordBellman(1); 52 | 53 | vector res; 54 | int resNum = inf; 55 | for(int i = 0; i < 26; ++i){ 56 | if(d[0][i] != inf && d[1][i] != inf){ 57 | if(d[0][i] + d[1][i] < resNum){ 58 | res.clear(); 59 | res.push_back((char)(i+65)); 60 | resNum = d[0][i] + d[1][i]; 61 | } 62 | else if(d[0][i] + d[1][i] == resNum) 63 | res.push_back((char)(i+65)); 64 | } 65 | } 66 | 67 | if(res.size()){ 68 | cout << resNum << " "; 69 | for(int i = 0; i < res.size() ; ++i) 70 | cout << res[i] << (i != res.size()-1 ? " " : "\n") ; 71 | } 72 | else cout << "You will never meet.\n"; 73 | } 74 | // fclose(stdout); 75 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 10305.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | bool visited[150]; 7 | vector > way; 8 | vector vc; 9 | 10 | void topological_sort(int x){ 11 | for(int i = 0; i < way[x].size(); ++i) 12 | if(!visited[way[x][i]]) 13 | topological_sort(way[x][i]); 14 | visited[x] = true; 15 | vc.insert(vc.begin(), x+1); 16 | } 17 | 18 | int main (){ 19 | int m, a, b, n; 20 | 21 | // freopen("output.txt", "w", stdout); 22 | while(cin >> n >> m && n != 0){ 23 | 24 | way.clear(); 25 | way.resize(n); 26 | vc.clear(); 27 | memset(visited, false, sizeof visited); 28 | 29 | for(int i = 0; i < m; ++i){ 30 | cin >> a >> b; 31 | way[a-1].push_back(b-1); 32 | } 33 | 34 | for(int i = 0; i < n; ++i){ 35 | if(!visited[i]) 36 | topological_sort(i); 37 | } 38 | 39 | cout << vc[0]; 40 | for (int i = 0; i < vc.size(); i++) 41 | cout << " " << vc[i]; 42 | cout << endl; 43 | } 44 | // fclose(stdout); 45 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 10350.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define inf 0x3f3f3f3f 4 | using namespace std; 5 | 6 | int main () { 7 | 8 | int n, m; 9 | string s; 10 | int dist[100001]; 11 | while(cin >> s){ 12 | cin >> n >> m; 13 | 14 | memset(dist, inf, sizeof dist); 15 | for(int i = 0; i < m; ++i) dist[i] = 0; 16 | 17 | for(int i = 0; i < n - 1; ++i){ 18 | for(int j = 0; j < m; ++j){ 19 | for(int k = 0; k < m; ++k){ 20 | int ct; 21 | cin >> ct; 22 | int x = m * (i + 1) + k; 23 | int y = m * i + j; 24 | dist[x] = min(dist[x], dist[y] + ct + 2); 25 | } 26 | } 27 | } 28 | 29 | int mn = inf; 30 | for (int i = n * m - m; i < n * m ; i++) { 31 | mn = min(mn, dist[i]); 32 | } 33 | 34 | cout << s << endl << mn << endl; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 10369.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #define maxN 1001 7 | #define max(x, y) x > y ? x : y 8 | using namespace std; 9 | 10 | int find(int x, int * parent) { 11 | if (parent[x] == x) return x; 12 | return parent[x] = find(parent[x], parent); 13 | } 14 | 15 | bool detectCycle(int ar[][2], int * parent, int i){ 16 | int x = find(ar[i][0], parent); 17 | int y = find(ar[i][1], parent); 18 | if(x == y) return true; 19 | parent[y] = x; 20 | return false; 21 | } 22 | 23 | int main (){ 24 | 25 | // freopen("out.txt", "w", stdout); 26 | 27 | int ar[maxN][2], parent[maxN], S, P; 28 | int t; cin >> t; 29 | while(t--){ 30 | 31 | cin >> S >> P; 32 | vector > > vc; 33 | pair nodes[P+1]; 34 | vc.clear(); 35 | 36 | for(int i = 0; i < P; ++i){ 37 | int a, b; 38 | cin >> a >> b; 39 | nodes[i] = make_pair(a, b); 40 | } 41 | 42 | for(int i = 0; i < P; ++i){ 43 | for(int j = i+1; j < P; ++j){ 44 | pair a = nodes[i], b = nodes[j]; 45 | double num2 = b.second - a.second; 46 | double num1 = b.first - a.first; 47 | double w = sqrt(num1*num1 + num2*num2); 48 | vc.push_back(make_pair(w ,make_pair(i, j))); 49 | } 50 | } 51 | 52 | for(int i = 0; i < P; ++i) parent[i] = i; 53 | 54 | sort(vc.begin(), vc.end()); 55 | 56 | int edges = 0; 57 | double D = .0; 58 | 59 | for(int i = 0, pos = 0; i < vc.size() && edges != P-S; ++i){ 60 | ar[pos][0] = vc[i].second.first; 61 | ar[pos++][1] = vc[i].second.second; 62 | if(!detectCycle(ar, parent, pos-1)){ 63 | D = max(D, vc[i].first); 64 | edges++; 65 | } 66 | else pos--; 67 | } 68 | 69 | printf("%.2lf\n", D); 70 | 71 | } 72 | // fclose(stdout); 73 | } 74 | -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 10557.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define INF 0xfffffff 6 | #define maxN 101 7 | using namespace std; 8 | bool visited[maxN]; 9 | int t, n, e, m; 10 | int energy[maxN], d[maxN]; 11 | vector ar[maxN]; 12 | 13 | bool dfs(int x){ 14 | visited[x] = true; 15 | for(int i = 0; i < ar[x].size(); ++i){ 16 | int cur = ar[x][i]; 17 | if(cur == n - 1) return true; 18 | if(!visited[cur] && dfs(cur)) return true; 19 | } 20 | return false; 21 | } 22 | 23 | int main () { 24 | 25 | // freopen("out.txt", "w", stdout); 26 | while(cin >> n && n != -1){ 27 | 28 | for(int i = 1; i <= n; ++i){ 29 | scanf("%d %d", &energy[i], &t); 30 | ar[i].clear(); 31 | energy[i] *= -1; 32 | while(t--){ 33 | cin >> e; 34 | ar[i].push_back(e); 35 | } 36 | d[i] = INF; 37 | } 38 | 39 | d[1] = -100; 40 | 41 | int counter = n-1, i , j, cur; 42 | 43 | for(int i = 0; i < n-1; ++i) 44 | for(int j = 1; j <= n; ++j) 45 | for(int k = 0; k < ar[j].size(); ++k){ 46 | int cur = ar[j][k]; 47 | if(d[j] + energy[cur] < 0) // WHY?? 48 | d[cur] = min(d[cur], d[j] + energy[cur]); 49 | } 50 | 51 | if(d[n] <= 0) goto win; 52 | for(int i = 1; i <= n; ++i) 53 | for(int j = 0; j < ar[i].size(); ++j){ 54 | int cur = ar[i][j]; 55 | if(d[i] + energy[cur] < 0 && d[i] + energy[cur] < d[cur]){ 56 | memset(visited, 0, sizeof(visited)); 57 | if(dfs(i)) goto win; 58 | } 59 | } 60 | goto lose; 61 | 62 | lose: cout << "hopeless\n"; continue; 63 | win: cout << "winnable\n"; continue; 64 | } 65 | // fclose(stdout); 66 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 1056.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define inf 0xfffffff 4 | using namespace std; 5 | int ar[51][51], n, m, ct = 1; 6 | bool flag = true; 7 | map mp; 8 | 9 | int Warshall(){ 10 | for(int i = 0; i < n; ++i) 11 | for(int j = 0; j < n; ++j) 12 | for(int k = 0; k < n; ++k) 13 | ar[j][k] = min(ar[j][k], ar[j][i] + ar[i][k]); 14 | 15 | int res = -1; 16 | 17 | for(int i = 0; i < n; ++i) 18 | for(int j = i+1; j < n; ++j){ 19 | res = max(res, ar[i][j]); 20 | } 21 | 22 | return res; 23 | } 24 | 25 | int main () { 26 | 27 | // freopen("in.txt", "r", stdin); 28 | // freopen("out.txt", "w", stdout); 29 | while(cin >> n >> m && n){ 30 | 31 | for(int i = 0 ; i < n; ++i){ 32 | for(int j = 0 ; j < n; ++j) 33 | ar[i][j] = inf; 34 | ar[i][i] = 0; 35 | } 36 | 37 | int cur = 0; 38 | for(int i = 0 ; i < m; ++i){ 39 | string s1, s2; 40 | cin >> s1 >> s2; 41 | if(!mp[s1]) mp[s1] = ++cur; 42 | if(!mp[s2]) mp[s2] = ++cur; 43 | ar[mp[s1]-1][mp[s2]-1] = ar[mp[s2]-1][mp[s1]-1] = 1; 44 | } 45 | 46 | int fin = Warshall(); 47 | 48 | cout << "Network " << ct++ << ": "; 49 | if(fin == inf) cout << "DISCONNECTED\n"; 50 | else cout << fin << endl; 51 | cout << endl; 52 | 53 | mp.clear(); 54 | } 55 | // fclose(stdin); 56 | // fclose(stdout); 57 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 1103.cpp: -------------------------------------------------------------------------------- 1 | /* Getting all right answer from every testcases that I found... 2 | Still not able to get AC */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | int matrix[1001][1001], space, m, n; 10 | bool flag = false; 11 | void dfsRemove(int x, int y){ 12 | if (matrix[x][y] != 0) return; 13 | matrix[x][y] = -1; 14 | if(x != 0) dfsRemove(x-1, y); // left 15 | if(y != 0) dfsRemove(x, y-1); // up 16 | if(y < n) dfsRemove(x, y+1); // down 17 | if(x < m) dfsRemove(x+1, y); // right 18 | if(x == m || y == n) flag = true; 19 | } 20 | 21 | void dfsFill(int x, int y){ 22 | if (matrix[x][y] != 1){ 23 | if(matrix[x][y] == 0){ 24 | cout << "IN\n"; 25 | dfsRemove(x, y); 26 | space++; 27 | } 28 | return; 29 | } 30 | matrix[x][y] = 2; 31 | if(x != 0) dfsFill(x-1, y); // left 32 | if(y != 0) dfsFill(x, y-1); // up 33 | if(x < m) dfsFill(x+1, y); // right 34 | if(y < n) dfsFill(x, y+1); // down 35 | } 36 | 37 | string hexaToBin(string s){ 38 | string news = ""; 39 | for(int i = 0; i < s.size(); ++i){ 40 | switch(s[i]){ 41 | case '0': news += "0000"; break; 42 | case '1': news += "0001"; break; 43 | case '2': news += "0010"; break; 44 | case '3': news += "0011"; break; 45 | case '4': news += "0100"; break; 46 | case '5': news += "0101"; break; 47 | case '6': news += "0110"; break; 48 | case '7': news += "0111"; break; 49 | case '8': news += "1000"; break; 50 | case '9': news += "1001"; break; 51 | case 'a': news += "1010"; break; 52 | case 'b': news += "1011"; break; 53 | case 'c': news += "1100"; break; 54 | case 'd': news += "1101"; break; 55 | case 'e': news += "1110"; break; 56 | case 'f': news += "1111"; break; 57 | } 58 | } 59 | return news; 60 | } 61 | 62 | string getLetter(int k){ 63 | switch(k){ 64 | case 0: return "W"; break; 65 | case 1: return "A"; break; 66 | case 2: return "K"; break; 67 | case 3: return "J"; break; 68 | case 4: return "S"; break; 69 | case 5: return "D"; break; 70 | } 71 | } 72 | 73 | void printMatrix(){ 74 | cout << endl << endl; 75 | for(int i = 0; i < m; ++i){ 76 | for(int j = 0; j < n; ++j) 77 | cout << matrix[i][j]; 78 | cout << endl; 79 | } 80 | } 81 | 82 | int main () { 83 | 84 | // freopen("output.txt", "w", stdout); 85 | 86 | int ct = 1; 87 | while(cin >> m >> n && m != 0){ 88 | for(int i = 0; i < m; ++i){ 89 | string s, str; cin >> str; 90 | s = hexaToBin(str); 91 | for(int j = 0; j < s.size() ; ++j) 92 | matrix[i][j] = s[j] - '0'; 93 | } 94 | n *= 4; 95 | // printMatrix(); 96 | 97 | int i , j; flag = false; 98 | for(i = 0; i < m; ++i){ 99 | for(j = 0; j < n; ++j) 100 | if(matrix[i][j] == 0) break; 101 | if(matrix[i][j] == 0){ 102 | dfsRemove(i, j); 103 | if(flag) break; 104 | i--; 105 | } 106 | } // bg removed 107 | // simply starting from 0,0 will fail 108 | // need to find all bg pieces 109 | 110 | // printMatrix(); 111 | 112 | string res = ""; 113 | for(int i = 0; i < m; ++i) 114 | for(int j = 0; j < n; ++j) 115 | if(matrix[i][j] == 1){ 116 | space = 0; 117 | dfsFill(i, j); 118 | res += getLetter(space); 119 | } 120 | sort(res.begin(), res.end()); 121 | cout << "Case " << ct++ << ": " << res << endl; 122 | memset(matrix, 0, sizeof matrix); 123 | } 124 | 125 | // fclose(stdout); 126 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 1112.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define INF 0xfffffff 5 | using namespace std; 6 | int ar[101][101], d[101]; 7 | 8 | bool djikstra(int n, int s, int end, int time){ 9 | bool visited[101]; 10 | for(int i = 0; i <= n; ++i) d[i] = INF, visited[i] = false; 11 | d[s] = 0; 12 | for(int ct = 0; ct < n ; ++ct){ 13 | for(int i = 1; i <= n; ++i) 14 | if(ar[s][i] != -1 && d[i] > d[s] + ar[s][i]) 15 | d[i] = d[s] + ar[s][i]; 16 | 17 | visited[s] = true; 18 | 19 | int mn = INF; 20 | for(int i = 1; i <= n; ++i) 21 | if(mn > d[i] && !visited[i]) 22 | mn = d[i], s = i; 23 | } 24 | 25 | if(d[end] <= time) return true; 26 | else return false; 27 | } 28 | 29 | int main () { 30 | int t, n, e, time, m; 31 | scanf("%d", &t); 32 | while(t--){ 33 | scanf("\n%d %d %d %d", &n, &e, &time, &m); 34 | 35 | memset(ar, -1, sizeof ar); 36 | 37 | for(int i = 0, a, b, w; i < m; ++i){ 38 | scanf("%d %d %d", &a, &b, &w); 39 | ar[a][b] = w; 40 | } 41 | 42 | int res = 0; 43 | for(int i = 1; i <= n; ++i) 44 | if(djikstra(n, i, e, time)) 45 | res++; 46 | 47 | printf("%d\n", res); 48 | if(t) cout << endl; 49 | } 50 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 11487.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | char grid[11][11]; 5 | bool vis[11][11], done; 6 | int n, ct = 1, ans = 0; 7 | char letter, goal; 8 | 9 | void BFS(int s1, int e1){ 10 | 11 | queue > > q; 12 | 13 | q.push({0, {s1, e1}}); 14 | 15 | int trace[4][2] = {{1,0}, {0,1}, {-1,0}, {0, -1}}; 16 | done = false; 17 | 18 | while(!q.empty()){ 19 | 20 | int x = q.front().second.first; 21 | int y = q.front().second.second; 22 | int len = q.front().first; 23 | q.pop(); 24 | 25 | for(int i = 0; i < 4; ++i){ 26 | 27 | int nX = x + trace[i][0]; 28 | int nY = y + trace[i][1]; 29 | 30 | if (nX >= 0 && nY >= 0 && nX < n && nY < n && !vis[nX][nY]){ 31 | vis[nX][nY] = true; 32 | 33 | if(grid[nX][nY] == '.'); 34 | else if(grid[nX][nY] == letter){ 35 | ans += len + 1; 36 | 37 | if(letter == goal) done = true, break; 38 | 39 | food++; 40 | 41 | while(!q.empty()) q.pop(); 42 | 43 | memset(vis, false, sizeof vis); 44 | vis[nX][nY] = true; 45 | 46 | q.push({0 , {nX,nY}}); 47 | break; 48 | } 49 | else continue; 50 | } 51 | q.push({len + 1, {nX, nY}}); 52 | } 53 | } 54 | } 55 | 56 | void fin(){ 57 | 58 | } 59 | 60 | int main (){ 61 | 62 | while(cin >> n, n){ 63 | int st1, st2; 64 | 65 | letter = 'B', totNum = 0; 66 | goal = 'A'+ n - 1; 67 | distRes = 0x3f3f3f3f; 68 | int letP[27][2]; // Letter Places; Keeps the data of letter coordinates, x-y 69 | 70 | for(int i = 0; i < n; ++i) 71 | for(int j = 0; j < n; ++j){ 72 | cin >> grid[i][j]; 73 | if(isAlpha(grid[i][j])){ 74 | letP[grid[i][j] - '65'][0] = i; 75 | letP[grid[i][j] - '65'][1] = j; 76 | } 77 | } 78 | 79 | BFS(letP[0][0], letP[0][1]); 80 | fin(); 81 | 82 | if(done) printf("Case %d: %d %d\n", ct++, distRes, totNum); 83 | else printf("Case %d: Impossible\n", ct++); 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 11492.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define maxN 5001 6 | #define INF 0xfffffff 7 | using namespace std; 8 | vector ar[maxN][maxN]; 9 | int d[maxN]; 10 | string start, finish, a, b, k; 11 | int n, cur; 12 | map exist; 13 | 14 | int main () { 15 | 16 | // freopen("out.txt", "w", stdout); 17 | 18 | while(cin >> n && n){ 19 | cin >> start >> finish; 20 | exist[start] = 1; 21 | exist[finish] = 2; 22 | int cur = 3, cur2 = 0; 23 | 24 | for(int i = 0; i < n; ++i){ 25 | cin >> a >> b >> k; 26 | if(!exist[a]) exist[a] = cur, cur++; 27 | if(!exist[b]) exist[b] = cur, cur++; 28 | ar[exist[a]][exist[b]].push_back(k); 29 | ar[exist[b]][exist[a]].push_back(k); 30 | // cout << exist[a] << " " << exist[b] << " " << k << endl; 31 | } 32 | 33 | // DJIKSTRA ///////////////// 34 | bool visited[maxN]; 35 | for(int i = 1; i < cur; ++i) d[i] = INF, visited[i] = false; 36 | int s = 2; 37 | d[s] = 0; 38 | char letter[2001] = {}; 39 | letter[s] = 'A'; 40 | for(int ct = 1; ct < cur ; ++ct){ 41 | for(int i = 1; i < cur; ++i){ 42 | // cout << ar[s][i].size() << endl; 43 | if(ar[s][i].size()) for(int j = 0; j < ar[s][i].size(); ++j){ 44 | if(d[i] >= d[s] + ar[s][i][j].size() && letter[s] != ar[s][i][j][0]){ 45 | // cout << ct << " " << i << " " << d[s] + ar[s][i][j].size() << endl; 46 | d[i] = d[s] + ar[s][i][j].size(); 47 | letter[i] = ar[s][i][j][0]; 48 | } 49 | } 50 | } 51 | 52 | visited[s] = true; 53 | 54 | int mn = INF; 55 | for(int i = 1; i < cur; ++i) 56 | if(mn > d[i] && !visited[i]) 57 | mn = d[i], s = i; 58 | } 59 | /////////////////////////////// 60 | 61 | if(d[1] != INF) cout << d[1] << endl; 62 | else cout << "impossivel\n"; 63 | 64 | for(int i = 0; i < cur; ++i) for(int j = 0; j < cur; ++j) ar[i][j].clear(); 65 | exist.clear(); 66 | } 67 | // fclose(stdout); 68 | 69 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 11747.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | struct node{ 7 | int x, y, v; 8 | node (int a, int b, int w){ 9 | x = a, y = b, v = w; 10 | } 11 | }; 12 | 13 | vector vc; 14 | vector res; 15 | int parent[10001]; 16 | 17 | void Union(int x, int y){ 18 | if(x > y) parent[y] = x; 19 | else parent[x] = y; 20 | } 21 | 22 | int find(int x){ 23 | if(parent[x] == x) 24 | return x; 25 | return parent[x] = find(parent[x]); 26 | } 27 | 28 | int cmp(node x, node y){ 29 | return x.v < y.v; 30 | } 31 | 32 | int main (){ 33 | 34 | int n, m; 35 | // freopen("out.txt", "w", stdout); 36 | while(cin >> n >> m && n){ 37 | 38 | for(int i = 0; i <= n; ++i) parent[i] = i; 39 | vc.clear(); res.clear(); 40 | 41 | for(int i = 0 ; i < m; ++i){ 42 | int a, b, w; 43 | cin >> a >> b >> w; 44 | vc.push_back(node(a,b,w)); 45 | } 46 | 47 | sort(vc.begin(), vc.end(), cmp); 48 | 49 | // MST 50 | for(int i = 0; i < m; ++i){ 51 | int x = find(vc[i].x); 52 | int y = find(vc[i].y); 53 | 54 | if(x == y) res.push_back(vc[i].v); 55 | else Union(x, y); 56 | } 57 | // 58 | 59 | if(res.size() == 0) cout << "forest\n"; 60 | else{ 61 | for(int i = 0; i < res.size() ; ++i) 62 | cout << res[i] << (res.size()-1==i ? "\n" : " "); 63 | } 64 | } 65 | // fclose(stdout); 66 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 12442.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int ar[50001], dfsRes[50001]; 8 | bool was[50001]; 9 | 10 | int dfs(int x){ 11 | was[x] = true; 12 | int res = 0; 13 | if(ar[x] && !was[ar[x]]) 14 | res += 1 + dfs(ar[x]); 15 | was[x] = false; 16 | return dfsRes[x] = res; 17 | } 18 | 19 | int main () { 20 | 21 | // freopen("output.txt", "w", stdout); 22 | 23 | int t, ct = 1, n, a , b, ans, val; 24 | cin >> t; 25 | while(t--){ 26 | cin >> n; 27 | 28 | memset(ar, 0, sizeof n+1); 29 | memset(was, false, sizeof n+1); 30 | 31 | int mx = -1; 32 | for(int i = 1; i <= n; ++i){ 33 | cin >> a >> b; 34 | ar[a] = b; 35 | dfsRes[i] = -1; 36 | } 37 | 38 | for(int i = 1; i <= n; ++i){ 39 | if(dfsRes[i] == -1) val = dfs(i); 40 | else val = dfsRes[i]; 41 | if(mx < val){ 42 | mx = val; 43 | ans = i; 44 | } 45 | } 46 | 47 | printf("Case %d: %d\n", ct++, ans); 48 | 49 | } 50 | 51 | // fclose(stdout); 52 | 53 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 247.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main (){ 6 | 7 | string s1, s2; 8 | int n, m, ct = 0; 9 | while(cin >> n >> m && n != 0){ 10 | 11 | if(ct) cout << endl; 12 | 13 | map names; 14 | string holder[26]; 15 | int vc[26][26]; 16 | bool visited[26]; 17 | 18 | int pos = 0; 19 | for(int i = 0; i < m ; ++i){ 20 | cin >> s1 >> s2; 21 | if(!names[s1]) names[s1] = ++pos, holder[pos] = s1; 22 | if(!names[s2]) names[s2] = ++pos, holder[pos] = s2; 23 | vc[names[s1]][names[s2]] = 1; 24 | } 25 | 26 | printf("Calling circles for data set %d:\n", ++ct); 27 | 28 | for(int i = 1; i <= pos; i++) 29 | vc[i][i] = 1; 30 | for(int i = 1; i <= pos; ++i) 31 | for(int j = 1; j <= pos; ++j) 32 | for(int k = 1; k <= pos; ++k) 33 | if(vc[j][i] && vc[i][k]) 34 | vc[j][k] = 1; 35 | 36 | for(int i = 1; i <= pos; ++i){ 37 | if(!visited[i]){ 38 | int tot = 0; 39 | for(int j = 1; j <= pos; ++j){ 40 | if(!visited[j] && vc[i][j] && vc[j][i]){ 41 | visited[j] = visited[i] = true; 42 | cout << (!tot++ ? "" : ", ") << holder[j]; 43 | } 44 | } 45 | cout << endl; 46 | } 47 | } 48 | 49 | } 50 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 924.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #define max(x, y) x > y ? x : y 7 | using namespace std; 8 | 9 | void BFS(vector > ways, int strt){ 10 | queue holder; 11 | int line[10001], pos[10001]; 12 | memset(line, -1, sizeof line); 13 | memset(pos, 0, sizeof pos); 14 | 15 | int maxDaily = 0, THEday, day = 0; 16 | 17 | line[strt] = 0; 18 | 19 | holder.push(strt); 20 | 21 | while (!holder.empty()) { 22 | 23 | int u = holder.front(), curr = 0; 24 | holder.pop(); 25 | 26 | for (int i = 0; i < ways[u].size() ; ++i) { 27 | int v = ways[u][i]; 28 | if (line[v] == -1) { 29 | line[v] = line[u] + 1; 30 | pos[line[u]]++; 31 | holder.push(v); 32 | } 33 | } 34 | 35 | if(pos[line[u]] > maxDaily) 36 | maxDaily = pos[line[u]], THEday = line[u] + 1; 37 | } 38 | 39 | if (ways[strt].size() == 0) cout << 0 << endl; 40 | else cout << maxDaily << " " << THEday << endl; 41 | } 42 | 43 | int main (){ 44 | 45 | // freopen("write.txt", "w", stdout); 46 | 47 | int n, t; 48 | cin >> n; 49 | 50 | vector > vc; 51 | 52 | for(int i = 0, a, b; i < n; ++i){ 53 | cin >> a; 54 | vector temp; temp.clear(); 55 | while(a--){ 56 | cin >> b; 57 | temp.push_back(b); 58 | } 59 | vc.push_back(temp); 60 | } 61 | 62 | cin >> t; 63 | while(t--){ 64 | int source; 65 | cin >> source; 66 | BFS(vc, source); 67 | } 68 | 69 | // fclose(stdout); 70 | 71 | } -------------------------------------------------------------------------------- /BedirT/Chapter 4/UVa - 988.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main (){ 6 | 7 | int n, a, k; bool flag = true; 8 | long long numberOfLife; 9 | vector vc[100001]; 10 | 11 | while(cin >> n && n){ 12 | 13 | if(flag) flag = false; 14 | else cout << endl; 15 | 16 | for(int i = 0; i < n; ++i){ 17 | cin >> k; 18 | while(k--){ 19 | cin >> a; 20 | vc[i].push_back(a); 21 | } 22 | } 23 | 24 | vector val(n, 0); 25 | numberOfLife = 0; 26 | val[0] = 1; 27 | 28 | for (int i = 0; i < n ; ++i){ 29 | if(!vc[i].size()) numberOfLife += val[i]; 30 | for(int v : vc[i]) val[v] += val[i]; 31 | } 32 | 33 | cout << numberOfLife << endl; 34 | 35 | for(int i = 0; i < n; ++i) vc[i].clear(); 36 | } 37 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 10586.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main (){ 8 | // freopen("out.txt", "w", stdout); 9 | int n, k; 10 | int ar[10005]; 11 | while(cin >> n >> k && n != -1){ 12 | 13 | for(int i = n; i >= 0 ; --i) 14 | cin >> ar[i]; 15 | 16 | for(int i = 0; i <= n-k; ++i){ 17 | ar[i+k] -= ar[i]; 18 | ar[i] = 0; 19 | } 20 | 21 | int cur = 0; 22 | while(ar[cur] == 0 && cur <= n) cur++; 23 | 24 | if(n < cur) cout << "0"; 25 | 26 | for(int i = n; i >= cur; --i){ 27 | if(i != n) cout << " "; 28 | cout << ar[i]; 29 | } 30 | cout << endl; 31 | } 32 | // fclose(stdout); 33 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 10751.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main () { 6 | 7 | int t, n; 8 | cin >> t; 9 | while(t--){ 10 | cin >> n; 11 | if(n == 1) printf("0.000\n"); 12 | else printf("%.3f\n", sqrt(2) * (n-2) * (n-2) + 4 * (n-1)); 13 | } 14 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 11231.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main (){ 6 | int n, m, c; 7 | while(cin >> n >> m >> c && n){ 8 | if(c == 0) cout << (n-7)*(m-7)/2 << endl; 9 | else cout << ((n-7)*(m-7) + 1)/2 << endl; 10 | } 11 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 11254.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main (){ 6 | int n; 7 | 8 | while(cin >> n && n != -1){ 9 | int s = -1, r = -1; 10 | for (int i = sqrt(2*n); i >= 1; i--){ 11 | int x = (2 * n + i - i * i) / (2 * i); 12 | if(i * (2 * x + (i-1)) == 2 * n){ 13 | s = x, r = i; 14 | break; 15 | } 16 | } 17 | printf("%d = %d + ... + %d\n", n, s, s+r-1); 18 | } 19 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 11723.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Really easy math q. Divide streets by the letters we allowed to use... 3 | */ 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main (){ 9 | int n, r, ct = 1; 10 | while(cin >> r >> n && r){ 11 | r -= n; // getting rid of the "only digit" part 12 | if(r <= n*26) printf("Case %d: %d\n", ct++, (int)ceil((double)r/n)); 13 | else printf("Case %d: impossible\n", ct++); 14 | } 15 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 11879.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main () { 6 | string s; 7 | while(cin >> s){ 8 | if(s[0] == '0' && s[1] == 0) return 0; 9 | int rem = 0; 10 | for(int i = 0; s[i]; ++i) 11 | rem = ( rem * 10 + s[i] - 48 ) % 17; 12 | cout << (rem ? "0\n" :"1\n"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 12036.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main () { 5 | int T, n, a, ar[101]; 6 | cin >> T; 7 | int ct = 1; 8 | while(T--){ 9 | cin >> n; 10 | bool ok = true; 11 | memset(ar, 0 , sizeof(ar)); 12 | for(int i = 0; i < n ; ++i){ 13 | for(int j = 0; j < n; ++j){ 14 | cin >> a; 15 | ar[a]++; 16 | } 17 | } 18 | for(int i = 0; i < n; ++i){ 19 | if(ar[i] > n){ 20 | ok = false; 21 | break; 22 | } 23 | } 24 | cout << "Case " << ct++ << ": " << (ok ? "yes\n" : "no\n"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 1210.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int n, arr[10021]; 8 | vector vc; 9 | map used; 10 | bool prime[10021]; 11 | 12 | int main() { 13 | int sz = 0; 14 | for (int i = 2; i * i <= 10000; ++i) 15 | if (!prime[i]){ 16 | for (int j = i * i; j <= 10000; j += i) { 17 | prime[j] = true; 18 | } 19 | } 20 | for (int i = 2; i <= 10000; ++i) 21 | if(!prime[i]) 22 | vc.push_back(i); 23 | for (int i = 0; i < vc.size(); ++i) { 24 | int total = vc[i]; 25 | used[total]++; 26 | for (int j = i + 1; j < vc.size(); ++j) { 27 | total += vc[j]; 28 | used[total]++; 29 | } 30 | } 31 | 32 | while (cin >> n && n != 0) 33 | cout << used[n] << endl; 34 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 1225.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int dig[10]; 5 | 6 | void addDigits(int x){ 7 | while(x > 0){ 8 | dig[x%10]++; 9 | x /= 10; 10 | } 11 | } 12 | 13 | int main (){ 14 | int t, n; 15 | cin >> t; 16 | while(t--){ 17 | memset(dig, 0, sizeof dig); 18 | cin >> n; 19 | for(int i = 1; i <= n; ++i) 20 | addDigits(i); 21 | for(int i = 0; i < 10; ++i) 22 | cout << dig[i] << (i == 9 ? "\n" : " "); 23 | } 24 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 377.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | string num1, num2, res; 8 | char op; 9 | string alph = "VUCD"; 10 | map m; 11 | void runA(){ 12 | m['V'] = 0, m['U'] = 1, m['C'] = 2, m['D'] = 3; 13 | res = ""; int carry = 0; 14 | for(int i = num2.size()-1; i >= 0; --i){ 15 | res = alph[(m[num1[i]] + m[num2[i]] + carry) % 4] + res; 16 | if(m[num1[i]] + m[num2[i]] + carry > 3) carry = 1; 17 | else carry = 0; 18 | } 19 | if(carry) res = 'U' + res; 20 | num2 = res; 21 | } 22 | 23 | void runL(){ 24 | num2 += 'V'; 25 | } 26 | 27 | void runR(){ 28 | num2 = num2.substr(0, num2.size()-1); 29 | num2 = 'V' + num2; 30 | } 31 | 32 | void operate(){ 33 | if(op == 'A') runA(); 34 | else if(op == 'L') runL(); 35 | else if(op == 'R') runR(); 36 | num2 = num2.substr(num2.size()-8, num2.size()); 37 | num1 = num1.substr(num1.size()-8, num1.size()); 38 | // cout << num2 << endl; 39 | } 40 | 41 | int main (){ 42 | int t; 43 | cin >> t; 44 | cout << "COWCULATIONS OUTPUT\n"; 45 | while(t--){ 46 | cin >> num1 >> num2; 47 | while(num2.size() < 8) num2 = 'V' + num2; 48 | while(num1.size() < 8) num1 = 'V' + num1; 49 | for(int i = 0; i < 3; ++i){ 50 | cin >> op; 51 | operate(); 52 | } 53 | cin >> res; 54 | // cout << num2 << endl; 55 | cout << ((res == num2) ? "YES\n" : "NO\n"); 56 | } 57 | cout << "END OF OUTPUT\n"; 58 | 59 | } -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 389.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | // #include 5 | using namespace std; 6 | 7 | int conv(char c){ 8 | if(c - '0' < 10){ 9 | return c - '0'; 10 | } 11 | else{ 12 | switch(c){ 13 | case 'A': 14 | return 10; 15 | case 'B': 16 | return 11; 17 | case 'C': 18 | return 12; 19 | case 'D': 20 | return 13; 21 | case 'E': 22 | return 14; 23 | case 'F': 24 | return 15; 25 | } 26 | } 27 | } 28 | 29 | char convback(int c){ 30 | if(c < 10){ 31 | return c + '0'; 32 | } 33 | else{ 34 | switch(c){ 35 | case 10: 36 | return 'A'; 37 | case 11: 38 | return 'B'; 39 | case 12: 40 | return 'C'; 41 | case 13: 42 | return 'D'; 43 | case 14: 44 | return 'E'; 45 | case 15: 46 | return 'F'; 47 | } 48 | } 49 | } 50 | 51 | 52 | int main () { 53 | 54 | string s; 55 | int a, b; 56 | 57 | while(cin >> s >> a >> b){ 58 | long long norm = 0; 59 | for(int i = 0; i < s.size() ; ++i){ 60 | int k = conv(s[i]); 61 | norm += k * pow(a, (s.size() - i - 1)); 62 | } 63 | string res = ""; 64 | cout.width(7); 65 | if(b == 10 || norm == 0) 66 | if (norm > 9999999) cout << "ERROR" << endl; 67 | else cout << norm << endl; 68 | else if(b < 10){ 69 | while(norm > 0){ 70 | char ch = (norm % b + '0'); 71 | res = ch + res; 72 | norm /= b; 73 | } 74 | if (res.size() > 7) cout << "ERROR" << endl; 75 | else cout << res << endl; 76 | } else { 77 | while (norm > 0) { 78 | res = convback(norm % b) + res; 79 | norm /= b; 80 | } 81 | if (res.size() > 7) cout << "ERROR" << endl; 82 | else cout << res << endl; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /BedirT/Chapter 5/UVa - 443.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main (){ 6 | int n; 7 | 8 | set s; 9 | s.insert(1); 10 | 11 | for(int i = 0; i < 5842; ++i){ 12 | long mn = *next(s.begin(), i); 13 | s.insert(mn*2); 14 | s.insert(mn*3); 15 | s.insert(mn*5); 16 | s.insert(mn*7); 17 | } 18 | while(cin >> n && n){ 19 | long res = *next(s.begin(), n-1); 20 | 21 | printf("The %d", n); 22 | if(n % 10 == 1 && n % 100 != 11) printf("st"); 23 | else if(n % 10 == 2 && n % 100 != 12) printf("nd"); 24 | else if(n % 10 == 3 && n % 100 != 13) printf("rd"); 25 | else printf("th"); 26 | printf(" humble number is %ld.\n", res); 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /BedirT/README.md: -------------------------------------------------------------------------------- 1 | ## [BedirT](https://github.com/BedirT) 2 | --- 3 | Solutions for the homeworks. __(*** - Looks correct but not passed)__ 4 | 5 | ### Chapter 2 - _Data Structures and Libraries_ 6 | 7 | - [x] [UVa 10038 - Jolly Jumpers](Chapter%202/UVa%20-%2010038.cpp) 8 | - [x] [UVa 11581 - Grid Successors](Chapter%202/UVa%20-%2011581.cpp) 9 | - [x] [UVa 10258 - Contest Scoreboard](Chapter%202/UVa%20-%2010258.cpp) 10 | - [x] [UVa 11933 - Splitting Numbers](Chapter%202/UVa%20-%2011933.cpp) 11 | - [x] [UVa 11988 - Broken Keyboard](Chapter%202/UVa%20-%2011988.cpp) 12 | - [ ] UVa 01062 - Containers 13 | - [x] [UVa 11286 - Conformity](Chapter%202/UVa%20-%2011286.cpp) 14 | - [x] [UVa 00978 - Lemmings Battle](Chapter%202/UVa%20-%20978.cpp) 15 | - [x] [UVa 10954 - Add All](Chapter%202/UVa%20-%2010954.cpp) 16 | - [x] [UVa 00599 - The Forrest for the Trees](Chapter%202/UVa%20-%20599.cpp) 17 | - [x] [UVa 00793 - Network Connections](Chapter%202/UVa%20-%20793.cpp) 18 | - [x] [UVa 12532 - Interval Product](Chapter%202/UVa%20-%2012532.cpp) 19 | 20 | ### Chapter 3 - _Problem Solving Paradigms_ 21 | 22 | - [x] [UVa 01237 - Expert Enough](Chapter%203/UVa%20-%201237.cpp) 23 | - [x] [UVa 10487 - Closest Sums](Chapter%203/UVa%20-%2010487.cpp) 24 | - [x] [UVa 00441 - Lotto](Chapter%203/UVa%20-%20441.cpp) 25 | - [x] [UVa 10660 - Citizen attention](Chapter%203/UVa%20-%2010660.cpp)*** 26 | - [ ] UVa 01047 - Zones 27 | - [x] [UVa 12455 - Bars](Chapter%203/UVa%20-%2012455.cpp) 28 | - [x] [UVa 11085 - Back to the 8-Queens](Chapter%203/UVa%20-%2011085.cpp) 29 | - [x] [UVa 00524 - Prime Ring Problem](Chapter%203/UVa%20-%20524.cpp) 30 | - [x] [UVa 01262 - Password](Chapter%203/UVa%20-%201262.cpp) 31 | - [x] [UVa 12192 - Grapevine](Chapter%203/UVa%20-%2012192.cpp) 32 | - [x] [UVa 12032 - The Monkey](Chapter%203/UVa%20-%2012032.cpp) 33 | - [x] [UVa 00183 - Bit Maps](Chapter%203/UVa%20-%20183.cpp)*** 34 | - [x] [UVa 11389 - The Bus Driver Problem](Chapter%203/UVa%20-%2011389.cpp) 35 | - [x] [UVa 12210 - A Match Making Problem](Chapter%203/UVa%20-%2012210.cpp) 36 | - [x] [UVa 11157 - Dynamic Frog](Chapter%203/UVa%20-%2011157.cpp) 37 | - [x] [UVa 10755 - Garbage Heap](Chapter%203/UVa%20-%2010755.cpp) 38 | - [x] [UVa 11951 - Area](Chapter%203/UVa%20-%2011951.cpp) 39 | - [x] [UVa 00481 - What Goes Up?](Chapter%203/UVa%20-%20481.cpp) 40 | - [x] [UVa 10819 - Trouble of 13-Dots](Chapter%203/UVa%20-%2010819.cpp) 41 | - [ ] UVa 10496 - Collecting Beepers 42 | - [x] [UVa 00357 - Let Me Count The Ways](Chapter%203/UVa%20-%20357.cpp) 43 | - [x] [UVa 10337 - Flight Planner](Chapter%203/UVa%20-%2010337.cpp)*** 44 | 45 | ### Chapter 4 - _Graph_ 46 | 47 | - [x] [UVa 12442 - Forwarding Emails](Chapter%204/UVa%20-%2012442.cpp) 48 | - [x] [UVa 01103 - Ancient Messages](Chapter%204/UVa%20-%201103.cpp)*** 49 | - [x] [UVa 10305 - Ordering Tasks](Chapter%204/UVa%20-%2010305.cpp) 50 | - [x] [UVa 10004 - Bicoloring](Chapter%204/UVa%20-%2010004.cpp) 51 | - [ ] UVa 10765 - Doves and Bombs 52 | - [x] [UVa 00247 - Calling Circles](Chapter%204/UVa%20-%20247.cpp) 53 | - [x] [UVa 11747 - Heavy Cycle Edges](Chapter%204/UVa%20-%2011747.cpp) 54 | - [x] [UVa 10369 - Arctic Networks](Chapter%204/UVa%20-%2010369.cpp) 55 | - [x] [UVa 00924 - Spreading the News](Chapter%204/UVa%20-%20924.cpp) 56 | - [ ] UVa 00314 - Robot 57 | - [x] [UVa 01112 - Mice and Maze](Chapter%204/UVa%20-%201112.cpp) 58 | - [x] [UVa 11492 - Babel](Chapter%204/UVa%20-%2011492.cpp) 59 | - [x] [UVa 10557 - XYZZY](Chapter%204/UVa%20-%2010557.cpp)*** 60 | - [x] [UVa 10171 - Meeting Prof. Miguel](Chapter%204/UVa%20-%2010171.cpp) 61 | - [x] [UVa 01056 - Degrees of Separation](Chapter%204/UVa%20-%201056.cpp) 62 | - [ ] UVa 11167 - Monkeys in the Emei 63 | - [ ] UVa 11380 - Down Went The Titanic 64 | - [x] [UVa 10350 - Liftless Eme](Chapter%204/UVa%20-%2010350.cpp) 65 | - [x] [UVa 00988 - Many paths, one](Chapter%204/UVa%20-%20988.cpp) 66 | - [ ] [UVa 11487 - Gathering Food](Chapter%204/UVa%20-%2011487.cpp) - __Not finished__ 67 | - [ ] UVa 10805 - Cockroach Escape 68 | - [ ] UVa 10596 - Morning Walk 69 | - [ ] UVa 11159 - Factors and Multiples 70 | 71 | ### Chapter 5 - _Mathematics_ 72 | 73 | - [x] [UVa 11723 - Numbering Road](Chapter%205/UVa%20-%2011723.cpp) 74 | - [x] [UVa 01225 - Digit Counting ](Chapter%205/UVa%20-%201225.cpp) 75 | - [x] [UVa 11254 - Consecutive Integers](Chapter%205/UVa%20-%2011254.cpp) 76 | - [x] [UVa 10751 - Chessboard](Chapter%205/UVa%20-%2010751.cpp) 77 | - [x] [UVa 11231 - Black and White Painting](Chapter%205/UVa%20-%2011231.cpp) 78 | - [ ] UVa 10233 - Dermuba Triangle 79 | - [x] [UVa 00443 - Humble Numbers](Chapter%205/UVa%20-%20443.cpp) 80 | - [x] [UVa 00701 - Archaelogist’s Dilemma](Chapter%205/UVa%20-%20701.cpp) 81 | - [x] [UVa 10586 - Polynomial Remains](Chapter%205/UVa%20-%2010586.cpp) 82 | - [x] [UVa 00377 - Cowculations](Chapter%205/UVa%20-%20377.cpp) 83 | - [x] [UVa 12036 - Stable Grid](Chapter%205/UVa%20-%2012036.cpp) 84 | - [x] [UVa 11879 - Multiple of 17](Chapter%205/UVa%20-%2011879.cpp) 85 | - [x] [UVa 00389 - Basically Speaking](Chapter%205/UVa%20-%20389.cpp) 86 | - [x] [UVa 01210 - Sum of Consecutive](Chapter%205/UVa%20-%201210.cpp) 87 | - [ ] UVa 01230 - MODEX 88 | - [ ] UVa 00763 - Fibinary Numbers 89 | - [ ] UVa 10541 - Stripe 90 | - [ ] UVa 10312 - Expression Bracketing 91 | - [ ] UVa 11597 - Spanning Subtree 92 | - [ ] UVa 11538 - Chess Queen 93 | - [ ] UVa 00543 - Goldbach’s Conjecture 94 | - [ ] UVa 11827 - Maximum GCD 95 | - [ ] UVa 00324 - Factorial Frequencies 96 | - [ ] UVa 11466 - Largest Prime Divisor 97 | - [ ] UVa 11889 - Benefit 98 | - [ ] UVa 11728 - Alternate Task 99 | - [ ] UVa 10990 - Another New Function 100 | - [ ] UVa 10212 - The Last Non-zero Digit 101 | - [ ] UVa 10104 - Euclid Problem 102 | - [ ] UVa 10110 - Light, more light 103 | - [ ] UVa 11176 - Winning Streak 104 | - [ ] UVa 11053 - Flavius Josephus 105 | - [ ] UVa 10111 - Find the Winning 106 | 107 | ### Chapter 6 - _String Processing_ 108 | 109 | - [ ] UVa 10851 - 2D Hieroglyphs ... 110 | - [ ] UVa 11385 - Da Vinci Code 111 | - [ ] UVa 00902 - Password Search 112 | - [ ] UVa 11878 - Homework Checker 113 | - [ ] UVa 00622 - Grammar Evaluation 114 | - [ ] UVa 00325 - Identifying Legal ... 115 | - [ ] UVa 00488 - Triangle Wave 116 | - [ ] UVa 00644 - Immediate Decodability 117 | - [ ] UVa 00941 - Permutations 118 | - [ ] UVa 10298 - Power Strings 119 | - [ ] UVa 00422 - Word Search Wonder 120 | - [ ] UVa 00526 - Edit Distance 121 | - [ ] UVa 11151 - Longest Palindrome 122 | - [ ] UVa 00760 - DNA Sequencing 123 | 124 | 125 | ### Chapter 7 - _(Computational) Geometry_ 126 | 127 | - [ ] UVa 00920 - Sunny Mountains 128 | - [ ] UVa 10005 - Packing polygons 129 | - [ ] UVa 10577 - Bounding box 130 | - [ ] UVa 00460 - Overlapping Rectangles 131 | - [ ] UVa 00737 - Gleaming the Cubes 132 | - [ ] UVa 10652 - Board Wrapping 133 | 134 | ### Chapter 8 - _More Advanced Topics_ 135 | 136 | - [ ] UVa 10309 - Turn the Lights Off 137 | - [ ] UVa 01098 - Robots on Ice 138 | - [ ] UVa 01211 - Atomic Car Race 139 | - [ ] UVa 01231 - ACORN 140 | - [ ] UVa 01099 - Sharing Chocolate 141 | - [ ] UVa 10983 - Buy one, get ... 142 | - [ ] UVa 10891 - Game of Sum 143 | - [ ] UVa 11324 - The Largest Clique 144 | - [ ] UVa 11635 - Hotel Booking 145 | - [ ] UVa 10539 - Almost Prime Numbers 146 | - [ ] UVa 10012 - How Big Is It? 147 | - [ ] UVa 11525 - Permutation 148 | - [ ] UVa 11610 - Reverse Prime 149 | 150 | ### Chapter 9 - _Rare Topics_ 151 | 152 | - [ ] UVa 10078 - Art Gallery 153 | - [ ] UVa 01096 - The Islands 154 | - [ ] UVa 00673 - Parentheses Balance 155 | - [ ] UVa 10296 - Jogging Trails 156 | - [ ] UVa 10245 - The Closest Pair Problem 157 | - [ ] UVa 10213 - How Many Pieces ... 158 | - [ ] UVa 00563 - Crimewave 159 | - [ ] UVa 00612 - DNA Sorting 160 | - [ ] UVa 00439 - Knight Moves 161 | - [ ] UVa 00348 - Optimal Array Mult 162 | - [ ] UVa 10746 - Crime Wave - The Sequel 163 | - [ ] UVa 01184 - Air Raid 164 | - [ ] UVa 00120 - Stacks Of Flapjacks 165 | - [ ] UVa 00344 - Roman Digititis 166 | - [ ] UVa 11462 - Age Sort 167 | - [ ] UVa 10017 - The Never Ending 168 | 169 | -------------------------------------------------------------------------------- /Contests/README.md: -------------------------------------------------------------------------------- 1 | #ACM-ICPC practice contests 2 | --- 3 | Here, we will be keeping track of our solutions of the practice contests during the preperation for ACM-ICPC 2017. 4 | 5 | ## Contests 6 | 7 | - [September 16 - Kattis open contest](Contests%20/September_16%20/) -------------------------------------------------------------------------------- /Contests/September_16/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int N, L, W, k, size, opt; 8 | double total; 9 | multiset v; 10 | multiset::iterator it, it2; 11 | 12 | int main() { 13 | cin >> N; 14 | cin >> L >> W; 15 | for (int i = 1; i <= N; ++i) { 16 | cin >> k; 17 | v.insert(k); 18 | } 19 | total = 0; 20 | size = L / ((N - 4) / 2 + 1); 21 | //cout << size << endl; 22 | for(int i = 0; i < 2; ++i){ 23 | it = v.lower_bound(0); 24 | if (i == 0) total += *it; else total += sqrt((*it) * (*it) + W * W); 25 | v.erase(it); 26 | } 27 | for(int i = 0; i < 2; ++i){ 28 | it = v.upper_bound(L); 29 | it--; 30 | //cout << *it << ' ' << sqrt((L - *it) * (L - *it) + W * W) << endl; 31 | if (i == 0) total += L - *it; else total += sqrt((L - *it) * (L - *it) + W * W); 32 | v.erase(it); 33 | } 34 | // cout << total << endl; 35 | N -= 4; 36 | int tmp = size; 37 | for (int i = 1; i <= N/2; ++i) { 38 | 39 | /// Left Side 40 | it = v.lower_bound(size); 41 | it2 = v.upper_bound(size); 42 | it2--; 43 | //cout << *it << " " << *it2 << endl; 44 | if(abs(size - *it2) > abs(size - *it)){ 45 | opt = abs(size - *it); 46 | v.erase(it); 47 | } else{ 48 | opt = abs(size - *it2); 49 | v.erase(it2); 50 | } 51 | total += opt; 52 | //// 53 | 54 | /// Right Side 55 | it = v.lower_bound(size); 56 | it2 = v.upper_bound(size); 57 | it2--; 58 | //cout << *it << " " << *it2 << endl; 59 | if(abs(size - *it2) > abs(size - *it)){ 60 | opt = abs(size - *it); 61 | v.erase(it); 62 | } else{ 63 | opt = abs(size - *it2); 64 | v.erase(it2); 65 | } 66 | total += sqrt(opt * opt + W * W); 67 | //// 68 | 69 | size += tmp; 70 | } 71 | printf("%.8lf", total); 72 | 73 | } -------------------------------------------------------------------------------- /Contests/September_16/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | int main (){ 7 | long long x , y; 8 | cin >> x >> y; 9 | long long res = 1, result = 1; 10 | while(y--){ 11 | res *= 2; 12 | result += res; 13 | } 14 | // cout << result << endl; 15 | if (result >= x) cout << "yes\n"; 16 | else cout << "no\n"; 17 | } 18 | -------------------------------------------------------------------------------- /Contests/September_16/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | const int prime = 31; 11 | 12 | int dp[1001][1001]; 13 | int mx = 0; 14 | int hashof(string str) { 15 | int hash = 0; 16 | for (int i = 0; i < str.size(); ++i) { 17 | hash = (hash + (str[i]-31))*prime; 18 | } 19 | return hash; 20 | } 21 | int main (){ 22 | int t; 23 | string s, name, str; 24 | vector mp[1001]; 25 | vector names; 26 | vector answer; 27 | cin >> t; 28 | while(t--){ 29 | cin >> name; cin.ignore(100,'\n'); 30 | names.push_back(name); 31 | while(getline(cin , s)){ 32 | if(s == "")continue; 33 | str = ""; 34 | if (s == "***END***") break; 35 | int k = 0, r = s.size()-1; 36 | while (s[k++] == ' '); 37 | while (s[r--] == ' '); 38 | for (int i = k; i <= r; ++i){ 39 | if(str[str.size()-1] == ' ' && s[i] == ' ') continue; 40 | str+=s[i]; 41 | } 42 | mp[names.size()-1].push_back(hashof(str)); 43 | } 44 | } 45 | std::vector vc; 46 | 47 | while(getline(cin , s)){ 48 | if(s == "")continue; 49 | str = ""; 50 | if (s == "***END***") break; 51 | int k = 0, r = s.size()-1; 52 | while (s[k++] == ' '); 53 | while (s[r--] == ' '); 54 | for (int i = k; i <= r; ++i){ 55 | if(str[str.size()-1] == ' ' && s[i] == ' ') continue; 56 | str+=s[i]; 57 | } 58 | vc.push_back(hashof(str)); 59 | } 60 | for (int i = 0; i < names.size(); ++i) { 61 | int _mx = 0; 62 | for (int j = 0; j < mp[i].size(); ++j) { 63 | for (int k = 0; k < vc.size() ; ++k){ 64 | int inc = 0; 65 | while (j+inc < mp[i].size() && k+inc < vc.size() && mp[i][j+inc] == vc[k+inc]) 66 | inc++; 67 | _mx = max(inc, _mx); 68 | } 69 | } 70 | if (_mx > mx) { 71 | mx = _mx; 72 | answer.clear(); 73 | answer.push_back(names[i]); 74 | } 75 | else 76 | if (_mx == mx) { 77 | answer.push_back(names[i]); 78 | } 79 | 80 | 81 | } 82 | cout << mx; 83 | if (mx > 0) { 84 | for (int i = 0; i < answer.size(); ++i) 85 | cout << " " << answer[i]; 86 | } 87 | cout << endl; 88 | } 89 | -------------------------------------------------------------------------------- /Contests/September_16/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | int main (){ 7 | int b, t; 8 | double f; 9 | vector > vc; 10 | cin >> b >> t >> f; 11 | while(b--){ 12 | double p; 13 | double s; 14 | cin >> p >> s; 15 | vc.push_back(make_pair(s,p)); 16 | } 17 | sort(vc.begin(), vc.end()); 18 | double solution = 0; 19 | int j = 0; 20 | for(int i = 0; ; ++i){ 21 | if(i >= vc.size()){ 22 | i = 0; 23 | j++; 24 | } 25 | double res = 0; 26 | res = vc[i].second * vc[i].first * (pow(f, j)); 27 | solution += res; 28 | vc[i].first -= res; 29 | t--; 30 | if(t <= 0){ 31 | cout << solution << endl; 32 | exit(0); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Quyen/Chap 2/UVa 10038 - Jolly Jumber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | //#define fin cin 9 | //#define fout cout 10 | using namespace std; 11 | int main (void) 12 | { 13 | /* ifstream fin; 14 | 15 | ofstream fout; 16 | 17 | fin.open("input.txt"); 18 | 19 | fout.open("output.txt");*/ 20 | int array [3000]; 21 | int n; 22 | while (cin>>n) 23 | { 24 | for (int i = 0; i < n;i++) 25 | cin>>array[i]; 26 | for (int j = 0; j < n - 1; j++) 27 | { 28 | array[j] = abs(array[j] - array [j+1]); 29 | } 30 | array[n - 1] = 0; 31 | // for (int x = 0; x < n;x++) 32 | // cout< 2 | #include 3 | 4 | using namespace std; 5 | int size[26]; 6 | int Alphabet[26]; 7 | 8 | void initialize() 9 | { 10 | 11 | for(int i = 0;i<26;i++) 12 | { 13 | 14 | Alphabet[i] = i ; 15 | size[ i ] = 1; 16 | } 17 | } 18 | 19 | int root(int i) 20 | { 21 | while(Alphabet[ i ] != i) //chase parent of current element until it reaches root. 22 | { 23 | 24 | Alphabet[i] = Alphabet[Alphabet[ i ] ] ; 25 | i = Alphabet[ i ]; 26 | } 27 | return i; 28 | } 29 | 30 | void Union(int A, int B) 31 | { 32 | int root_A = root(A); 33 | int root_B = root(B); 34 | if (root(A) == root(B)) 35 | { 36 | return; 37 | } 38 | if(size[root_A] < size[root_B]) 39 | { 40 | Alphabet[ root_A ] = Alphabet[root_B]; 41 | size[root_B] += size[root_A]; 42 | size[root_A] = 0; 43 | } 44 | else 45 | { 46 | Alphabet[ root_B ] = Alphabet[root_A]; 47 | size[root_A] += size[root_B]; 48 | size[root_B] = 0; 49 | } 50 | 51 | } 52 | 53 | 54 | 55 | 56 | int main (void) 57 | { 58 | int n; 59 | cin>>n; 60 | while (n--) 61 | { 62 | initialize(); 63 | string s; 64 | string a; 65 | while(1) 66 | { 67 | // cout<<"hi"; 68 | cin>>s; 69 | if (s[0] == '*') 70 | break; 71 | Union(s[1]-65, s[3] - 65); 72 | } 73 | cin>>a; 74 | int tree = 0; 75 | int acorn = 0; 76 | // for (int x = 0; x <26;x++) 77 | // cout< 2) 85 | tree++; 86 | else if (size[j] == 2) 87 | acorn++; 88 | } 89 | // for (int x = 0; x <26;x++) 90 | // cout< 2 | #include 3 | #include 4 | #include 5 | #define fin cin 6 | #define fout cout 7 | using namespace std; 8 | int main (void) 9 | { 10 | /* ifstream fin; 11 | 12 | ofstream fout; 13 | 14 | fin.open("input.txt"); 15 | 16 | fout.open("output.txt");*/ 17 | int n; 18 | cin>>n; 19 | while (n--) 20 | { 21 | int b;//number of battle field 22 | cin>>b; 23 | int sg;//number of green armies 24 | cin>>sg; 25 | int sb;//number of blue armies 26 | cin>>sb; 27 | vector Green; 28 | vector Blue; 29 | int a = 0; 30 | for (int i = 0; i < sg; i++) 31 | { 32 | cin>>a; 33 | Green.push_back(a); 34 | } 35 | for (int j = 0; j >a; 38 | Blue.push_back(a); 39 | } 40 | 41 | sort (Green.begin(),Green.end(),greater());// Strongest warrior go first 42 | sort (Blue.begin(),Blue.end(), greater());// Strongest warrior go first 43 | 44 | while(1) 45 | { 46 | 47 | for (int x= 0 ; x < b;x++) 48 | { 49 | // cout< Blue[x]) 52 | { 53 | Green[x] = Green[x] - Blue[x]; 54 | Blue[x] = 0; 55 | } 56 | else if (Green[x] < Blue[x]) 57 | { 58 | Blue[x] = Blue[x] - Green[x]; 59 | Green[x] = 0; 60 | } 61 | else 62 | { 63 | Green[x] = 0; 64 | Blue[x] = 0; 65 | } 66 | // cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | using namespace std; 10 | 11 | int main (void) 12 | { 13 | int t; 14 | cin >> t; 15 | string s; 16 | getline(cin, s); 17 | getline(cin, s); 18 | while (t--) 19 | { 20 | int contestant,problem,time; 21 | string st; 22 | char stat; 23 | int array [101][10][1]; 24 | memset (array,0,sizeof(array)); 25 | 26 | while(cin>>contestant) 27 | { 28 | if (contestant == 0) 29 | break; 30 | cin >> problem; 31 | cin >> time; 32 | cin >> stat; 33 | if (stat == 'C')//Correct answer 34 | array[contestant-1][problem-1][0] += time;//Time for only 1 problem 35 | else if (stat == 'I')//Incorrect answer 36 | array[contestant-1][problem-1][0] += 20;//Time for only 1 problem 37 | 38 | 39 | // cout << contestant<< " " << problem << " " << array[contestant - 1][problem-1][0]; 40 | 41 | } 42 | 43 | 44 | int totalTime[101]; 45 | int problemCount[101]; 46 | for (int i = 0; i < 101; i++)//for each contestant 47 | { 48 | totalTime[i] = 0; 49 | problemCount[i] = 0; 50 | for (int j = 0; j < 10; j++)//for each problem 51 | { 52 | totalTime[i] += array[i][j][0]; 53 | if(array[i][j][0] != 0) 54 | problemCount[i]++;//counting the number of problem 55 | }//end for loop 56 | if(totalTime[i] != 0) 57 | { 58 | int j = i + 1; 59 | cout << j << " "; 60 | cout << problemCount[i]<< " "; 61 | cout << totalTime[i] < 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | 12 | int n; 13 | 14 | while (cin >> n) 15 | { 16 | if (n == 0) 17 | break; 18 | vector numbers; 19 | int numb; 20 | int cost = 0; 21 | for (int i = 0; i < n;i++) 22 | { 23 | cin >> numb; 24 | numbers.push_back(numb); 25 | } 26 | 27 | while (n != 1) 28 | { 29 | sort(numbers.begin(), numbers.end()); 30 | cost += numbers[1] + numbers[0]; 31 | numbers.push_back(numbers[0] + numbers[1]); 32 | numbers.erase(numbers.begin(),numbers.begin() + 2); 33 | n--; 34 | } 35 | 36 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main (void) 9 | { 10 | int n; 11 | while(1){ 12 | cin >> n; 13 | if(n == 0) 14 | break; 15 | 16 | map, int> students; 17 | for (int i = 0; i < n;i++) 18 | { 19 | vector courses(5); 20 | for (int j = 0; j < 5;j++) 21 | cin >> courses[j]; 22 | sort(courses.begin(), courses.end()); 23 | students[courses]++; //If the there are same combination the second value update 24 | } 25 | int max = 1; 26 | int count = 0; 27 | for (map,int> :: iterator x = students.begin() ;x!= students.end();x++ ) 28 | { 29 | 30 | if (x->second == max) 31 | 32 | count+= x->second; 33 | if (x->second > max) 34 | { 35 | max = x->second; 36 | count = max; 37 | } 38 | } 39 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | int main (void) 6 | { 7 | int n; 8 | 9 | while(1) 10 | { 11 | cin>>n; 12 | if (n == 0) 13 | break; 14 | int a = 0; 15 | int b = 0; 16 | string bit = bitset<32>(n).to_string(); 17 | bool toA = true; 18 | bool toB = false; 19 | //cout< 2 | 3 | int main (void) 4 | { 5 | char text[100000]; 6 | scanf ("%s", text); 7 | for (int i = 0; i < 100000;i++) 8 | { 9 | if(text[i] == ']' || text[i] == '[') 10 | { 11 | for (int x = i ; x < 100000 - 1 ; x++ ) 12 | { 13 | text[x] = text[x+1]; 14 | i = 0; 15 | } 16 | 17 | } 18 | } 19 | printf ("%s", text); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Quyen/Chap 2/Uva 12532 - Interval Product.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main (void) 6 | { 7 | int n; 8 | int k; 9 | while(cin>>n>>k) 10 | { 11 | vector sequence; 12 | string result; 13 | for (int i = 0;i < n;i++) 14 | { 15 | int a; 16 | cin>>a; 17 | sequence.push_back(a); 18 | } 19 | char command; 20 | 21 | while(k--) 22 | { 23 | cin>>command; 24 | if (command == 'C') 25 | { 26 | int I; 27 | int V; 28 | cin>>I; 29 | cin>>V; 30 | sequence[I - 1] = V; 31 | // for (int i = 0; i>I; 41 | cin>>J; 42 | for (int i = I-1; i < J;i++) 43 | product *= sequence[i]; 44 | if(product == 0) 45 | result.push_back('0'); 46 | else if (product > 0) 47 | result.push_back('+'); 48 | else 49 | result.push_back('-'); 50 | product = 1; 51 | } 52 | // cout< 2 | #include 3 | #include 4 | #define fin cin 5 | #define fout cout 6 | using namespace std; 7 | int root(int Computer[],int i); 8 | void Union(int Computer[],int size[],int A, int B); 9 | 10 | 11 | int main (void) 12 | { 13 | 14 | /* ifstream fin; 15 | 16 | ofstream fout; 17 | 18 | fin.open("input.txt"); 19 | 20 | fout.open("output.txt");*/ 21 | int n; 22 | cin>>n; 23 | while (n--) 24 | { 25 | int c; 26 | cin>>c; 27 | int size[c]; 28 | int Computer[c]; 29 | for (int i = 1; i <= c;i++) 30 | { 31 | Computer[i] = i; 32 | size[i] = 1; 33 | } 34 | int ss = 0; 35 | int us = 0 ; 36 | string st; 37 | getline(cin,st); 38 | // getline(cin,st); 39 | while (getline(cin,st)) 40 | { 41 | if (st == "") 42 | break; 43 | int ci; 44 | int cj; 45 | char status; 46 | istringstream s(st); 47 | s>>status>>ci>>cj; 48 | 49 | // cout< 2 | 3 | using namespace std; 4 | int main (void) 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | int p; 13 | cin>>p; 14 | int array[p]; 15 | for (int a = 0; a < p;a++) 16 | cin>>array[a]; 17 | int ans; 18 | bool check = false; 19 | for(int i = 0; i < (1< 5 | #include 6 | #include 7 | //#define fin cin 8 | //#define fout cout 9 | using namespace std; 10 | struct Car{ 11 | string name; 12 | int low; 13 | int high; 14 | }; 15 | 16 | int main() 17 | { 18 | /* ifstream fin; 19 | 20 | ofstream fout; 21 | 22 | fin.open("input.txt"); 23 | 24 | fout.open("output.txt");*/ 25 | int t; 26 | cin >> t; 27 | while (t--) 28 | { 29 | int d; 30 | cin >> d; 31 | Car* pcar = new Car[d]; 32 | int a = 0; 33 | while (a != d) 34 | { 35 | // cout<> pcar[a].name >> pcar[a].low >> pcar[a].high; 38 | //cout<< pcar[d-1].name << pcar[d-1].low << pcar[d-1].high; 39 | a++; 40 | } 41 | 42 | int qSize; 43 | cin >> qSize; 44 | while (qSize--) 45 | { 46 | int q; 47 | cin >> q; 48 | // cout<<"HI"; 49 | int count = 0; 50 | int spec = 0; 51 | for (int i = 0;i < d; i++) 52 | { 53 | // cout<= pcar[i].low && q <= pcar[i].high) 55 | { 56 | count++; 57 | spec = i; 58 | } 59 | 60 | } 61 | if (count == 1) 62 | cout < 2 | #include 3 | #include 4 | #include 5 | #include 6 | //#define fin cin 7 | //#define fout cout 8 | using namespace std; 9 | 10 | 11 | 12 | int main (void) 13 | { 14 | /* ifstream fin; 15 | 16 | ofstream fout; 17 | 18 | fin.open("input.txt"); 19 | 20 | fout.open("output.txt");*/ 21 | int n; 22 | vector numbers; 23 | int qCase = 0; 24 | while(1) 25 | { 26 | 27 | cin>>n; 28 | if (n == 0) 29 | break; 30 | for (int i = 0; i < n;i++) 31 | { 32 | int a; 33 | cin>>a; 34 | numbers.push_back(a); 35 | } 36 | 37 | 38 | int m;//number of queries 39 | 40 | 41 | 42 | cin>>m; 43 | qCase++; 44 | cout<<"Case "<>q; 51 | int ans = numbers[0] + numbers[1]; 52 | int current; 53 | cout<<"Closest sum to "< abs(current - q)) 59 | { 60 | // cout<<"\n"< 2 | #include 3 | using namespace std; 4 | 5 | int rowPosition[1000]; 6 | int position[1000]; 7 | int ans; 8 | 9 | bool place (int newCol,int newRow) 10 | { 11 | for (int i = 1; i < newCol;i++) 12 | { 13 | if (rowPosition[i] == newRow) 14 | return false; 15 | if (abs(i - newCol) == abs(rowPosition[i] - newRow)) 16 | return false; 17 | } 18 | return true; 19 | 20 | } 21 | int count() 22 | { 23 | int count = 0; 24 | for (int i = 1; i < 9;i++) 25 | if(rowPosition[i] - position[i] != 0) 26 | count++; 27 | // cout<<"Count: "<>position[1]>>position[2]>>position[3]>>position[4]>>position[5]>> 60 | position[6]>>position[7]>>position[8]) 61 | { 62 | 63 | 64 | ans = 1000; 65 | backtrack(1); 66 | 67 | cout<<"Case "< 2 | #include 3 | 4 | using namespace std; 5 | int arr[100000]; 6 | int main (void) 7 | { 8 | 9 | int T; 10 | cin>>T; 11 | int Case = 1; 12 | while (T--) 13 | { 14 | 15 | int x; 16 | cin>>x; 17 | 18 | for (int j = 0; j < x;j++) 19 | cin>>arr[j]; 20 | int k = arr[0]; 21 | 22 | for (int i = 1; i < x ;i++) 23 | { 24 | k = max(k,arr[i] - arr[i-1]); 25 | }//find k 26 | cout< j) 36 | { 37 | k++; 38 | break; 39 | } 40 | } 41 | cout<<"Case "< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main (void) 7 | { 8 | while(1) 9 | { 10 | 11 | int row; 12 | cin>>row; 13 | int col; 14 | cin>>col; 15 | if(row == 0 && col == 0) 16 | break; 17 | int arr[row][col]; 18 | 19 | for(int i = 0;i >arr[i][j]; 22 | 23 | int q; 24 | cin>>q; 25 | while(q--) 26 | { 27 | int L; 28 | cin>>L; 29 | int U; 30 | cin>>U; 31 | 32 | int ans = 0; 33 | for(int j = 0; j < row;j++) 34 | { 35 | int* lb = lower_bound(arr[j], arr[j] + col,L);//finding the starting number for each line 36 | int index = lb - arr[j]; // get the index of the starting number 37 | for (int k = ans; k < row;k++) 38 | { 39 | if(j+k >= row || index + k >= col || arr[j+k][index + k] > U) 40 | /* 3 conditions to terminate the loop 41 | 1: the last number of row 42 | 2: the last number of a collumn 43 | 3: if the diagonal index is larger than the upper bound 44 | */ 45 | break; 46 | if (k + 1 > ans)//add 1 if the break above not execute 47 | ans = k + 1; 48 | } 49 | } 50 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main (void) 7 | { 8 | int n; 9 | int count = 0; 10 | while(1) 11 | { 12 | cin>>n; 13 | int array[n]; 14 | if (n != 0 && count != 0) 15 | cout<>array[i]; 21 | 22 | 23 | for (int a = 0; a < n - 5;a++) 24 | for (int b = a + 1; b < n - 4;b++) 25 | for(int c = b + 1; c < n - 3; c++) 26 | for(int d = c + 1;d < n - 2; d ++) 27 | for(int e = d + 1; e < n - 1; e++ ) 28 | for(int f = e + 1; f < n;f++) 29 | cout< 2 | 3 | using namespace std; 4 | 5 | int main () { 6 | int n; 7 | 8 | while (cin >> n) { 9 | bool isJolly = true; 10 | bool check[n] = { 0 }; 11 | int arr[n]; 12 | 13 | for (int i = 0; i < n; ++i) { 14 | cin >> arr[i]; 15 | if (i > 0) { 16 | check[abs(arr[i]-arr[i-1])] = true; 17 | } 18 | } 19 | 20 | for (int i = 1; i < n; ++i) { 21 | if (!check[i]){ 22 | isJolly = false; 23 | break; 24 | } 25 | } 26 | 27 | cout << ((isJolly) ? "Jolly\n" : "Not jolly\n"); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /iRasuna/Chapter 2/UVa 10258.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | struct Teams { 6 | int ID; 7 | int qSolved; 8 | int penalty; 9 | int qMap[10]; 10 | bool submit; 11 | }; 12 | 13 | bool team_cmp(Teams const& lhs, Teams const& rhs) { 14 | if (lhs.qSolved != rhs.qSolved) 15 | return lhs.qSolved > rhs.qSolved; 16 | if (lhs.penalty != rhs.penalty) 17 | return lhs.penalty < rhs.penalty; 18 | return lhs.ID < rhs.ID; 19 | } 20 | 21 | int main() { 22 | int t, teamID, questionID, time; 23 | char verdict; 24 | string s; 25 | 26 | cin >> t; 27 | getline(cin, s); getline(cin, s); 28 | 29 | while(t--){ 30 | Teams team[101] = { 0 }; 31 | 32 | while(getline(cin, s), s != "") { 33 | istringstream strin(s); 34 | 35 | strin >> teamID >> questionID >> time >> verdict; 36 | 37 | team[teamID].ID = teamID; 38 | team[teamID].submit = true; 39 | 40 | if (team[teamID].qMap[questionID] != -1) { 41 | if (verdict == 'I') { 42 | team[teamID].qMap[questionID]++; 43 | } 44 | else if (verdict == 'C') { 45 | team[teamID].penalty += (team[teamID].qMap[questionID] * 20) + time; 46 | team[teamID].qSolved++; 47 | team[teamID].qMap[questionID] = -1; 48 | } 49 | } 50 | } 51 | 52 | sort(team, team+101, &team_cmp); 53 | 54 | for(int i = 0; i < 101; ++i){ 55 | if (team[i].submit){ 56 | cout << team[i].ID << " " << team[i].qSolved << " " << team[i].penalty << endl; 57 | } 58 | } 59 | 60 | if (t) cout << endl; 61 | } 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /iRasuna/Chapter 2/UVa 1062.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string s; 7 | int _case = 1; 8 | 9 | while (cin >> s, s != "end") { 10 | int len = s.length(); 11 | int arr[1005], dp[1005]; 12 | int stack = 0; 13 | 14 | for (int i = 0; i < len; ++i) { 15 | arr[i] = s[i] - 'A'; 16 | } 17 | 18 | for (int i = 0; i < len; ++i) { 19 | dp[i] = 1; 20 | 21 | for (int j = 0; j < i; ++j) { 22 | if (arr[j] < arr[i]) { 23 | dp[i] = max(dp[i], dp[j]+1); 24 | } 25 | } 26 | } 27 | 28 | for (int i = 0; i < len; ++i) { 29 | stack = max(stack, dp[i]); 30 | } 31 | 32 | cout << "Case " << _case << ": " << stack << endl; 33 | _case++; 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /iRasuna/Chapter 2/UVa 11933.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | string dec2bin(int x) { 6 | string result = ""; 7 | 8 | while (x > 0) { 9 | result = char((x % 2) + '0') + result; 10 | x /= 2; 11 | } 12 | 13 | return result; 14 | } 15 | 16 | int main() { 17 | int n; 18 | 19 | while (cin >> n, n != 0) { 20 | string bin = dec2bin(n); 21 | bool alternate = true; 22 | int a = 0, b = 0, len = bin.length() - 1; 23 | 24 | for (int i = len; i >= 0; --i) { 25 | if (bin[i]=='1' && alternate) { 26 | a += pow(2, len-i); 27 | alternate = false; 28 | } 29 | else if (bin[i]=='1') { 30 | b += pow(2, len-i); 31 | alternate = true; 32 | } 33 | } 34 | 35 | cout << a << " " << b << endl; 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /iRasuna/Chapter 2/UVa 11988.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | string s; 7 | 8 | while (cin >> s) { 9 | string result = ""; 10 | int len = s.length(); 11 | int pos = 0; 12 | 13 | for (int i = 0; i < len; ++i) { 14 | if (s[i] == '[') { 15 | pos = 0; 16 | } 17 | else if (s[i] == ']') { 18 | pos = result.length(); 19 | } 20 | else { 21 | result.insert(pos, 1, s[i]); 22 | pos++; 23 | } 24 | } 25 | 26 | cout << result << endl; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /iRasuna/README.md: -------------------------------------------------------------------------------- 1 | ## [iRasuna](https://github.com/iRasuna) 2 | 3 | ### Chapter 2 - _Data Structures and Libraries_ 4 | 5 | - [X] [UVa 10038 - Jolly Jumpers](Chapter%202/UVa%2010038.cpp) 6 | - [ ] UVa 11581 - Grid Successors :question: 7 | - [X] [UVa 10258 - Contest Scoreboard](Chapter%202/UVa%2010258.cpp) 8 | - [X] [UVa 11933 - Splitting Numbers](Chapter%202/UVa%2011933.cpp) 9 | - [X] [UVa 11988 - Broken Keyboard](Chapter%202/UVa%2011988.cpp) :exclamation: 10 | - [X] [UVa 01062 - Containers](Chapter%202/UVa%201062.cpp) 11 | - [ ] UVa 11286 - Conformity 12 | - [ ] UVa 00978 - Lemmings Battle 13 | - [ ] UVa 10954 - Add All 14 | - [ ] UVa 00599 - The Forrest for the Trees 15 | - [ ] UVa 00793 - Network Connections 16 | - [ ] UVa 12532 - Interval Product 17 | 18 | ### Chapter 3 - _Problem Solving Paradigms_ 19 | 20 | - [ ] UVa 01237 - Expert Enough 21 | - [ ] UVa 10487 - Closest Sums 22 | - [ ] UVa 00441 - Lotto 23 | - [ ] UVa 10660 - Citizen attention 24 | - [ ] UVa 01047 - Zones 25 | - [ ] UVa 12455 - Bars 26 | - [ ] UVa 11085 - Back to the 8-Queens 27 | - [ ] UVa 00524 - Prime Ring Problem 28 | - [ ] UVa 01262 - Password 29 | - [ ] UVa 12192 - Grapevine 30 | - [ ] UVa 12032 - The Monkey 31 | - [ ] UVa 00183 - Bit Maps 32 | - [ ] UVa 11389 - The Bus Driver Problem 33 | - [ ] UVa 12210 - A Match Making Problem 34 | - [ ] UVa 11157 - Dynamic Frog 35 | - [ ] UVa 10755 - Garbage Heap 36 | - [ ] UVa 11951 - Area 37 | - [ ] UVa 00481 - What Goes Up? 38 | - [ ] UVa 10819 - Trouble of 13-Dots 39 | - [ ] UVa 10496 - Collecting Beepers 40 | - [ ] UVa 00357 - Let Me Count The Ways 41 | - [ ] UVa 10337 - Flight Planner 42 | 43 | ### Chapter 4 - _Graph_ 44 | 45 | - [ ] UVa 12442 - Forwarding Emails 46 | - [ ] UVa 01103 - Ancient Messages 47 | - [ ] UVa 10305 - Ordering Tasks 48 | - [ ] UVa 10004 - Bicoloring 49 | - [ ] UVa 10765 - Doves and Bombs 50 | - [ ] UVa 00247 - Calling Circles 51 | - [ ] UVa 11747 - Heavy Cycle Edges 52 | - [ ] UVa 10369 - Arctic Networks 53 | - [ ] UVa 00924 - Spreading the News 54 | - [ ] UVa 00314 - Robot 55 | - [ ] UVa 01112 - Mice and Maze 56 | - [ ] UVa 11492 - Babel 57 | - [ ] UVa 10557 - XYZZY 58 | - [ ] UVa 10171 - Meeting Prof. Miguel 59 | - [ ] UVa 01056 - Degrees of Separation 60 | - [ ] UVa 11167 - Monkeys in the Emei 61 | - [ ] UVa 11380 - Down Went The Titanic 62 | - [ ] UVa 10350 - Liftless Eme 63 | - [ ] UVa 00988 - Many paths, one 64 | - [ ] UVa 11487 - Gathering Food 65 | - [ ] UVa 10805 - Cockroach Escape 66 | - [ ] UVa 10596 - Morning Walk 67 | - [ ] UVa 11159 - Factors and Multiples 68 | 69 | ### Chapter 5 - _Mathematics_ 70 | 71 | - [ ] UVa 11723 - Numbering Road 72 | - [ ] UVa 01225 - Digit Counting 73 | - [ ] UVa 11254 - Consecutive - [ ] Integers 74 | - [ ] UVa 10751 - Chessboard 75 | - [ ] UVa 11231 - Black and White Painting 76 | - [ ] UVa 10233 - Dermuba Triangle 77 | - [ ] UVa 00443 - Humble Numbers 78 | - [ ] UVa 00701 - Archaelogist’s Dilemma 79 | - [ ] UVa 10586 - Polynomial Remains 80 | - [ ] UVa 00377 - Cowculations 81 | - [ ] UVa 12036 - Stable Grid 82 | - [ ] UVa 11879 - Multiple of 17 83 | - [ ] UVa 00389 - Basically Speaking 84 | - [ ] UVa 01210 - Sum of Consecutive 85 | - [ ] UVa 01230 - MODEX 86 | - [ ] UVa 00763 - Fibinary Numbers 87 | - [ ] UVa 10541 - Stripe 88 | - [ ] UVa 10312 - Expression Bracketing 89 | - [ ] UVa 11597 - Spanning Subtree 90 | - [ ] UVa 11538 - Chess Queen 91 | - [ ] UVa 00543 - Goldbach’s Conjecture 92 | - [ ] UVa 11827 - Maximum GCD 93 | - [ ] UVa 00324 - Factorial Frequencies 94 | - [ ] UVa 11466 - Largest Prime Divisor 95 | - [ ] UVa 11889 - Benefit 96 | - [ ] UVa 11728 - Alternate Task 97 | - [ ] UVa 10990 - Another New Function 98 | - [ ] UVa 10212 - The Last Non-zero Digit 99 | - [ ] UVa 10104 - Euclid Problem 100 | - [ ] UVa 10110 - Light, more light 101 | - [ ] UVa 11176 - Winning Streak 102 | - [ ] UVa 11053 - Flavius Josephus 103 | - [ ] UVa 10111 - Find the Winning 104 | 105 | ### Chapter 6 - _String Processing_ 106 | 107 | - [ ] UVa 10851 - 2D Hieroglyphs ... 108 | - [ ] UVa 11385 - Da Vinci Code 109 | - [ ] UVa 00902 - Password Search 110 | - [ ] UVa 11878 - Homework Checker 111 | - [ ] UVa 00622 - Grammar Evaluation 112 | - [ ] UVa 00325 - Identifying Legal ... 113 | - [ ] UVa 00488 - Triangle Wave 114 | - [ ] UVa 00644 - Immediate Decodability 115 | - [ ] UVa 00941 - Permutations 116 | - [ ] UVa 10298 - Power Strings 117 | - [ ] UVa 00422 - Word Search Wonder 118 | - [ ] UVa 00526 - Edit Distance 119 | - [ ] UVa 11151 - Longest Palindrome 120 | - [ ] UVa 00760 - DNA Sequencing 121 | 122 | 123 | ### Chapter 7 - _(Computational) Geometry_ 124 | 125 | - [ ] UVa 00920 - Sunny Mountains 126 | - [ ] UVa 10005 - Packing polygons 127 | - [ ] UVa 10577 - Bounding box 128 | - [ ] UVa 00460 - Overlapping Rectangles 129 | - [ ] UVa 00737 - Gleaming the Cubes 130 | - [ ] UVa 10652 - Board Wrapping 131 | 132 | ### Chapter 8 - _More Advanced Topics_ 133 | 134 | - [ ] UVa 10309 - Turn the Lights Off 135 | - [ ] UVa 01098 - Robots on Ice 136 | - [ ] UVa 01211 - Atomic Car Race 137 | - [ ] UVa 01231 - ACORN 138 | - [ ] UVa 01099 - Sharing Chocolate 139 | - [ ] UVa 10983 - Buy one, get ... 140 | - [ ] UVa 10891 - Game of Sum 141 | - [ ] UVa 11324 - The Largest Clique 142 | - [ ] UVa 11635 - Hotel Booking 143 | - [ ] UVa 10539 - Almost Prime Numbers 144 | - [ ] UVa 10012 - How Big Is It? 145 | - [ ] UVa 11525 - Permutation 146 | - [ ] UVa 11610 - Reverse Prime 147 | 148 | ### Chapter 9 - _Rare Topics_ 149 | 150 | - [ ] UVa 10078 - Art Gallery 151 | - [ ] UVa 01096 - The Islands 152 | - [ ] UVa 00673 - Parentheses Balance 153 | - [ ] UVa 10296 - Jogging Trails 154 | - [ ] UVa 10245 - The Closest Pair Problem 155 | - [ ] UVa 10213 - How Many Pieces ... 156 | - [ ] UVa 00563 - Crimewave 157 | - [ ] UVa 00612 - DNA Sorting 158 | - [ ] UVa 00439 - Knight Moves 159 | - [ ] UVa 00348 - Optimal Array Mult 160 | - [ ] UVa 10746 - Crime Wave - The Sequel 161 | - [ ] UVa 01184 - Air Raid 162 | - [ ] UVa 00120 - Stacks Of Flapjacks 163 | - [ ] UVa 00344 - Roman Digititis 164 | - [ ] UVa 11462 - Age Sort 165 | - [ ] UVa 10017 - The Never Ending -------------------------------------------------------------------------------- /nadide/Chapter2/UVa-00599.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void dfs(int v[26][26], int was[], int nodes[], int size, int x) { 7 | was[nodes[x]] = 1; 8 | for (int i=0; i < size; i++) { 9 | if (v[nodes[x]][nodes[i]] && !was[i]) 10 | dfs(v, was, nodes, size, i); 11 | } 12 | } 13 | 14 | int main () 15 | { 16 | int t; cin >> t; 17 | while (t--) { 18 | int v[26][26]={0}; 19 | string s; cin>>s; 20 | while (s[0] != '*') { 21 | v[s[1]-'A'][s[3]-'A'] = 1; 22 | v[s[3]-'A'][s[1]-'A'] = 1; 23 | cin >> s; 24 | } 25 | cin >> s; 26 | 27 | int size=s.length()/2+1, nodes[size]; 28 | for (int i=0; i 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int root(int* ar, int x) { 8 | while (ar[x] != x) 9 | x = ar[x]; 10 | return x; 11 | } 12 | 13 | void unionn (int* ar, int a, int b) { 14 | int rA = root(ar, a); 15 | int rB = root(ar, b); 16 | ar[rA] = rB; 17 | } 18 | 19 | bool find (int* ar, int a, int b) { 20 | if (root(ar,a) == root(ar,b)) 21 | return true; 22 | else 23 | return false; 24 | } 25 | 26 | int main () 27 | { 28 | int t; cin >> t; 29 | 30 | string s; 31 | getline(cin, s); 32 | while (t--) { 33 | int n; cin >> n; 34 | getline(cin, s); 35 | 36 | int ar[10005]; 37 | for (int i=0; i<=n; i++) ar[i]=i; 38 | int succes=0, fail=0; 39 | 40 | getline(cin, s); 41 | do { 42 | char c; int x,y; 43 | stringstream ss(s); 44 | ss >> c >> x >> y; 45 | 46 | if (c == 'c') 47 | unionn (ar,x,y); 48 | else 49 | find(ar,x,y) ? ++succes : ++fail ; 50 | 51 | getline(cin, s); 52 | } while(!s.empty()); 53 | cout << succes <<","<< fail << endl; 54 | if(t) cout << endl; 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /nadide/Chapter2/UVa-10038.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | while (cin >> n) { 9 | vector v(n, 0); 10 | 11 | int num1; cin >> num1; 12 | for (int i=0; i < n-1; i++) { 13 | int num2; cin >> num2; 14 | if (abs(num2-num1) < n) 15 | v[abs(num2-num1)] = 1; 16 | num1 = num2; 17 | } 18 | 19 | bool jolly = true; 20 | for (int i=1; i < n; i++) 21 | if(v[i] == 0) { 22 | jolly = false; 23 | break; 24 | } 25 | cout << (jolly?"Jolly":"Not jolly") << endl; 26 | } 27 | } -------------------------------------------------------------------------------- /nadide/Chapter2/UVa-1062.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NAU-ACM/ICPC-Question-Solving/7c0c53a7b3b6c7393cbdf63687ca633f7c4a7606/nadide/Chapter2/UVa-1062.cpp -------------------------------------------------------------------------------- /nadide/Chapter2/UVa-11286.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main () { 8 | int n; cin >> n; 9 | while (n) { 10 | map,int> m; 11 | while (n--) { 12 | vector v(5); 13 | cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4]; 14 | sort(v.begin(), v.end()); 15 | m[v]++; 16 | } 17 | 18 | int max = 0, nMax = 0; 19 | for (map,int>::iterator i = m.begin(); i != m.end(); ++i) 20 | { 21 | if (i->second > max) 22 | max = i->second, nMax = 0; 23 | if (i->second == max) 24 | nMax += max; 25 | } 26 | cout << nMax << endl; 27 | cin >> n; 28 | } 29 | } -------------------------------------------------------------------------------- /nadide/Chapter2/UVa-11581.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int g[3][3]; 4 | 5 | void f() { 6 | int h[3][3]; 7 | 8 | h[0][0] = (g[0][1] + g[1][0]) % 2; 9 | h[0][1] = (g[0][0] + g[1][1] + g[0][2]) % 2; 10 | h[0][2] = (g[0][1] + g[1][2]) % 2; 11 | 12 | h[1][0] = (g[0][0] + g[1][1] + g[2][0]) % 2; 13 | h[1][1] = (g[0][1] + g[1][0] + g[1][2] + g[2][1]) % 2; 14 | h[1][2] = (g[1][1] + g[0][2] + g[2][2]) % 2; 15 | 16 | h[2][0] = (g[2][1] + g[1][0]) % 2; 17 | h[2][1] = (g[2][0] + g[1][1] + g[2][2]) % 2; 18 | h[2][2] = (g[2][1] + g[1][2]) % 2; 19 | 20 | for (int i=0; i < 3; i++) 21 | for (int j=0; j < 3; j++) 22 | g[i][j] = h[i][j]; 23 | } 24 | 25 | bool isZero() { 26 | for (int i = 0; i < 3; i++) { 27 | for (int j = 0; j < 3; j++) { 28 | if (g[i][j] > 0) 29 | return false; 30 | } 31 | } 32 | return true; 33 | } 34 | 35 | int main() { 36 | int t; cin >> t; 37 | 38 | while (t--) { 39 | for (int i=0; i < 3; i++) { 40 | string s; cin >> s; 41 | for (int j=0; j < 3; j++) 42 | g[i][j] = s[j]-'0'; 43 | } 44 | 45 | int ind = -1; 46 | while (!isZero()) { 47 | f(); 48 | ind++; 49 | } 50 | cout << ind << endl; 51 | } 52 | 53 | return 0; 54 | } -------------------------------------------------------------------------------- /nadide/Chapter2/UVa-12532.cpp: -------------------------------------------------------------------------------- 1 | // Interval Product 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | char *tree; 7 | int h; 8 | 9 | char sign(int x) { 10 | if (x > 0) return 1; 11 | if (x < 0) return -1; 12 | return 0; 13 | } 14 | 15 | void build(int n) { 16 | for(h=1; h> x; 22 | tree[i] = sign(x); 23 | } 24 | for (int i=h-1; i > 0; i--) //others 25 | tree[i] = sign(tree[2*i]) * sign(tree[2*i+1]); 26 | } 27 | 28 | char product(int l, int r) { 29 | char ans = 1; 30 | while(l <= r){ 31 | if(l % 2 == 1) ans *= tree[l]; 32 | if(r % 2 == 0) ans *= tree[r]; 33 | l = (l+1)/2; 34 | r = (r-1)/2; 35 | } 36 | return ans; 37 | } 38 | 39 | void change(int x, int y) { 40 | if (sign(tree[h+x-1] == sign(y))) return; 41 | 42 | tree[h+x-1] = sign(y); 43 | for (int i=(h+x-1)/2; i > 0; i/=2) 44 | tree[i] = sign(tree[2*i]) * sign(tree[2*i+1]); 45 | } 46 | 47 | int main() { 48 | int n, k; 49 | char c; int x,y; 50 | 51 | while (cin >> n >> k) { 52 | build (n); 53 | 54 | while (k--) { 55 | cin >> c >> x >> y; 56 | if (c == 'C') { 57 | change(x,y); 58 | } 59 | else { 60 | char ans = product(h+x-1, h+y-1); // range of leaves 61 | if(ans > 0) cout << "+"; 62 | else if(ans < 0) cout << "-"; 63 | else cout << "0"; 64 | } 65 | } 66 | cout << endl; 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /nadide/Chapter3/00183-Bit-Maps.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int m[201][201]; 6 | 7 | void BtoD (int Rl, int Rr, int Cl, int Cr, int ch) { 8 | // base case: 0-by-0 bitmap 9 | if (Rl == Rr || Cl == Cr) 10 | return; 11 | 12 | // make each line 50 ch 13 | if (ch > 0 && ch%50 == 0) 14 | printf("\n"); 15 | ch++; 16 | 17 | int zero=0; 18 | for (int r = Rl; r < Rr; ++r) 19 | for (int c = Cl; c < Cr; ++c) 20 | if (m[r][c] == 0) zero++; 21 | 22 | // if all are 0 23 | if (zero == (Rr-Rl)*(Cr-Cl)) 24 | printf("0"); 25 | // if all are 1 26 | else if (zero == 0) 27 | printf("1"); 28 | // otherwise divide it 29 | else { 30 | 31 | printf("D"); 32 | // mid of R and C 33 | int Rm = (Rl + Rr + 1) / 2; 34 | int Cm = (Cl + Cr + 1) / 2; 35 | 36 | // divide and conqure 37 | BtoD(Rl, Rm, Cl, Cm, ch); 38 | BtoD(Rl, Rm, Cm, Cr, ch); 39 | BtoD(Rm, Rr, Cl, Cm, ch); 40 | BtoD(Rm, Rr, Cm, Cr, ch); 41 | } 42 | } 43 | 44 | void DtoB (int Rl, int Rr, int Cl, int Cr) { 45 | // base case: 0-by-0 bitmap 46 | if (Rl == Rr || Cl == Cr) 47 | return; 48 | 49 | // Get 1 char 50 | char ch; 51 | scanf ("%c", &ch); 52 | 53 | // if all quarter is 0 or 1 54 | if (ch == '0' || ch == '1') 55 | { 56 | for (int r = Rl; r < Rr; ++r) 57 | for (int c = Cl; c < Cr; ++c) 58 | m[r][c] = ch - '0'; 59 | return; 60 | } 61 | // otherwise extend quarters - divided part 62 | else 63 | { 64 | int Rm = (Rl + Rr + 1) / 2; 65 | int Cm = (Cl + Cr + 1) / 2; 66 | DtoB(Rl, Rm, Cl, Cm); 67 | DtoB(Rl, Rm, Cm, Cr); 68 | DtoB(Rm, Rr, Cl, Cm); 69 | DtoB(Rm, Rr, Cm, Cr); 70 | } 71 | 72 | } 73 | 74 | int main () { 75 | char type; 76 | scanf ("%c", &type); 77 | while (type != '#') { 78 | int row, col; 79 | scanf ("%d %d", &row, &col); 80 | 81 | // print first line 82 | printf("%s", (type == 'B'? "D" : "B")); 83 | printf("%4d%4d\n", row, col); 84 | 85 | if (type == 'B') { 86 | string s; 87 | // read all lines 88 | while (s.size() < row * col) 89 | { 90 | string tmp; 91 | getline(cin, tmp); 92 | s = s + tmp; 93 | } 94 | 95 | // place to 2D map 96 | for (int r = 0; r < row; ++r) 97 | for (int c = 0; c < col; ++c) 98 | m[r][c] = s[r * col + c] - '0'; 99 | 100 | // start with entire map 101 | BtoD (0, row, 0, col, 0); 102 | printf("\n"); 103 | } 104 | else { 105 | // start with entire map 106 | DtoB (0, row, 0, col); 107 | 108 | // print bit map 109 | for (int r = 0; r < row; ++r) 110 | for (int c = 0; c < col; ++c) 111 | { 112 | // make each line 50 char 113 | if (r + c > 0 && (r * col + c) % 50 == 0) 114 | printf("\n"); 115 | printf ("%d", m[r][c]); 116 | } 117 | printf("\n"); 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /nadide/Chapter3/UVa-00357.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main () { 6 | int n,c[5]={1,5,10,25,50}; 7 | while (scanf("%d", &n) == 1) { 8 | long long int dp[n+100]; 9 | memset (dp, 0, sizeof dp); 10 | 11 | dp[0] = 1; 12 | for (int i=0; i<5; i++) 13 | for (int j=c[i]; j<=n; j++) 14 | if (dp[j-c[i]]) 15 | dp[j] += dp[j-c[i]]; 16 | if (dp[n] == 1) 17 | printf("There is only 1 way to produce %d cents change.\n", n); 18 | else 19 | printf ("There are %lld ways to produce %d cents change.\n", dp[n], n); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /nadide/Chapter3/UVa-00441.cpp: -------------------------------------------------------------------------------- 1 | // Lotto 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int K, a[15]; 8 | 9 | cin >> K; 10 | while (K) { 11 | for (int i=0; i> a[i]; 13 | 14 | for (int i=0; i> K; 22 | if (K) cout << endl; 23 | } 24 | } -------------------------------------------------------------------------------- /nadide/Chapter3/UVa-01237.cpp: -------------------------------------------------------------------------------- 1 | // Expert Enough 2 | #include 3 | using namespace std; 4 | 5 | struct car{ 6 | int l,h; 7 | string m; 8 | } d[10005]; 9 | 10 | int main() { 11 | int t; cin >> t; 12 | while (t--) { 13 | int n; cin >> n; 14 | for (int i=0; i < n; i++) 15 | cin >> d[i].m >> d[i].l >> d[i].h; 16 | 17 | int q; cin >> q; 18 | while (q--) { 19 | int p; cin >> p; 20 | 21 | int maker = -1; 22 | for (int i=0; i < n; i++) 23 | if (d[i].l <= p && p <= d[i].h) 24 | if (maker == -1) 25 | maker = i; 26 | else { 27 | maker = -1; 28 | break; 29 | } 30 | 31 | if (maker == -1) 32 | cout << "UNDETERMINED" << endl; 33 | else 34 | cout << d[maker].m << endl; 35 | } 36 | if(t) cout << endl; 37 | } 38 | } -------------------------------------------------------------------------------- /nadide/Chapter3/UVa-10487.cpp: -------------------------------------------------------------------------------- 1 | // Closest Sum 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | #define INF 0x7FFFFFFF 8 | int a[10001]; 9 | 10 | int main() { 11 | int n,m,q,x=1; 12 | cin >> n; 13 | while (n) { 14 | cout << "Case "<< x++ <<":" << endl; 15 | for (int i=0; i < n; i++) 16 | cin >> a[i]; 17 | //sort(a, a+n); 18 | cin >> m; 19 | while (m--) { 20 | cin >> q; 21 | 22 | int diff=INF, sum=0; 23 | for (int i=0; i < n && diff; i++) 24 | for (int j=i+1; j < n && diff; j++) 25 | if (abs(q-(a[i]+a[j])) < diff) { 26 | sum = a[i]+a[j]; 27 | diff = abs(q-(a[i]+a[j])); 28 | if (diff == 0) break; 29 | } 30 | cout << "Closest sum to "<> n; 34 | } 35 | } -------------------------------------------------------------------------------- /nadide/Chapter3/UVa-10660.cpp: -------------------------------------------------------------------------------- 1 | // Citizen Attention 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | #define INF 0x7fffffff 7 | struct population {int idx,val;} pop[5]; 8 | 9 | int distXY(int x, int y) { 10 | return abs(x%5-y%5) + abs(x/5-y/5); 11 | } 12 | 13 | int dist(int x, int i, int j, int k, int l, int m) { 14 | int mn = distXY(x, i); 15 | mn = min(mn, distXY(x, j)); 16 | mn = min(mn, distXY(x, k)); 17 | mn = min(mn, distXY(x, l)); 18 | mn = min(mn, distXY(x, m)); 19 | return mn; 20 | } 21 | 22 | int main() { 23 | int x,y,z, mnArr[5]; 24 | 25 | int t; cin >> t; 26 | while (t--) { 27 | int n; cin >> n; 28 | for (int i=0; i < n; ++i) { 29 | cin >> x >> y >> z; 30 | pop[i].idx = x*5+y, pop[i].val = z; 31 | } 32 | 33 | int mnDis = INF; 34 | for (int i=0; i < 25; i++) 35 | for (int j=i+1; j < 25; j++) 36 | for (int k=j+1; k < 25; k++) 37 | for (int l=k+1; l < 25; l++) 38 | for (int m=l+1; m < 25; m++) { 39 | int total = 0; 40 | for (int ii=0; ii < n; ii++) 41 | total += dist(pop[ii].idx, i,j,k,l,m) * pop[ii].val; 42 | if (total < mnDis) { 43 | mnDis = total; 44 | mnArr[0]=i, mnArr[1]=j, mnArr[2]=k, mnArr[3]=l, mnArr[4]=m; 45 | } 46 | } 47 | cout << mnArr[0] <<" "<< mnArr[1] <<" "<< mnArr[2] <<" "<< mnArr[3] <<" "<< mnArr[4] << endl; 48 | } 49 | } -------------------------------------------------------------------------------- /nadide/README.md: -------------------------------------------------------------------------------- 1 | ## [nadide](https://github.com/nadide) 2 | 3 | Solutions for the homeworks 4 | 5 | ### Chapter 2 - _Data Structures and Libraries_ 6 | 7 | - [x] [UVa 10038 - Jolly Jumpers](Chapter2/UVa-10038.cpp) 8 | - [x] [UVa 11581 - Grid Successors](Chapter2/UVa-11581.cpp) 9 | - [ ] UVa 10258 - Contest Scoreboard 10 | - [ ] UVa 11933 - Splitting Numbers 11 | - [ ] UVa 11988 - Broken Keyboard 12 | - [ ] UVa 01062 - Containers 13 | - [x] [UVa 11286 - Conformity](Chapter2/UVa-11286.cpp) 14 | - [ ] UVa 00978 - Lemmings Battle 15 | - [ ] UVa 10954 - Add All 16 | - [ ] UVa 00599 - The Forrest for the Trees 17 | - [x] [UVa 00793 - Network Connections](Chapter2/UVa-00793.cpp) 18 | - [x] [UVa 12532 - Interval Product](Chapter2/UVa-12532.cpp) 19 | 20 | ### Chapter 3 - _Problem Solving Paradigms_ 21 | 22 | - [x] [UVa 01237 - Expert Enough](Chapter3/UVa-01237.cpp) 23 | - [x] [UVa 10487 - Closest Sums](Chapter3/UVa-10487.cpp) 24 | - [x] [UVa 00441 - Lotto](Chapter3/UVa-00441.cpp) 25 | - [x] [UVa 10660 - Citizen attention](Chapter3/UVa-10660.cpp) 26 | - [ ] UVa 01047 - Zones 27 | - [ ] UVa 12455 - Bars 28 | - [ ] UVa 11085 - Back to the 8-Queens 29 | - [ ] UVa 00524 - Prime Ring Problem 30 | - [ ] UVa 01262 - Password 31 | - [ ] UVa 12192 - Grapevine 32 | - [ ] UVa 12032 - The Monkey 33 | - [ ] UVa 00183 - Bit Maps 34 | - [ ] UVa 11389 - The Bus Driver Problem 35 | - [ ] UVa 12210 - A Match Making Problem 36 | - [ ] UVa 11157 - Dynamic Frog 37 | - [ ] UVa 10755 - Garbage Heap 38 | - [ ] UVa 11951 - Area 39 | - [ ] UVa 00481 - What Goes Up? 40 | - [ ] UVa 10819 - Trouble of 13-Dots 41 | - [ ] UVa 10496 - Collecting Beepers 42 | - [ ] UVa 00357 - Let Me Count The Ways 43 | - [ ] UVa 10337 - Flight Planner 44 | 45 | ### Chapter 4 - _Graph_ 46 | 47 | - [ ] UVa 12442 - Forwarding Emails 48 | - [ ] UVa 01103 - Ancient Messages 49 | - [ ] UVa 10305 - Ordering Tasks 50 | - [ ] UVa 10004 - Bicoloring 51 | - [ ] UVa 10765 - Doves and Bombs 52 | - [ ] UVa 00247 - Calling Circles 53 | - [ ] UVa 11747 - Heavy Cycle Edges 54 | - [ ] UVa 10369 - Arctic Networks 55 | - [ ] UVa 00924 - Spreading the News 56 | - [ ] UVa 00314 - Robot 57 | - [ ] UVa 01112 - Mice and Maze 58 | - [ ] UVa 11492 - Babel 59 | - [ ] UVa 10557 - XYZZY 60 | - [ ] UVa 10171 - Meeting Prof. Miguel 61 | - [ ] UVa 01056 - Degrees of Separation 62 | - [ ] UVa 11167 - Monkeys in the Emei 63 | - [ ] UVa 11380 - Down Went The Titanic 64 | - [ ] UVa 10350 - Liftless Eme 65 | - [ ] UVa 00988 - Many paths, one 66 | - [ ] UVa 11487 - Gathering Food 67 | - [ ] UVa 10805 - Cockroach Escape 68 | - [ ] UVa 10596 - Morning Walk 69 | - [ ] UVa 11159 - Factors and Multiples 70 | 71 | ### Chapter 5 - _Mathematics_ 72 | 73 | - [ ] UVa 11723 - Numbering Road 74 | - [ ] UVa 01225 - Digit Counting 75 | - [ ] UVa 11254 - Consecutive - [ ] Integers 76 | - [ ] UVa 10751 - Chessboard 77 | - [ ] UVa 11231 - Black and White Painting 78 | - [ ] UVa 10233 - Dermuba Triangle 79 | - [ ] UVa 00443 - Humble Numbers 80 | - [ ] UVa 00701 - Archaelogist’s Dilemma 81 | - [ ] UVa 10586 - Polynomial Remains 82 | - [ ] UVa 00377 - Cowculations 83 | - [ ] UVa 12036 - Stable Grid 84 | - [ ] UVa 11879 - Multiple of 17 85 | - [ ] UVa 00389 - Basically Speaking 86 | - [ ] UVa 01210 - Sum of Consecutive 87 | - [ ] UVa 01230 - MODEX 88 | - [ ] UVa 00763 - Fibinary Numbers 89 | - [ ] UVa 10541 - Stripe 90 | - [ ] UVa 10312 - Expression Bracketing 91 | - [ ] UVa 11597 - Spanning Subtree 92 | - [ ] UVa 11538 - Chess Queen 93 | - [ ] UVa 00543 - Goldbach’s Conjecture 94 | - [ ] UVa 11827 - Maximum GCD 95 | - [ ] UVa 00324 - Factorial Frequencies 96 | - [ ] UVa 11466 - Largest Prime Divisor 97 | - [ ] UVa 11889 - Benefit 98 | - [ ] UVa 11728 - Alternate Task 99 | - [ ] UVa 10990 - Another New Function 100 | - [ ] UVa 10212 - The Last Non-zero Digit 101 | - [ ] UVa 10104 - Euclid Problem 102 | - [ ] UVa 10110 - Light, more light 103 | - [ ] UVa 11176 - Winning Streak 104 | - [ ] UVa 11053 - Flavius Josephus 105 | - [ ] UVa 10111 - Find the Winning 106 | 107 | ### Chapter 6 - _String Processing_ 108 | 109 | - [ ] UVa 10851 - 2D Hieroglyphs ... 110 | - [ ] UVa 11385 - Da Vinci Code 111 | - [ ] UVa 00902 - Password Search 112 | - [ ] UVa 11878 - Homework Checker 113 | - [ ] UVa 00622 - Grammar Evaluation 114 | - [ ] UVa 00325 - Identifying Legal ... 115 | - [ ] UVa 00488 - Triangle Wave 116 | - [ ] UVa 00644 - Immediate Decodability 117 | - [ ] UVa 00941 - Permutations 118 | - [ ] UVa 10298 - Power Strings 119 | - [ ] UVa 00422 - Word Search Wonder 120 | - [ ] UVa 00526 - Edit Distance 121 | - [ ] UVa 11151 - Longest Palindrome 122 | - [ ] UVa 00760 - DNA Sequencing 123 | 124 | 125 | ### Chapter 7 - _(Computational) Geometry_ 126 | 127 | - [ ] UVa 00920 - Sunny Mountains 128 | - [ ] UVa 10005 - Packing polygons 129 | - [ ] UVa 10577 - Bounding box 130 | - [ ] UVa 00460 - Overlapping Rectangles 131 | - [ ] UVa 00737 - Gleaming the Cubes 132 | - [ ] UVa 10652 - Board Wrapping 133 | 134 | ### Chapter 8 - _More Advanced Topics_ 135 | 136 | - [ ] UVa 10309 - Turn the Lights Off 137 | - [ ] UVa 01098 - Robots on Ice 138 | - [ ] UVa 01211 - Atomic Car Race 139 | - [ ] UVa 01231 - ACORN 140 | - [ ] UVa 01099 - Sharing Chocolate 141 | - [ ] UVa 10983 - Buy one, get ... 142 | - [ ] UVa 10891 - Game of Sum 143 | - [ ] UVa 11324 - The Largest Clique 144 | - [ ] UVa 11635 - Hotel Booking 145 | - [ ] UVa 10539 - Almost Prime Numbers 146 | - [ ] UVa 10012 - How Big Is It? 147 | - [ ] UVa 11525 - Permutation 148 | - [ ] UVa 11610 - Reverse Prime 149 | 150 | ### Chapter 9 - _Rare Topics_ 151 | 152 | - [ ] UVa 10078 - Art Gallery 153 | - [ ] UVa 01096 - The Islands 154 | - [ ] UVa 00673 - Parentheses Balance 155 | - [ ] UVa 10296 - Jogging Trails 156 | - [ ] UVa 10245 - The Closest Pair Problem 157 | - [ ] UVa 10213 - How Many Pieces ... 158 | - [ ] UVa 00563 - Crimewave 159 | - [ ] UVa 00612 - DNA Sorting 160 | - [ ] UVa 00439 - Knight Moves 161 | - [ ] UVa 00348 - Optimal Array Mult 162 | - [ ] UVa 10746 - Crime Wave - The Sequel 163 | - [ ] UVa 01184 - Air Raid 164 | - [ ] UVa 00120 - Stacks Of Flapjacks 165 | - [ ] UVa 00344 - Roman Digititis 166 | - [ ] UVa 11462 - Age Sort 167 | - [ ] UVa 10017 - The Never Ending 168 | 169 | --------------------------------------------------------------------------------