当前位置:网站首页>UPC2022暑期个人训练赛第23场(Credit Card Payment)
UPC2022暑期个人训练赛第23场(Credit Card Payment)
2022-08-02 23:54:00 【.Ashy.】
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ull;
typedef unsigned long long ll;
const int N = 1e5+10;
const int NN = 1e6+100;
const int pp = 1e9+7;
typedef pair<string,int>PII;
const int inf = 2147483647;
double eps = 1e-5;
int t,cnt;
double a,c,b;
/*首先读完题,我们可以发现一共有两个操作步骤 1. 计算 根据本金计算利息 2. 计算 新本金=本金+利息-还款 已知利息是个整数无误差(要四舍五入) 所以我们考虑精确第二个步骤 我们可以发现每个小数都是小数点后两位,为了消除误差我们可以把小数运算化成整数运算 即把本金和还款化为整数,这样所有的运算就都消除了误差 */
int main()
{
cin>>t;
while(t--)
{
cin>>a>>b>>c;
bool f=0;
cnt=0;
double a1=a/100.0;//计算出利率
int b1=b*100+eps;//本金化为整数
int c1=c*100+eps;//还款化为整数 注意eps尽量取1e-5 - 1e-7
int e=b1*a1+0.5;//计算出利息
if(e>c1) f=1;//如果第一次利息就大于还款,那么永远都还不完
else//否则计算还款次数
{
while(b1>0)
{
e=a1*b1+0.5;
// cout<<e<<endl;
b1=b1+e-c1;
cnt++;
if(cnt==1201)
{
f=1;
break;
}
}
}
if(f) cout<<"impossible\n";
else cout<<cnt<<"\n";
}
}
至于为什么化成整数的时候要加 eps ,这与浮点数的储存有关
详见博文:浮点数误差处理
边栏推荐
猜你喜欢
随机推荐
DownMusic总结记录
Canonical correlation analysis of CCA calculation process
Speech Synthesis Model Cheat Sheet (1)
如何突破测试/开发程序员思维?一种不一样的感觉......
flutter 时间戳转日期
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
Nacos配置中心之事件订阅
Auto.js special positioning control method cannot perform blocking operations on the ui thread, please use setTimeout instead
matplotlib中的3D绘图警告解决:MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure
为了面试阿里,熬夜肝完这份软件测试笔记后,Offer终于到手了
「PHP基础知识」隐式数据类型
Rasa 3.x 学习系列- Rasa - Issues 4792 socket debug logs clog up debug feed学习笔记
【TypeScript笔记】01 - TS初体验 && TS常用类型
我为什么又能面试一次就拿到offer
合并两个excel表格工具
可编程逻辑控制器(PLC) : 基础、类型和应用
6、Powershell命令配置Citrix PVS云桌面桌面注销不关机
Mock工具之Moco使用教程
面试题 08.07. 无重复字符串的排列组合 ●●
scala 集合通用方法









