【Codeforces 644A】Parliament of Berland

【链接】 我是链接,点我呀:)
【题意】

题意

【题解】

https://blog.csdn.net/V5ZSQ/article/details/70873661 看这个人的吧。

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 100;
const long long M = 15e6;

int n,a,b,ans[N+10][N+10];
int kk = 0;

int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> a >> b;
    if (n>a*b) {
        cout<<-1<<endl;
        return 0;
    }
    int cur = 0;
    if (b%2==1 || a==1){
        for (int i = 1;i <= a;i++)
            for (int j = 1;j <= b;j++){
                if (cur<n){
                    ans[i][j] = ++cur;
                }else ans[i][j] = 0;
            }
    }else{
        for (int i = 1;i <= a;i++){
            if (i%2==1){
                for (int j = 1;j <= b;j++){
                    if (cur<n){
                        ans[i][j] = ++cur;
                    }else ans[i][j] = 0;
                }
            }else{
                for (int j = b;j >= 1;j--){
                    if (cur<n){
                        ans[i][j] = ++cur;
                    }else ans[i][j] = 0;
                }
            }
        }
    }
    for (int i = 1;i <= a;i++){
        for (int j = 1;j <= b;j++){
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }
	return 0;
}

posted @ 2019-03-31 23:17  AWCXV  阅读(112)  评论(0编辑  收藏  举报