結果
| 問題 |
No.401 数字の渦巻き
|
| コンテスト | |
| ユーザー |
LogicR_piman
|
| 提出日時 | 2016-09-26 03:29:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,188 bytes |
| コンパイル時間 | 687 ms |
| コンパイル使用メモリ | 61,668 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-18 15:04:27 |
| 合計ジャッジ時間 | 1,358 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include<iostream>
#include<string>
using namespace std;
/*void replace(string *s, int i, int x, int y) {
int d, e ;
string ii;
ii = to_string(i);
d = i / 10 + 1;
e = y * (n * 4 + 1) + x * 4;
s.replace(e, d, i);
}*/
int main() {
int n, nn, i, j, k, x = 0, y = 0, d=0, e=0, f=0;
string s, ii;
cin >> n;
nn = n*n;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n * 4; j++) {
s.insert(0, "0");
}
s.insert(0, "\n");
}
for (j = 0; j < n * 4; j++) {
s.insert(0, "0");
}
//cout << s << endl;
for (i = 1; i <= 3 * n - 2; i++) {
if (i == 1) {
x = 0;
y = 0;
}
else if (i <= n) {
x += 1;
y = 0;
}
else if (i <= 2 * n - 1) {
y += 1;
}
else if (i <= 3 * n - 2) {
x -= 1;
}
if (i <= 3 * n - 2) {
if (i < 10) d = 2;
else if (i < 100) d = 3;
else d = 4;
e = y * (n * 4 + 1) + x * 4 - d + 4;
ii = to_string(i);
ii += " ";
s.replace(e, d, ii);
}
}
while(1){
if (i > 3 * n - 2) {
for (k = 0; k < n - 2 - f; k++) {
y -= 1;
if (i < 10) d = 2;
else if (i < 100) d = 3;
else d = 4;
e = y * (n * 4 + 1) + x * 4 - d + 4;
ii = to_string(i);
ii += " ";
//cout << i << x << y << endl;
s.replace(e, d, ii);
i++;
}
if (i > nn) break;
for (k = 0; k < n - 2 - f; k++) {
x += 1;
if (i < 10) d = 2;
else if (i < 100) d = 3;
else d = 4;
e = y * (n * 4 + 1) + x * 4 - d + 4;
ii = to_string(i);
ii += " ";
//cout << i << x << y << endl;
s.replace(e, d, ii);
i++;
}
if (i > nn) break;
for (k = 0; k < n - 3 - f; k++) {
y += 1;
if (i < 10) d = 2;
else if (i < 100) d = 3;
else d = 4;
e = y * (n * 4 + 1) + x * 4 - d + 4;
ii = to_string(i);
ii += " ";
//cout << i << x << y << endl;
s.replace(e, d, ii);
i++;
}
if (i > nn) break;
for (k = 0; k < n - 3 - f; k++) {
x -= 1;
if (i < 10) d = 2;
else if (i < 100) d = 3;
else d = 4;
e = y * (n * 4 + 1) + x * 4 - d + 4;
ii = to_string(i);
ii += " ";
//cout << i << x << y << endl;
s.replace(e, d, ii);
i++;
}
if (i > nn) break;
f += 2;
}
}
cout << s << endl;
return 0;
}
LogicR_piman