Class(ACM ICPC 2008–2009, NEERC, Northern Subregional Contest)

ACM ICPC 2008–2009, NEERC, Northern Subregional Contest
St Petersburg, November 1, 2008
Problem C. Class
Input file: class.in
Output file: class.out
Time limit: 3 seconds
Memory limit: 256 megabytes
Dr. Strange is a really strange lecturer. Each lecture he calculates class fullness and if it is small, he
decreases all semester grades by one. So the students want to maximize the class fullness.
The class fullness is the minimum of row fullness and column fullness. The column fullness is the
maximum number of students in a single column and the row fullness is the maximum number of students
in a single row.
For example there are 16 students shown on the left picture (occupied desks are darkened). The row
fullness of this arrangement is 5 (the 4-th row) and the column fullness is 3 (the 1-st, the 3-rd, the 5-th or
the 6-th columns). So, the class fullness is 3. But if the students rearrange as shown on the right picture
then the column fullness will become 4 (the 5-th column), and so the class fullness will also become 4.
1
2
3
4
1
2
3
4
5
6
1
2
3
4
1
2
3
4
5
6
The students of Dr. Strange need to know the arrangement that maximizes class fullness so they ask
you to write a program that calculates it for them.
Input
The first line of the input file contains three integer numbers: n, r and c — number of students, rows
and columns in the class (1 ≤ r, c ≤ 100, 1 ≤ n ≤ r × c).
Output
The first line of the output file must contain a single integer number — the maximum possible class
fullness.
The following r lines must contain the optimal student arrangement. Each line must contain a description
of a single row. Row description is a line of c characters either ‘‘.’’ or ‘‘#’’, where ‘‘.’’ denotes an empty
desk, and ‘‘#’’ denotes an occupied one. If there are multiple optimal arrangements, output any one.
Example
class.in class.out
16 4 6 4
.####.
#..###
#...##
###.##

//
//  main.cpp
//  160929
//
//  Created by liuzhe on 17/3/30.
//  Copyright © 2016年 my_code. All rights reserved.
//
//#include <bits/stdc++.h>

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <bitset>
#include <stack>
using namespace std;
char s[105][105];
int main( )
{
    freopen("class.in","r",stdin);
    freopen("class.out","w",stdout);
    
    int n,m,a;
    while(cin>>a>>n>>m)
    {
        int t = min(n,m);
        int x = (a+1)>>1;
        t = min(t,x);
        cout<<t<<endl;
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                s[i][j] = '.';
        for(int i=0,j=0;j<m&&j<t;j++)
        {
            if(a)
            {
                s[i][j] = '#';
                a--;
            }
        }
        if(a)
        {
            for(int j=0,i=0;i<n;i++)
            {
                if(a)
                {
                    if(s[i][j]!='#')
                    {
                        s[i][j] = '#';
                        a--;
                    }
                }
            }
        }
            for(int i=0;i<n;i++)
                for(int j=0;j<m;j++)
                {
                    if(a&&s[i][j]!='#')
                    {
                        a--;
                        s[i][j]='#';
                    }
                }
        for(int i=0;i<n;i++)
            cout<<s[i]<<endl;
        
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值