Blackness's blog

By Blackness, history, 7 years ago, In English

When codeforces first opened, how did it get so popular?

Full text and comments »

  • Vote: I like it
  • +10
  • Vote: I do not like it

By Blackness, history, 7 years ago, In English

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?

Full text and comments »

  • Vote: I like it
  • -9
  • Vote: I do not like it

By Blackness, history, 7 years ago, In English

Not trying to hustle here, but how and what does it mean to hack during a contest? Are you supposed to find a bug in a different person's code?

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it

By Blackness, history, 7 years ago, In English

Is it often for the Judge Queue to go wrong?

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By Blackness, history, 8 years ago, In English

I'd like to know if I'm allowed to get some hints on problems(previous ones from past contest). If possible, can I have some help on the problem:Sonya and Queries?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Blackness, history, 8 years ago, In English

I'm afraid oyu8201 is cheating, his code:#include <bits/stdc++.h>

define fr(a, init, end) for(int a = init; a < end; ++a)

define add_wedge(a, b, c) to[z] = b; ant[z] = adj[a]; adj[a] = z; cost[z] = c; z++

define add_edge(a, b) to[z] = b; ant[z] = adj[a]; adj[a] = z++

define fre(i, u) for(int i = adj[u]; i != -1; i = ant[i])

define sc(a) scanf("%d", &a)

define debug(x) cerr << ">>> " << #x << " = " << x << endl;

define dbg(x) if(1) cerr << ">>> " << x << endl;

define _ << " , " <<

define endl '\n'

using namespace std;

typedef long long ll; typedef pair<int, int> ii;

const int N = int(1e6);

int col[N]; int to[N], ant[N], adj[N], z;

void dfs(int u) { fre(i, u) { if(col[to[i]] == -1) { col[to[i]] = col[u] ^ 1; dfs(to[i]); } } } int main() { ios::sync_with_stdio(false);cin.tie(NULL);

memset(col, -1, sizeof col);
memset(adj, -1, sizeof adj);
z = 0;

int n;
cin >> n;

int a, b;
vector<ii> p;

fr(i, 0, n)
{
    cin >> a >> b;
    --a, --b;
    add_edge(a, b);
    add_edge(b, a);
    p.push_back({a, b});
}

fr(i, 0, 2 * n)
{
    add_edge(i, i + 1);
    add_edge(i + 1, i);
    ++i;
}

fr(i, 0, 2 * n)
{
    if(col[i] == -1)
    {
        col[i] = 0;
        dfs(i);
    }
}

fr(i, 0, n)
{
    cout << col[p[i].first] + 1 << ' ' << col[p[i].second] + 1 << endl;
}

return 0;

}

my code: #include <bits/stdc++.h>

define fr(a, init, end) for(int a = init; a < end; ++a)

define add_wedge(a, b, c) to[z] = b; ant[z] = adj[a]; adj[a] = z; cost[z] = c; z++

define add_edge(a, b) to[z] = b; ant[z] = adj[a]; adj[a] = z++

define fre(i, u) for(int i = adj[u]; i != -1; i = ant[i])

define sc(a) scanf("%d", &a)

define debug(x) cerr << ">>> " << #x << " = " << x << endl;

define dbg(x) if(1) cerr << ">>> " << x << endl;

define _ << " , " <<

define endl '\n'

using namespace std;

typedef long long ll; typedef pair<int, int> ii;

const int N = int(1e6);

int col[N]; int to[N], ant[N], adj[N], z;

void dfs(int u) { fre(i, u) { if(col[to[i]] == -1) { col[to[i]] = col[u] ^ 1; dfs(to[i]); } } } int main() { ios::sync_with_stdio(false);cin.tie(NULL);

memset(col, -1, sizeof col);
memset(adj, -1, sizeof adj);
z = 0;

int n;
cin >> n;

int a, b;
vector<ii> p;

fr(i, 0, n)
{
    cin >> a >> b;
    --a, --b;
    add_edge(a, b);
    add_edge(b, a);
    p.push_back({a, b});
}

fr(i, 0, 2 * n)
{
    add_edge(i, i + 1);
    add_edge(i + 1, i);
    ++i;
}

fr(i, 0, 2 * n)
{
    if(col[i] == -1)
    {
        col[i] = 0;
        dfs(i);
    }
}

fr(i, 0, n)
{
    cout << col[p[i].first] + 1 << ' ' << col[p[i].second] + 1 << endl;
}

return 0;

}

Full text and comments »

  • Vote: I like it
  • -42
  • Vote: I do not like it