Last active
October 2, 2017 19:04
-
-
Save MJ111/975d9ec3b00ad3756dd7ff63916f44e3 to your computer and use it in GitHub Desktop.
csacademy round#50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // can try http://mathworld.wolfram.com/ConvexHull.html, but overkill.. | |
| #include <algorithm> | |
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| int Dist(pair<int, int> a, pair<int, int> b) { | |
| return (a.first - b.first) * (a.first - b.first) + | |
| (a.second - b.second) * (a.second - b.second); | |
| } | |
| int main() { | |
| vector<pair<int, int>> coords(4); | |
| int t; | |
| cin >> t; | |
| while (t--) { | |
| int mn_y = 1005, mx_y = -1, mn_x = 1005, mx_x = -1; | |
| for (int i = 0; i < 4; i += 1) { | |
| cin >> coords[i].first >> coords[i].second; | |
| mn_x = min(mn_x, coords[i].first); | |
| mx_x = max(mx_x, coords[i].first); | |
| mn_y = min(mn_y, coords[i].second); | |
| mx_y = max(mx_y, coords[i].second); | |
| } | |
| // mathmatical theory in square: https://en.wikipedia.org/wiki/File:01-Quadrat-Diagonale-gegeben.gif | |
| if (mx_x - mn_x != mx_y - mn_y) { | |
| cout << 0 << "\n"; | |
| continue; | |
| } | |
| vector<int> order = { 0, 1, 2, 3 }; | |
| bool k = false; | |
| do { | |
| int dist = Dist(coords[order[0]], coords[order[1]]); | |
| bool ok = true; | |
| for (int i = 0; i < 4; i += 1) { | |
| if (dist != Dist(coords[order[i]], coords[order[(i + 1) % 4]])) { | |
| ok = false; | |
| } | |
| } | |
| if (ok) { | |
| cout << 1 << '\n'; | |
| k = true; | |
| break; | |
| } | |
| } while (next_permutation(order.begin(), order.end())); // http://en.cppreference.com/w/cpp/algorithm/next_permutation | |
| if (not k) { | |
| cout << 0 << '\n'; | |
| } | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| vector<string> weekDays{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; | |
| vector<int> days{31,28,31,30,31,30,31,31,30,31,30,31}; | |
| int main() { | |
| string startDay; | |
| cin >> startDay; | |
| int day = find(weekDays.begin(), weekDays.end(), startDay) - weekDays.begin(); // vector iterator operation (+, -) | |
| int res = 0; | |
| for (int month = 0; month < 12; ++month) { | |
| for (int i = 0; i < days[month]; ++i) { | |
| if (i == 12 && day == 4) { | |
| ++res; | |
| } | |
| day = (day + 1) % 7; // convenient zero-based index | |
| } | |
| } | |
| cout << res << "\n"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <algorithm> | |
| using namespace std; | |
| int patienceSorting(int n, vector<int> els) { | |
| vector<int> piles; // save greatest value of each pile | |
| for (auto itr : els) { | |
| if (piles.size()) { | |
| vector<int>::iterator low = lower_bound(piles.begin(), piles.end(), itr-1, [](int a, int b) { return a > b; }); | |
| int pos = low - piles.begin(); | |
| if (low != end(piles)) { | |
| if (*low < itr) { | |
| *low = itr; | |
| continue; | |
| } | |
| } | |
| } | |
| piles.push_back(itr); | |
| } | |
| return piles.size(); | |
| } | |
| int main() { | |
| int n, k; cin >> n >> k; | |
| vector<int> els(n); | |
| for (int i = 0; i < n; i += 1) { | |
| int group, racer; cin >> group >> racer; | |
| els[racer - 1] = group; | |
| } | |
| cout << patienceSorting(n, els) << '\n'; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> // http://www.geeksforgeeks.org/bitsstdc-h-c/ | |
| using namespace std; | |
| const int MAX_LEN = 1000; | |
| int main() { | |
| string s; | |
| cin >> s; | |
| assert(1 <= s.size() && s.size() <= MAX_LEN); | |
| int x = 0, y = 0; | |
| for (auto it : s) { // https://solarianprogrammer.com/2014/08/21/cpp-14-auto-tutorial/ | |
| if (it == 'N') { | |
| x += 1; | |
| } else if (it == 'E') { | |
| y += 1; | |
| } else if (it == 'S') { | |
| x -= 1; | |
| } else if (it == 'W') { | |
| y -= 1; | |
| } else { | |
| return 1; | |
| } | |
| } | |
| cout << abs(x) + abs(y) << "\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment