Input file: class.in
Output file: class.out
Time limit: 3 seconds
Memory limit: 256 megabytes
Description
Dr. 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.
Input
The 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).
Output
The 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.
Sample Input
16 4 6
Sample Output
4
.####.
#..###
#...##
###.##
题解:因为没有规定输出,所以我们可以先排0行0列,剩下一个1~n-1的矩阵,然后多的#在矩阵中随便放。
代码如下:
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn = 1e6+5;
ll n,m,k,a[maxn],b[maxn];
int main()
{
freopen("class.in","r",stdin);
freopen("class.out","w",stdout);
char a[111][111];
memset(a,'.',sizeof(a));
int n,r,c;
cin>>n>>c>>r;
if((n+1)/2>max(r,c))//判断0行0列是否能排满
{
cout<<min(r,c)<<endl;
n++;//(0,0)遍历了两遍
for(int i=0; i<r; i++)
{
a[0][i]='#';
n--;
}
for(int i=0; i<c; i++)
{
a[i][0]='#';
n--;
}
if(n!=0)
{
for(int i=1; i<c; i++)
{
for(int j=1; j<r; j++)
{
a[i][j]='#';
n--;
if(n==0)
{
i=c;
break;
}
}
}
}
for(int i=0; i<c; i++)
{
for(int j=0; j<r; j++)
{
cout<<a[i][j];
}
cout<<endl;
}
}
else
{
cout<<min(min(r,c),(n+1)/2)<<endl;//输出最小的那个,符合题目要求
int t=n+1;
for(int i=0; i<min(min(r,c),(n+1)/2); i++)
{
a[i][0]='#';
t--;
if(t==0)
break;
}
for(int i=0; i<min(min(r,c),(n+1)/2); i++)
{
if(t==0)
break;
a[0][i]='#';
t--;
}
for(int i=0; i<c; i++)
{
for(int j=0; j<r; j++)
{
if(t==0)
{
i=c;
break;
}
if(a[i][j]!='#')
{
a[i][j]='#';
t--;
}
}
}
for(int i=0; i<c; i++)
{
for(int j=0; j<r; j++)
{
cout<<a[i][j];
}
cout<<endl;
}
}
return 0;
}