diff --git a/GESP/SheXingJuZhen.cpp b/GESP/SheXingJuZhen.cpp new file mode 100644 index 0000000..4564fb7 --- /dev/null +++ b/GESP/SheXingJuZhen.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +const int N = 110; +int dx[] = {0, 1, 0, -1}; // 右下左上 +int dy[] = {1, 0, -1, 0}; // 右下左上 +int a[N][N]; +int x, y, p; // x,y:当前蛇走到的坐标位置;p:现在正在使用哪个方向 +int n, m; + +int main() { + cin >> n >> m; + for (int k = 1; k <= n * m; k++) { // 没有填充完毕 + a[x][y] = k; // 在当前位置填充数字, 值在长大 + // p是说方向数组中的游标,它是需要变化的,什么情况下变化呢? + // 1、出界了就变化 2、遇到了障碍就变化 + int tx = x + dx[p], ty = y + dy[p]; // 蛇准备去的位置 + if (tx >= n || ty >= m || tx < 0 || ty < 0 || a[tx][ty]) + p = (p + 1) % 4; // 换下个方向(本题比较容易,因为在没有填充完时,每次碰壁只需换下个方向就一定有可以走的路) + + // 下一个坐标位置 : 注意:下面的代码不能用 x=tx,y=ty!!! 原因是经过上面的转换,p可能变化了!!! + x += dx[p], y += dy[p]; + } + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) + printf("%3d", a[i][j]); + cout << endl; + } + + return 0; +} \ No newline at end of file diff --git a/GESP/Test.cpp b/GESP/Test.cpp deleted file mode 100644 index ed0b98d..0000000 --- a/GESP/Test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -using namespace std; -const int N = 110; -int dx[] = {0, 1, 0, -1}; // 右下左上 -int dy[] = {1, 0, -1, 0}; // 右下左上 -int a[N][N]; - -int main() { - int n = 5, m = n * n; - - int idx = 1; - int x = 0, y = 0, p = 0; - while (idx <= m) { - a[x][y] = idx; // - idx++; // 值在长大 - // p是说方向数组中的游标,它是需要变化的,什么情况下变化呢? - // 1、出界了就变化 - if (x + dx[p] >= n || y + dy[p] >= n || a[x + dx[p]][y + dy[p]]) - p = (p + 1) % 4; - - // 下一个坐标位置 - x += dx[p], y += dy[p]; - } - - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) - printf("%3d", a[i][j]); - cout << endl; - } - - return 0; -} \ No newline at end of file diff --git a/jetbra/vmoptions/appcode.vmoptions b/jetbra/vmoptions/appcode.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/appcode.vmoptions +++ b/jetbra/vmoptions/appcode.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/clion.vmoptions b/jetbra/vmoptions/clion.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/clion.vmoptions +++ b/jetbra/vmoptions/clion.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/datagrip.vmoptions b/jetbra/vmoptions/datagrip.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/datagrip.vmoptions +++ b/jetbra/vmoptions/datagrip.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/dataspell.vmoptions b/jetbra/vmoptions/dataspell.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/dataspell.vmoptions +++ b/jetbra/vmoptions/dataspell.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/devecostudio.vmoptions b/jetbra/vmoptions/devecostudio.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/devecostudio.vmoptions +++ b/jetbra/vmoptions/devecostudio.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/gateway.vmoptions b/jetbra/vmoptions/gateway.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/gateway.vmoptions +++ b/jetbra/vmoptions/gateway.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/goland.vmoptions b/jetbra/vmoptions/goland.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/goland.vmoptions +++ b/jetbra/vmoptions/goland.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/idea.vmoptions b/jetbra/vmoptions/idea.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/idea.vmoptions +++ b/jetbra/vmoptions/idea.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/jetbrains_client.vmoptions b/jetbra/vmoptions/jetbrains_client.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/jetbrains_client.vmoptions +++ b/jetbra/vmoptions/jetbrains_client.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/jetbrainsclient.vmoptions b/jetbra/vmoptions/jetbrainsclient.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/jetbrainsclient.vmoptions +++ b/jetbra/vmoptions/jetbrainsclient.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/phpstorm.vmoptions b/jetbra/vmoptions/phpstorm.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/phpstorm.vmoptions +++ b/jetbra/vmoptions/phpstorm.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/pycharm.vmoptions b/jetbra/vmoptions/pycharm.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/pycharm.vmoptions +++ b/jetbra/vmoptions/pycharm.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/rider.vmoptions b/jetbra/vmoptions/rider.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/rider.vmoptions +++ b/jetbra/vmoptions/rider.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/rubymine.vmoptions b/jetbra/vmoptions/rubymine.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/rubymine.vmoptions +++ b/jetbra/vmoptions/rubymine.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/studio.vmoptions b/jetbra/vmoptions/studio.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/studio.vmoptions +++ b/jetbra/vmoptions/studio.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/webide.vmoptions b/jetbra/vmoptions/webide.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/webide.vmoptions +++ b/jetbra/vmoptions/webide.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file diff --git a/jetbra/vmoptions/webstorm.vmoptions b/jetbra/vmoptions/webstorm.vmoptions index 5724f9e..32beca5 100644 --- a/jetbra/vmoptions/webstorm.vmoptions +++ b/jetbra/vmoptions/webstorm.vmoptions @@ -19,4 +19,3 @@ --add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED --add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED --javaagent:D:\python\jetbra\ja-netfilter.jar=jetbrains \ No newline at end of file