Problem Difficulty

Revision en2, by Blackness, 2017-07-31 09:04:02

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?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Blackness 2017-07-31 09:18:55 24
en2 English Blackness 2017-07-31 09:04:02 6
en1 English Blackness 2017-07-31 08:56:56 1831 Initial revision (published)