DPS(2023牛客五一集训派对day5,F题)

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 max⁡idi>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 max⁡idi>0\max_i d_i > 0maxi​di​>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;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值