Codeforces Good Bye 2017 Div.2 908A,B
2018-02-20 17:25
295 查看
A. New Year and Counting Cards
Problem Statement
http://codeforces.com/contest/908/problem/AAnalysis
For letter, only vowel need to know the digit in the other side.For digit, only odd number need to know the letter in the other side.
Code
#include <iostream> #include <string> using namespace std; #define MAX 50 int main() { int cnt = 0; string s; cin >> s; for(int i = 0; i < s.length(); i++) { if('a' <= s.at(i) <= 'z') { if('a' == s.at(i)|| 'e' == s.at(i) || 'i' == s.at(i) || 'o' == s.at(i) || 'u' == s.at(i)) { cnt++; } } if('0' <= s.at(i) <= '9') { if('1' == s.at(i) || '3' == s.at(i) || '5' == s.at(i) || '7' == s.at(i) || '9' == s.at(i)) { cnt++; } } } cout << cnt; }
B. New Year and Buggy Bot
Problem Statement
http://codeforces.com/contest/908/problem/BAnalysis
(1) Bob forgot to actually assign the directions to digits, so there are 24 mapping relations between directions and digitsDirection | Digit |
---|---|
DOWN, UP, RIGHT, LEFT | 0, 1, 2, 3 |
DOWN, UP, RIGHT, LEFT | 0, 1, 3, 2 |
DOWN, UP, RIGHT, LEFT | 0, 2, 1, 3 |
DOWN, UP, RIGHT, LEFT | 0, 2, 3, 1 |
DOWN, UP, RIGHT, LEFT | 0, 3, 1, 2 |
DOWN, UP, RIGHT, LEFT | 0, 3, 2, 1 |
DOWN, UP, RIGHT, LEFT | 1, 0, 2, 3 |
DOWN, UP, RIGHT, LEFT | 1, 0, 3, 2 |
DOWN, UP, RIGHT, LEFT | 1, 2, 0, 3 |
DOWN, UP, RIGHT, LEFT | 1, 2, 3, 0 |
DOWN, UP, RIGHT, LEFT | 1, 3, 0, 2 |
DOWN, UP, RIGHT, LEFT | 1, 3, 2, 0 |
DOWN, UP, RIGHT, LEFT | 2, 0, 1, 3 |
DOWN, UP, RIGHT, LEFT | 2, 0, 3, 1 |
DOWN, UP, RIGHT, LEFT | 2, 1, 0, 3 |
DOWN, UP, RIGHT, LEFT | 2, 1, 3, 0 |
DOWN, UP, RIGHT, LEFT | 2, 3, 0, 1 |
DOWN, UP, RIGHT, LEFT | 2, 3, 1, 0 |
DOWN, UP, RIGHT, LEFT | 3, 0, 1, 2 |
DOWN, UP, RIGHT, LEFT | 3, 0, 2, 1 |
DOWN, UP, RIGHT, LEFT | 3, 1, 0, 2 |
DOWN, UP, RIGHT, LEFT | 3, 1, 2, 0 |
DOWN, UP, RIGHT, LEFT | 3, 2, 0, 1 |
DOWN, UP, RIGHT, LEFT | 3, 2, 1, 0 |
Code
#include <bits/stdc++.h> using namespace std; enum Dir{DOWN, UP, RIGHT, LEFT}; const int maxn = 50; char grid[maxn][maxn]; int n, m; // n for rows, m for columns int digit[4] = {0, 1, 2, 3}; int startX, startY, exitX, exitY; string instructions; int move() { int row = startX, col = startY; for (int i = 0; i < instructions.size(); ++i) { int d = instructions[i] - '0'; for (int j = 0; j < 4; ++j) { if (d == digit[j]) { if (j == DOWN) { row++; } if (j == UP) { row--; } if (j == RIGHT) { col++; } if (j == LEFT) { col--; } } if (row > n || row < 1 || col > m || col < 1) { return 0; } else if (grid[row][col] == 'E') { return 1; } else if (grid[row][col] == '#') { return 0; } } } return 0; } int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> grid[i][j]; if (grid[i][j] == 'S') { startX = i; startY = j; } else if (grid[i][j] == 'E') { exitX = i; exitY = j; } } } cin >> instructions; int res = 0; do { res += move(); } while (next_permutation(digit, digit + 4)); cout << res << endl; return 0; }
更多内容请关注微信公众号
相关文章推荐
- Codeforces Good Bye 2017 A - New Year and Counting Cards
- Codeforces Good Bye 2017 B - New Year and Buggy Bot
- Codeforces Good Bye 2017 908F F. New Year and Rainbow Roads
- Codeforces Good Bye 2017 C - New Year and Curling
- Codeforces Good Bye 2017: F. New Year and Rainbow Roads(模拟)
- Codeforces Good Bye 2017 908F - New Year and Rainbow Roads 贪心+模拟
- Codeforces Good Bye 2017 F - New Year and Rainbow Roads
- Codeforces Good Bye 2017
- [Codeforces]Good Bye 2017
- Codeforces Good Bye 2017
- Codeforces Good Bye 2017 B. New Year and Buggy Bot 枚举全排列、模拟
- Codeforces-Good Bye 2017 C. New Year and Curling(计算几何)
- Codeforces Good Bye 2017 C. New Year and Curling(模拟水题)
- Codeforces Good Bye 2017
- Codeforces-Good Bye 2017 B. New Year and Buggy Bot(模拟)
- Codeforces Good Bye 2017 C. New Year and Curling 几何、枚举
- Codeforces Good Bye 2017 - (A,B,C)
- Codeforces Good Bye 2017 D. New Year and Arbitrary Arrangement
- codeforces Good Bye 2017
- codeforces 336 Div.2 B. Hamming Distance Sum