Codeforces #252 (Div. 2) C. Valera and Tubes

Source: Internet
Author: User

A simple question

It may not be easy to read

Is to give n * m matrix, let you find k paths can fill the Matrix

Each path must have a minimum of 2 grids, and the grids on the path must be adjacent.

It's better to understand the meaning of the question. Just be greedy.

Before the K-1 step each take 2 lattice, the last finish the rest of the grid can be

The Code is as follows:

#include <cstdio>#include <iostream>#include <algorithm>#define MAXN 100010#define ll long longusing namespace std;int n, m, k, cnt, col, row;int x[MAXN], y[MAXN];int main(void) {    while(cin >> n >> m >> k) {        cnt = 1;        x[1] = 1; row = 1;        y[1] = 1; col = 1;        while(cnt <= n*m) {                        cnt++;                        if((col==m&&row%2) || (col==1&&row%2==0)) {                row++;                x[cnt] = row;                y[cnt] = col;            }            else {                if(row % 2) {                    col++;                }                else {                    col--;                }                x[cnt] = row;                y[cnt] = col;            }        }        /*        cout << cnt << endl;        for(int i=1; i<cnt; ++i) {            cout << x[i] << " " << y[i] << endl;        }        */        int j = 1;        for(int i=1; i<k; ++i) {            cout << "2 " << x[j] << " " << y[j] << " ";            ++j;            cout << x[j] << " " << y[j] << endl;            ++j;        }                cout << cnt-j << " ";        for(int i=j; i<cnt-1; ++i) {            cout << x[i] << " " << y[i] << " ";        }        cout << x[cnt-1] << " " << y[cnt-1] << endl;            }    return 0;}

Now again, I think codeforces's 3rd question is not that difficult.

I want to locate myself again later

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.