結果
問題 |
No.455 冬の大三角
|
ユーザー |
![]() |
提出日時 | 2018-09-18 10:54:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,106 bytes |
コンパイル時間 | 1,006 ms |
コンパイル使用メモリ | 108,260 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-18 07:55:05 |
合計ジャッジ時間 | 2,853 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 WA * 2 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:242:31: warning: 'y3' may be used uninitialized [-Wmaybe-uninitialized] 242 | if (i == y3 && j == x3) { | ~~^~~~~ main.cpp:222:17: note: 'y3' was declared here 222 | int x3, y3; | ^~ main.cpp:242:42: warning: 'x3' may be used uninitialized [-Wmaybe-uninitialized] 242 | if (i == y3 && j == x3) { | ~~^~~~~ main.cpp:222:13: note: 'x3' was declared here 222 | int x3, y3; | ^~ main.cpp:89:44: warning: 'y2' may be used uninitialized [-Wmaybe-uninitialized] 89 | for (i = y2 - 1; i >= 0; i--) { | ~~^~~~ main.cpp:31:25: note: 'y2' was declared here 31 | int x1, y1, x2, y2; | ^~ main.cpp:88:32: warning: 'x2' may be used uninitialized [-Wmaybe-uninitialized] 88 | double xx = x2; | ^~ main.cpp:31:21: note: 'x2' was declared here 31 | int x1, y1, x2, y2; | ^~ main.cpp:76:33: warning: 'y1' may be used uninitialized [-Wmaybe-uninitialized] 76 | if (i == y1) { | ^~ main.cpp:31:17: note: 'y1' was declared here 31 | int x1, y1, x2, y2; | ^~ main.cpp:66:33: warning: 'x1' may be used uninitialized [-Wmaybe-uninitialized] 66 | if (j == x1) { | ^~ main.cpp:31:13: note: 'x1' was declared here 31 | int x1, y1, x2, y2; | ^~
ソースコード
#include <stdio.h> #include <algorithm> #include <iostream> #include <string> #include <vector> #include <functional> #include <map> #include <iomanip> #include <math.h> #include <stack> #include <queue> #include <bitset> #include <cstdlib> #include <tuple> #include <cctype> #include <ctype.h> #include <set> #include <sstream> using namespace std; int main() { int i, j; int h, w; vector<string>s; double dx, dy; vector<vector<bool>>mat(105, vector<bool>(105, false)); cin >> h >> w; int x1, y1, x2, y2; for (i = 0; i < h; i++) { string str; cin >> str; s.push_back(str); } bool flag = false; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (s[i][j] == '*') { if (flag == false) { x1 = j; y1 = i; flag = true; } else { x2 = j; y2 = i; break; } } } } mat[y1][x1] = true; mat[y2][x2] = true; if (x1 == x2) { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (j == x1) { mat[i][j] = true; } } } } else if (y1 == y2) { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (i == y1) { mat[i][j] = true; } } } } else if (x2 > x1) { dx = (double)(x2 - x1) / (double)abs(y2 - y1); if (y2 > y1) { double xx = x2; for (i = y2 - 1; i >= 0; i--) { xx += dx; int dox = floor(xx); int upx = ceil(xx); if (upx >= w) break; mat[i][dox] = true; mat[i][upx] = true; } for (i = y2 + 1; i < y1; i++) { xx -= dx; int dox = floor(xx); int upx = ceil(xx); if (dox < 0) break; mat[i][dox] = true; mat[i][upx] = true; } for (i = y1 + 1; i < h; i++) { xx -= dx; int dox = floor(xx); int upx = ceil(xx); if (dox < 0) break; mat[i][dox] = true; mat[i][upx] = true; } } else if (y2 < y1) { //右下がり直線 double xx = x2; for (i = y1 - 1; i >= 0; i--) { xx -= dx; int dox = floor(xx); int upx = ceil(xx); if (dox < 0) break; mat[i][dox] = true; mat[i][upx] = true; } for (i = y1 + 1; i < y2; i++) { xx += dx; int dox = floor(xx); int upx = ceil(xx); if (upx >= w) break; mat[i][dox] = true; mat[i][upx] = true; } for (i = y2 + 1; i < h; i++) { xx += dx; int dox = floor(xx); int upx = ceil(xx); if (upx >= w) break; mat[i][dox] = true; mat[i][upx] = true; } } } else if (x2 < x1) { dx = (double)(x1 - x2) / (double)abs(y1 - y2); if (y2 > y1) { double xx = x2; for (i = y2 - 1; i >= 0; i--) { xx -= dx; int dox = floor(xx); int upx = ceil(xx); if (dox < 0) break; mat[i][dox] = true; mat[i][upx] = true; } for (i = y2 + 1; i < y1; i++) { xx += dx; int dox = floor(xx); int upx = ceil(xx); if (upx >= w) break; mat[i][dox] = true; mat[i][upx] = true; } for (i = y1 + 1; i < h; i++) { xx += dx; int dox = floor(xx); int upx = ceil(xx); if (upx >= w) break; mat[i][dox] = true; mat[i][upx] = true; } } else if (y2 < y1) { //右上がり直線 double xx = x2; for (i = y1 - 1; i >= 0; i--) { xx += dx; int dox = floor(xx); int upx = ceil(xx); if (upx >= w) break; mat[i][dox] = true; mat[i][upx] = true; } for (i = y1 + 1; i < y2; i++) { xx -= dx; int dox = floor(xx); int upx = ceil(xx); if (dox < 0) break; mat[i][dox] = true; mat[i][upx] = true; } for (i = y2 + 1; i < h; i++) { xx -= dx; int dox = floor(xx); int upx = ceil(xx); if (dox < 0) break; mat[i][dox] = true; mat[i][upx] = true; } } } int x3, y3; bool flag2 = false; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (mat[i][j] == false) { x3 = j; y3 = i; flag2 = true; break; } } if (flag2 == true) break; } cout << endl; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (i == y3 && j == x3) { cout << "*"; continue; } else { cout << s[i][j]; } } cout << endl; } getchar(); getchar(); return 0; }