SRM 564 DIV2 DIV1
2012-12-13 16:05
183 查看
1、只要把重复出现的删掉再判断就OK了。
2、分成三次计算,每一次里边的个数都是相同的
3、在可以移动一次的情况下,把所有的方格看成是重复出现的
DIV1-2、算法很巧妙,
http://blog.csdn.net/cyberzhg/article/details/8288425
#include <iostream> #include <string> #include <vector> #include <cstdlib> #include <map> #include <algorithm> #include <stack> #include <queue> #include <cmath> using namespace std; class FauxPalindromes { public: string classifyIt(string word) { int wend = word.size() - 1; int wstart = 0; bool judge = true; while (wstart < wend) { if (word[wstart] != word[wend]) { judge = false; break; } wstart++; wend--; } if(judge) return "PALINDROME"; string wordsame; int sz = word.size(); char pre = 'a'; for (int i = 0; i < sz; i++) { if (word[i] == pre) { pre = word[i]; continue; } wordsame += word[i]; pre = word[i]; } wend = wordsame.size() - 1; wstart = 0; judge = true; while (wstart < wend) { if (wordsame[wstart] != wordsame[wend]) { judge = false; break; } wstart++; wend--; } if (judge) return "FAUX"; return "NOT EVEN FAUX"; } };
2、分成三次计算,每一次里边的个数都是相同的
#include <iostream> #include <string> #include <vector> #include <cstdlib> #include <map> #include <algorithm> #include <stack> #include <queue> #include <cmath> using namespace std; typedef long long ll; ll cn[3][3]; class AlternateColors { public: string choose(ll cn[], ll num) { string c[] = { "RED", "GREEN", "BLUE" }; int co = -1; for (int i = 0; i < 3; i++) { if (cn[i] > 0) { co++; } if (co == num) return c[i]; } return "RED"; } string getColor(long long r, long long g, long long b, long long k) { ll cno[] = { r, g, b }; for (int i = 0; i < 3; i++) { ll cmin = min(min(cno[0], cno[1]), cno[2]); ll cmax = max(max(cno[0], cno[1]), cno[2]); ll cmid = cno[0] + cno[1] + cno[2] - cmin - cmax; if (cmin == 0) { if (cmid != 0) { cmin = cmid; } else { cmin = cmax; } } for (int j = 0; j < 3; j++) { if (cno[j] >= cmin) { cn[i][j] = cmin; cno[j] -= cmin; } } } ll num_color[3] = { 0, 0, 0 }; ll num_total[3] = { 0, 0, 0 }; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (cn[i][j] > 0) { num_color[i]++; num_total[i] += cn[i][j]; } } } for (int i = 0; i < 3; i++) { if (k <= num_total[i]) { ll cur = (k - 1) % num_color[i]; return choose(cn[i], cur); } k = k - num_total[i]; } return "RED"; } };
3、在可以移动一次的情况下,把所有的方格看成是重复出现的
#include <iostream> #include <string> #include <vector> #include <cstdlib> #include <map> #include <algorithm> #include <stack> #include <queue> #include <cmath> using namespace std; typedef long long ll; int dx[4] = { -1, -1, 1, 1 }; int dy[4] = { -1, 1, -1, 1 }; int n, W, H, A, B; bool vis[1100][1100]; long long dfs(int x, int y) { if (x < 0 || x >= n || x >= W || y < 0 || y >= n || y >= H) return 0; if (vis[x][y]) return 0; vis[x][y] = true; ll res = W / n + (x + 1 <= W % n); res *= H / n + (y + 1 <= H % n); for (int i = 0; i < 4; i++) res = res + dfs(x + dx[i] * A, y + dy[i] * B) + dfs(x + dx[i] * B, y + dy[i] * A); return res; } class KnightCircuit { public: long long maxSize(int w, int h, int a, int b) { if ((a >= w && b >= w) || (a >= h && b >= h))//保证可以移动一次 return 1; A = a, B = b, n = 2 * a * b, W = w, H = h; ll ans = 0, res; for (int i = 0; i < n && i < W; i++) for (int j = 0; j < n && j < H; j++) if (!vis[i][j]) { res = dfs(i, j); ans = max(res, ans); } return ans; } };
DIV1-2、算法很巧妙,
http://blog.csdn.net/cyberzhg/article/details/8288425
#include <iostream> #include <string> #include <vector> #include <cstdlib> #include <map> #include <algorithm> #include <stack> #include <queue> #include <cmath> using namespace std; typedef long long ll; class AlternateColors2 { public: long long countWays(int n, int k) { long long ans = 0; if ((k - 1) % 3 == 0) {//假设后边r、g、b都有 int remain = n - k; ans += (long long) (remain + 2) * (remain + 1) / 2; } for (int i = 0; i * 3 < (k - 1); ++i) { int remain = k - 1 - i * 3; ans += remain ;//后边如果只有r if (remain % 2 == 0) {//后边如果有b或者g ans += n - k + 1; ans += n - k + 1; } } return ans; } };
相关文章推荐
- SRM 564 div1
- SRM 549 DIV2
- SRM 452 DIV2 Problems 1000
- SRM 555 DIV2
- Topcoder SRM 597 DIV 1
- TopCoder SRM 681 Div. 2 Problem 500 - ExplodingRobots (枚举)
- SRM 578 div1
- SRM574 Div1 450
- TC SRM 636 Div2 C ChocolateDividingHard 二分
- SRM 604 DIV2 250
- TOPCODER/SRM 566 DIVII(250、500、1000题)(1000PT暂未附上代码)
- [TC SRM 571] DIV1 1000
- Topcoder SRM 687 (Div 2) 500.Quacking __ string matches
- topcoder srm 690 div1 -3
- Topcoder SRM 687 div2
- TopCoder SRM 144 DIV1 550 Lottery
- 数学 SRM 690 Div1 WolfCardGame 300
- srm575_div1&2_1000(网络流)
- [LP对偶费用流] SRM 676 div1 Farmville
- TopCoder SRM 663 Div2 Problem 1000 - CheeseRolling (状压dp)