牛客多校(2020第五场)F DPS

题目链接:https://ac.nowcoder.com/acm/contest/5670/F

题解:注意爆int,需注意double精度问题,向上取整

 1 #include
 2 #include
 3 using namespace std;
 4 
 5 const long long  MAX_N = 1000;
 6 
 7 long long n;
 8 long long s;
 9 
10 long long col_s(long long  mx, long long  di) {
11    return (50 * di + mx - 1) * 1.0/ mx;
12 }
13 
14 void out_print (long long  length, long long  di, long long  max) {
15     cout << "+";
16     for (long long  i = 0; i < length; i++) {
17         cout << "-";
18     }
19     cout << "+\n";
20     cout << "|";
21     for (long long  i = 0; i < length-1; i++) {
22         cout << " ";
23     }
24     if(di == max)
25         cout << "*|" << di << "\n";
26     else if (di == 0) 
27         cout << "|" << di << "\n";
28     else
29         cout << " |" << di << "\n";
30     cout << "+";
31     for (long long  i = 0; i < length; i++) {
32         cout << "-";
33     }
34     cout << "+\n";
35 }
36 
37 int main() {
38     cin >> n;
39     long long  a[MAX_N];
40     long long  max_num = 0;
41     for (long long  i = 0; i < n; i++) {
42         cin >> a[i];
43         if (max_num < a[i]) max_num = a[i];
44     }
45     for (long long  i = 0; i < n; i++) {
46         long long  length = col_s(max_num, a[i]);
47         out_print (length, a[i], max_num);
48     }
49     return 0;
50 }

 

你可能感兴趣的:(牛客多校(2020第五场)F DPS)