1 second
256 megabytes
standard input
standard output
At many competitions that have a word «cup» in its official name the winner is presented with an actual cup. This time the organizers of one unusual programming competition have decided to please the winner even more and to add a nameplate to the cup with the handle of the winner.
The nameplate is to be rectangular and the text on it will be printed as a table of several rows and columns. Having some measurements done, the organizers have found out that the number aa of rows cannot be greater than 55 while the number bb of columns cannot exceed 2020. Every cell of the table will contain either an asterisk («*») or a letter of user’s handle.
Furthermore, the organizers want the rows of the table to be uniform, which means that the number of asterisks used in different rows should differ by at most one (i.e. you can’t have two asterisks in the first row and none in the second). The main goal, however, is to obtain the winner’s handle precisely when reading the table from top to bottom and from left to right in every row (skipping asterisks).
The organizers want for the nameplate to have as few rows as possible and among all valid tables with the minimum number of rows they want to choose the one that has the minimum number of columns.
The winner is not yet determined so your task is to write a program that, given a certain handle, generates the necessary table.
The only line contains one string ss (1≤|s|≤1001≤|s|≤100), comprised of uppercase and lowercase Latin letters, — the handle of the winner.
In the first line output the minimum number aa of rows in the table and the minimum number bb of columns in an optimal table with rows.
The following aa lines should contain bb characters each — any valid table.
tourist
1 7 tourist
MyNameIsLifeIAmForeverByYourSideMyNameIsLife
3 15 MyNameIsLifeIAm ForeverByYourSi deMyNameIsL*ife
首先反思一下,自己切水题太慢了,导致没有赶在服务器宕机之前加第二题。
题意:在保证行最小的情况下保证列最小,并且rows<=5,cols<=20,要求输出是矩形,多余部分用*代替,任意两行*相差不超过1,也就是说,其实只要按照矩形输出,在短行输出*补位。保证行最小情况下列最小,*每行最多出现一次,可以反证。可以分类进行讨论,用一个函数输出,也可以先划分好行列,再计算补位数进行补位。
赛程:
[cpp]
#include<algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define P(a,b,c) make_pair(a,make_pair(b,c))
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define CLR(vis) memset(vis,0,sizeof(vis))
#define MST(vis,pos) memset(vis,pos,sizeof(vis))
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef pair<int,pair<int,int> >pii;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
const int maxn = 1e2+5;
char s[maxn];
int len;
void print(int num){
if(len%num)printf("%d %d\n", num,len/num+1);
else printf("%d %d\n", num,len/num);
int ans=num-len%num;
if(ans==num)ans=0;
int t=len/num;
if(len%num==0)t=0;
int i=0;
while(i<len){
if(ans==0){
cout<<s[++i];
t++;
}else{
cout<<s[++i];
}
if(ans==0&&t==(len+num-1)/num){
cout<<endl;
t=0;
}
else if(i%t==0&&ans>0){
printf("*\n");
ans--;
if(ans==0)t=0;
}
}
}
int main(){
// ios::sync_with_stdio( false );
scanf("%s", s);
len = strlen(s);
per(i,1,len){
s[i]=s[i-1];
}
int r,c,xin;
if(len<=20){
printf("%d %d\n%s\n", 1,len,s+1);
}else if(len<=40){
print(2);
}else if(len<=60){
print(3);
}else if(len<=80){
print(4);
}else if(len<=100){
print(5);
}
return 0;
}
[/cpp]
实际上差不多的代码:
[cpp]
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
ios::sync_with_stdio(0);
string s;
cin >> s;
long long n = ceil(s.size()*1.0/20);//朝正无穷取整,这里计算行数
vector<long long> v(n, 0);
for(long long i = 0; i < s.size(); i++){
v[i%n]++;
}
long long Max = *max_element(v.begin(), v.end());//找出列数//脱裤子放屁
cout << n << " " << Max << endl;
int fi=0, se=v[0];
for(int i = 0; i < n; i++){//按行列划分
for(int j = fi; j < (se+fi); j++){
cout << s[j];
}
if(se != Max){
cout << '*';
}
fi = se+fi;
se = v[i+1];
cout << endl;
}
return 0;
}
[/cpp]