原文链接:
http://www.zlingfly.com/2018/05/12/%E5%90%88%E5%B7%A5%E5%A4%A7OJ-1372-%E6%89%BE%E9%9B%B6/#more
题目要求把物品总价值的‘分’进位,思路大概就是把总价值乘以100,然后就相当于如果个位不为0就进位。
思路超级简单是不是?但是这题最坑的地方就是总价值*100会爆int。。。
using namespace std;
typedef long long LL;
int main(){
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
int cas=1;
while(t--){
LL n;
double all=0.0;
double sum=0.0,m=0.0;
cin>>n>>m;
for(int i=0;i<n;i++){
double x;
double c;
cin>>x>>c;
all=all+(x*c*100);
}
LL a=(int)all%10;
if(a!=0){
all=all+10-a;
}
sum=all/100;
if(m>=sum)
printf("Case %d: %.2f\n",cas,m-sum);
else {
printf("Case %d: -1\n",cas);
}
cas++;
}
return 0;
}