fashon-show.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <vector>
  4. #define MAXN 100
  5. using namespace std;
  6. int n;
  7. bool row[MAXN], col[MAXN], diag1[MAXN * 2 - 1], diag2[MAXN * 2 - 1];
  8. int crossSol[MAXN][MAXN], plusSol[MAXN][MAXN];
  9. void placeCrosses() {
  10. for(int i = 0; i < n; i++) {
  11. if(row[i]) continue;
  12. for(int j = 0; j < n; j++) {
  13. if(col[j]) continue;
  14. crossSol[i][j] = 1;
  15. col[j] = true;
  16. break;
  17. }
  18. }
  19. }
  20. int placePluses() {
  21. vector<int> ds;
  22. for(int i = 0; i < n - 1; i++) {
  23. ds.push_back(i);
  24. ds.push_back(n * 2 - i - 2);
  25. }
  26. ds.push_back(n - 1);
  27. int points = 0;
  28. for(int d: ds) {
  29. if(diag1[d]) { points++; continue; }
  30. int i = d < n ? d : n - 1;
  31. int j = d < n ? 0 : d - n + 1;
  32. for(; i >= 0 && j < n; i--, j++) {
  33. if(diag2[i - j + n - 1]) continue;
  34. plusSol[i][j] = 1;
  35. diag2[i - j + n - 1] = true;
  36. points++;
  37. break;
  38. }
  39. }
  40. return points;
  41. }
  42. int main() {
  43. int t; scanf("%d\n", &t);
  44. for(int tc = 1; tc <= t; tc++) {
  45. int m; scanf("%d %d\n", &n, &m);
  46. memset(row, 0, sizeof(row));
  47. memset(col, 0, sizeof(col));
  48. memset(diag1, 0, sizeof(diag1));
  49. memset(diag2, 0, sizeof(diag2));
  50. memset(crossSol, 0, sizeof(crossSol));
  51. memset(plusSol, 0, sizeof(plusSol));
  52. for(int i = 0; i < m; i++) {
  53. char ch; int r, c; scanf("%c %d %d\n", &ch, &r, &c);
  54. r--; c--;
  55. if(ch != '+') {
  56. crossSol[r][c] = -1;
  57. row[r] = col[c] = true;
  58. }
  59. if(ch != 'x') {
  60. plusSol[r][c] = -1;
  61. diag1[r + c] = diag2[r - c + n - 1] = true;
  62. }
  63. }
  64. placeCrosses();
  65. int plusPoints = placePluses();
  66. int pieces = 0;
  67. for(int i = 0; i < n; i++) {
  68. for(int j = 0; j < n; j++) {
  69. if(crossSol[i][j] > 0 || plusSol[i][j] > 0) pieces++;
  70. }
  71. }
  72. printf("Case #%d: %d %d\n", tc, n + plusPoints, pieces);
  73. for(int i = 0; i < n; i++) {
  74. for(int j = 0; j < n; j++) {
  75. if(crossSol[i][j] > 0 || plusSol[i][j] > 0) {
  76. char ch = crossSol[i][j] ? (plusSol[i][j] ? 'o' : 'x') : '+';
  77. printf("%c %d %d\n", ch, i + 1, j + 1);
  78. }
  79. }
  80. }
  81. }
  82. return 0;
  83. }