简单题,大致的题意就是求 $(\sum_{i = 1}^n a_i \times b_i) \times 0.85$,然后保留一位小数的值。需要注意的是,这里的保留一位小数是直接舍去后面的数字,而不是四舍五入求值

处理保留一位小数的两种方法:

  1. 分类讨论,如果小数部分 $>0.5$,就整体减去 $0.5$,否则不变,然后直接用 %0.1lf 输出。
  2. 直接操作 tot = ((int)(tot * 0.85 * 10)) / 10.0

另外就直接相加就完事了。。。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#define init(x) memset (x,0,sizeof (x))
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
int n,sum;double price,tot;
int main ()
{
//freopen (".in","r",stdin);
//freopen (".out","w",stdout);
scanf ("%d",&n);
while (n--)
{
scanf ("%lf%d",&price,&sum);
tot += price * sum;
}
tot = ((int)(tot * 0.85 * 10)) / 10.0;
printf ("%0.1lf\n",tot);
return 0;
}