Блог пользователя Blackness

Автор Blackness, история, 7 лет назад, По-английски

I am having difficulty solving a problem on a different coding website. The problem goes like this:

The m × n rectangular grid is a graph whose vertices correspond to the points in the plane with x-coordinates being integers in the range 0, … , n-1 and y-coordinates being integers in the range 0, … , m-1, and two vertices are joined by an edge whenever the corresponding points are at unit distance apart. For example, a 4 × 6 rectangular grid is shown in Figure 1. The grid has n vertices appearing in each of m rows and m vertices in each of n columns. The vertex in row i and column j is denoted by (i, j), where 0 ≤ i ≤ m — 1 and 0 ≤ j ≤ n — 1.

If we add an edge joining two vertices (i, 0) and (i, n-1) of the m × n rectangular grid for every row i ∈ {0, … , m-1} and moreover, add an edge between two vertices (0, j) and (m-1, j) for every column j ∈ {0, … , n-1}, then each row forms a cycle of length n and each column forms a cycle of length m, as illustrated in Figure 2. The resulting graph is often called an m × n toroidal grid, because it can be drawn on a torus without edge crossings.

Given an m × n toroidal grid, you are to write a program to find a cycle that visits every vertex exactly once. Here, the required cycle may be represented as a sequence, (v1, v2, … , vmn), of mn distinct vertices of the graph such that vk and vk+1 are adjacent for all k ∈ {1, … , mn-1} and moreover, vmn and v1 are adjacent.

I got a compile error my code:


#include<stdio.h> int main() { int t; scanf("%d", &t); while(t--){ int r, c; scanf("%d %d", &r, &c); printf("1\n"); for(int i=0; i=1; j--){ printf("(%d,%d)\n", i, j); } }else{ for(int j=1; j=1; i--){ printf("(%d,0)\n", i, 0); } } }

What was wrong?

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Please write your code using the "Block" format or provide a link to your code. What you copy and paste would look slightly different and therefore be difficult to tell what went wrong.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Blackness (previous revision, new revision, compare).

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    can you add

    ~~~~

    before and after your code?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    your j is not declared in for(int i=0; i=1; j--){, sure it wont compile. you should declare int j; before that. though your code makes no sense to me still

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

After the for loop there is an else statement with no pairing if.