Kaidul

Untitled

Jun 1st, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.15 KB | None | 0 0
  1. //  Created by Kaidul Islam on 7/02/2017.
  2. //  Copyright © 2017 Kaidul Islam. All rights reserved.
  3. //
  4. //
  5. #include <algorithm>
  6. #include <array>
  7. #include <bitset>
  8. #include <cassert>
  9. #include <cctype>
  10. #include <climits>
  11. #include <cmath>
  12. #include <cstdio>
  13. #include <cstdlib>
  14. #include <cstring>
  15. #include <ctime>
  16. #include <deque>
  17. #include <iomanip>
  18. #include <iostream>
  19. #include <limits>
  20. #include <list>
  21. #include <map>
  22. #include <memory>
  23. #include <numeric>
  24. #include <queue>
  25. #include <set>
  26. #include <sstream>
  27. #include <stack>
  28. #include <string>
  29. #include <unordered_map>
  30. #include <unordered_set>
  31. #include <utility>
  32. #include <vector>
  33.  
  34. using namespace std;
  35.  
  36. #define rep(i, n) for(__typeof(n) i = 0; i < (n); i++)
  37. #define rrep(i, n) for(__typeof(n) i = (n) - 1; i >= 0; --i)
  38. #define rep1(i, n) for(__typeof(n) i = 1; i <= (n); i++)
  39. #define FOR(i, a, b) for(__typeof(b) i = (a); i <= (b); i++)
  40. #define forstl(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
  41. #define SIZE(v) ((int)v.size())
  42. #define INF (1 << 30)
  43. #define PI acos(-1.0)
  44. #define bitcnt __builtin_popcount
  45. #define pb push_back
  46. #define ppb pop_back
  47. #define all(x) x.begin(), x.end()
  48. #define mem(x, y) memset(x, y, sizeof x)
  49. #define eps 1e-9
  50. #define pii pair<int, int>
  51. #define couple make_pair
  52. #define X first
  53. #define Y second
  54. #define vi vector<int>
  55. #define vpii vector< pii >
  56. #define si set<int>
  57. #define SDc(x) sf("%c", &x)
  58. #define SDi(x) sf("%d", &x)
  59. #define SD2(x, y) sf("%d %d", &x, &y)
  60. #define SD3(x, y, z) sf("%d %d %d", &x, &y, &z)
  61. #define SDs(x) sf("%s", x)
  62. #define pf printf
  63. #define print(x) pf("%d ", x)
  64. #define println(x) pf("%d\n", x)
  65. #define output(x, y); pf("Case %d: %d", ++x, y)
  66. #define newLine pf("\n")
  67. #define sf scanf
  68. #define READ(f) freopen(f, "r", stdin)
  69. #define WRITE(f) freopen(f, "w", stdout)
  70. #if ( _WIN32 or __WIN32__ )
  71. #define LLD "%I64d"
  72. #else
  73. #define LLD "%lld"
  74. #endif
  75. #define SDl(x) sf(LLD, &x)
  76. #define MAX5 100001
  77. #define MAX7 10000001
  78. #define MAX9 1000000000
  79. #define MOD9 (MAX9 + 7)
  80. typedef long long i64;
  81. typedef unsigned long long ui64;
  82. const i64 INF64 = (i64) 1E18;
  83.  
  84. template<typename T> string toStr(T n) { ostringstream oss; oss << n; oss.flush(); return oss.str(); }
  85. template<typename T> T toInt(string s) { T n = 0; istringstream sin(s); sin >> n; return n; }
  86.  
  87. class TimeTracker {
  88.     clock_t start, end;
  89. public:
  90.     TimeTracker() {
  91.         start = clock();
  92.     }
  93.     ~TimeTracker() {
  94.         end = clock();
  95.         fprintf(stderr, "%.3lf s\n", (double)(end - start) / CLOCKS_PER_SEC);
  96.     }
  97. };
  98.  
  99. struct Point {
  100.     int x, y;
  101.     Point(): x(0), y(0) {}
  102.     Point(int a, int b): x(a), y(b) {}
  103.     bool operator < (const Point& other) const {
  104.         return x < other.x;
  105.     }
  106. };
  107. // BitMask
  108. int Set(int N, int pos) {
  109.     return N |= (1 << pos);
  110. }
  111. int Reset(int N, int pos) {
  112.     return N &= ~(1 << pos);
  113. }
  114. int Check(int N, int pos) {
  115.     return (N & (1 << pos));
  116. }
  117. int toggle(int N, int pos) {
  118.     return N ^= (1 << pos);
  119. }
  120.  
  121. // direction array
  122. //int dx[] = {0, -1, 0, 1};
  123. //int dy[] = {-1, 0, 1, 0};
  124. //int Dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
  125. //int Dy[] = {-1, -1, 0, 1, 1, 1, 0, -1};
  126. //int _row, _col;
  127. //inline bool isValid(int i, int j) {
  128. //    return i >= 0 and j >= 0 and i < _row and j < _col;
  129. //}
  130.  
  131. #define MOD (MAX9 + 7)
  132.  
  133. inline void IncMod(int &x, int y) {
  134.     x += y;
  135.     if (x >= MOD) {
  136.         x -= MOD;
  137.     }
  138. }
  139.  
  140. #define keyType int
  141. class Compare {
  142. public:
  143.     bool operator() (keyType& lhs, keyType& rhs) const {
  144.         return lhs > rhs;
  145.     }
  146. } compare;
  147. // e.g. sort(all(arr), compare)
  148.  
  149.  
  150. #define error(args...) { vector<string> _v; split(#args, ',', _v); err(_v.begin(), args); }
  151.  
  152. void split(const string& s, char c, vector<string>& result) {
  153.     stringstream ss(s);
  154.     string x;
  155.     while (getline(ss, x, c))
  156.         result.push_back(x);
  157. }
  158.  
  159. void err(vector<string>::iterator it) {}
  160. template<typename T, typename... Args>
  161. void err(vector<string>::iterator it, T a, Args... args) {
  162.     cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
  163.     err(++it, args...);
  164. }
  165.  
  166. /*
  167.  error(a, b, c)
  168.  output:
  169.  a = 4
  170.  b = 8
  171.  c = 9
  172.  */
  173.  
  174. /** Implementation **/
  175.  
  176. #define MAX MAX5
  177. int n;
  178. char grid[2][MAX];
  179.  
  180. int main(int argc, const char * argv[]) {
  181.     int tcase;
  182.     SDi(tcase);
  183.     while(tcase--) {
  184.         SDi(n);
  185.         getc(stdin);
  186.         rep(i, 2) {
  187.             rep(j, n) {
  188.                 SDc(grid[i][j]);
  189.             }
  190.             getc(stdin);
  191.         }
  192.         int count = 0;
  193.         int top = 0, bottom = 0;
  194.         rep(i, n) {
  195.             top += (grid[0][i] == '*');
  196.             bottom += (grid[1][i] == '*');
  197.         }
  198.         if(top > 0 and bottom > 0) {
  199.             count++;
  200.         }
  201.         bool r1 = true, r2 = true;
  202.         rep(i, n) {
  203.             if((grid[0][i] == '*' and !r1) or (grid[1][i] == '*' and !r2)) {
  204.                 count++;
  205.                 r1 = !(grid[0][i] == '*');
  206.                 r2 = !(grid[1][i] == '*');
  207.             } else {
  208.                 r1 = !((grid[0][i] == '*') or !r1);
  209.                 r2 = !((grid[1][i] == '*') or !r2);
  210.             }
  211.         }
  212.         println(count);
  213.     }
  214.     return 0;
  215. }
Advertisement
Add Comment
Please, Sign In to add comment