fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. bool mp[101][101] = {false};
  6. int dx[] = {1, 0, -1, 0};
  7. int dy[] = {0, -1, 0, 1};
  8.  
  9. bool isValid(int x, int y) {
  10. return x >= 0 && x <= 100 && y >= 0 && y <= 100;
  11. }
  12.  
  13. pair<int, int> turn(pair<int, int> o, pair<int, int>& p) {
  14. auto c = make_pair(p.first-o.first, p.second-o.second);
  15. return make_pair(o.first+c.second, o.second-c.first);
  16. }
  17.  
  18. void func(int x, int y, int d, int g) {
  19. vector<pair<int, int>> v;
  20. v.push_back({x, y});
  21. v.push_back({x+dx[d], y+dy[d]});
  22.  
  23. while(g--) {
  24. auto o = v.back();
  25. for(int i = v.size()-2; i >= 0; i--)
  26. v.push_back(turn(o, v[i]));
  27. }
  28.  
  29. for(auto& p : v) {
  30. if(isValid(p.first, p.second))
  31. mp[p.second][p.first] = true;
  32. }
  33. }
  34.  
  35. int check() {
  36. int result = 0;
  37. for(int y = 0; y < 100; y++) {
  38. for(int x = 0; x < 100; x++)
  39. if(mp[y][x] && mp[y+1][x] && mp[y][x+1] && mp[y+1][x+1])
  40. result++;
  41. }
  42. return result;
  43. }
  44.  
  45. int main() {
  46. int t;
  47. cin >> t;
  48. while(t--) {
  49. int x, y, d, g;
  50. cin >> x >> y >> d >> g;
  51. func(x, y, d, g);
  52. }
  53. cout << check();
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5360KB
stdin
4
3 3 0 1
4 2 1 3
4 2 2 1
2 7 3 4
stdout
14