When you are playing multiplayer games, you may want to show that you are the MVP of your team -- or blame the one always wandering and watching away from the storm center. Well, there're statistics that show you preformance, but sometimes numbers speak softer than charts. Now, you're hired to write a program that output ASCII art histograms showing damage dealt to enemies.
There are n players in the game. Given that the i-th player dealt did_idi damage to enemies where maxidi>0 is granted, you need to calculate the number sis_isi of spaces in the bar by the following foluma:
Instead of formal definition of bar description, we will give an example. For some player i whose si=7 and di=777, the bar is shown as:
+-------+ | |777 +-------+
Moreover, you have to mark the player with maximal damage dealt to enemies by replacing the last space into '*'. If there're multiple maximum, mark all of them.
See samples for more ideas.
输入描述:
The first line contains one integer n(1≤n≤100).
The next n line each contains one integer, the i-th line contains di(0≤di≤43962200)
It's granted that maxidi>0\max_i d_i > 0maxidi>0.
输出描述:
3n lines, each 3 lines denote a bar in the correct format.
示例1
输入
4 50 40 50 0
输出
+--------------------------------------------------+ | *|50 +--------------------------------------------------+ +----------------------------------------+ | |40 +----------------------------------------+ +--------------------------------------------------+ | *|50 +--------------------------------------------------+ ++ ||0 ++
示例2
输入
5 1676 4396 2200 443 556
输出
+--------------------+ | |1676 +--------------------+ +--------------------------------------------------+ | *|4396 +--------------------------------------------------+ +--------------------------+ | |2200 +--------------------------+ +------+ | |443 +------+ +-------+ | |556 +-------+
思路:
很简单一道模拟题,记得要开long long,43962200*50会爆int。
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1e4 + 10;
int n,a[N],ans=1e9;
int f[N];
int work() {
int res = 0;
for(int i = 1; i <= n;i++){
f[i] = 1;
for(int j = 1;j<i;j++)
if(a[i] > a[j]) f[i] = max(f[i],f[j] + 1);
res = max(res, f[i]);
}
return res;
}
void move() {
int ans = a[1];
for (int i = 1; i < n; i ++ )
a[i] = a[i + 1];
a[n] = ans;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = 1; i <= n; i ++ )
ans = min(ans, n - work()), move();
cout << ans;
}