intget_direction(pair<int, int> p1, pair<int, int> p2){ if (p1.first == p2.first){ // x 座標相同 if (p2.second > p1.second) return1; // p2 y 座標 > p1 y 座標,表示向北 elsereturn3; // p2 y 座標 < p1 y 座標,表示向南 } else{ // y 座標相同 if (p2.first > p1.first) return0; // p2 x 座標 > p1 x 座標,表示向東 elsereturn2; // p2 x 座標 < p1 x 座標,表示向西 } return-1; }
intmain(){ int n; cin >> n; vector <pair<int, int>> p; p.push_back({0, 0}); for (int i = 0; i < n; i++){ int x, y; cin >> x >> y; p.push_back({x, y}); } int left = 0, right = 0, u_turn = 0; for (int i = 1; i < n; i++){ int d1 = get_direction(p[i-1], p[i]); // 進入方向 int d2 = get_direction(p[i], p[i+1]); // 離開方向 int dir = (d2 - d1 + 4) % 4; // 判斷轉向 if (dir == 1) left++; elseif (dir == 3) right++; elseif (dir == 2) u_turn++; // 這邊不要寫成 else 了,因為還有 dir == 0 的情形 } cout << left << " " << right << " " << u_turn; return0; }
intmain(){ int n, m; cin >> n >> m; vector <vector<int>> a(n, vector<int>(m)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; vector <pair<int, int>> special; // 用 pair 容器表示點座標 for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ int x = a[i][j]; int sum = 0; // 枚舉曼哈頓距離小於等於 x 的點 // 用 max 跟 min 是防止超過邊界 // max(0, i - x) 代表最小不能小於第 0 列 // min(n - 1, i + x) 代表最大不能超過第 n-1 列 for (int p = max(0, i - x); p <= min(n - 1, i + x); p++){ int dp = x - abs(i - p); for (int q = max(0, j - dp); q <= min(m - 1, j + dp); q++){ sum += a[p][q]; } } if (sum % 10 == x){ special.emplace_back(i, j); } } } cout << special.size() << '\n'; for (auto [i, j] : special){ cout << i << " " << j << '\n'; } return0; }