Codeforces Round #252 (Div. 2), problem: (C) Valera and Tubes 【模拟】

题意

在 n * m 的表格里放下k个管子
注意每个管子长度至少为2
一定要铺满

思路

只要填满格子,并且要求每个管子最少占据两个格子。那么只要k-1个管子每个管子占据两个格子,剩下的一个管子占据剩下的所有格子。这样得到的一定是正解当中的一个解。

code

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int n,m,k;
int main(){
    cin>>n>>m>>k;
    int x=1,y=1;
    bool flag=false;
    for(int i=0;i<k-1;i++){
        cout<<2;
        for(int j=0;j<2;j++){
            if(!flag)
                cout<<" "<<x<<" "<<y++;
            else
                cout<<" "<<x<<" "<<y--;
            if(y>m){
                y=m;
                x++;
                flag=!flag;
            }
            if(y<1){
                y=1;
                x++;
                flag=!flag;
            }
        }
        cout<<endl;
    }
    cout<<n*m-(k-1)*2;
    while(x<=n){
        if(!flag)
            cout<<" "<<x<<" "<<y++;
        else
            cout<<" "<<x<<" "<<y--;
        if(y>m){
            y=m;
            x++;
            flag=!flag;
        }
        if(y<1){
            y=1;
            x++;
            flag=!flag;
        }
    }
    cout<<endl;
    return 0;
}
学如逆水行舟,不进则退
发布了418 篇原创文章 · 获赞 980 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/weixin_42429718/article/details/104112997