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

来源:互联网 发布:怎样手机网络理财投资 编辑:程序博客网 时间:2024/06/05 10:10
ACM ICPC 2008–2009, NEERC, Northern Subregional ContestSt Petersburg, November 1, 2008Problem C. ClassInput file: class.inOutput file: class.outTime limit: 3 secondsMemory limit: 256 megabytesDr. Strange is a really strange lecturer. Each lecture he calculates class fullness and if it is small, hedecreases 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 themaximum number of students in a single column and the row fullness is the maximum number of studentsin a single row.For example there are 16 students shown on the left picture (occupied desks are darkened). The rowfullness of this arrangement is 5 (the 4-th row) and the column fullness is 3 (the 1-st, the 3-rd, the 5-th orthe 6-th columns). So, the class fullness is 3. But if the students rearrange as shown on the right picturethen the column fullness will become 4 (the 5-th column), and so the class fullness will also become 4.12341234561234123456The students of Dr. Strange need to know the arrangement that maximizes class fullness so they askyou to write a program that calculates it for them.InputThe first line of the input file contains three integer numbers: n, r and c — number of students, rowsand columns in the class (1 ≤ r, c ≤ 100, 1 ≤ n ≤ r × c).OutputThe first line of the output file must contain a single integer number — the maximum possible classfullness.The following r lines must contain the optimal student arrangement. Each line must contain a descriptionof a single row. Row description is a line of c characters either ‘‘.’’ or ‘‘#’’, where ‘‘.’’ denotes an emptydesk, and ‘‘#’’ denotes an occupied one. If there are multiple optimal arrangements, output any one.Exampleclass.in class.out16 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
原创粉丝点击