2020牛客暑期多校训练营(第五场)F.DPS(构造)

题目链接

思路:

构造即可。

代码:

#include
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=55;
const int M=4e5+8;
const double eps=1e-8;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926;
int d[150];
signed main()
{
    IOS;
    int n;
    int ma=-1;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>d[i];
        ma=max(ma,d[i]);
    }
    for(int i=0;i<n;i++)
    {
        if(d[i]==0)
        {
            cout<<"++"<<endl;
            cout<<"||0"<<endl;
            cout<<"++"<<endl;
            continue;
        }
        int a=50.0*d[i];
        if(a%ma==0)
        {
            a=a/ma;
        }
        else
        {
            a=a/ma+1;
        }
        string s(a,'-');
        string ss(a-1,' ');
        if(d[i]==ma)
        {
            ss+='*';
        }
        else
        {
            ss+=' ';
        }
        cout<<'+'<<s<<'+'<<endl;
        cout<<'|'<<ss<<'|'<<d[i]<<endl;
        cout<<'+'<<s<<'+'<<endl;
    }
    return 0;
}

你可能感兴趣的:(思维,构造)