P17790 [入门赛 #53] 买牛奶
这题应该是一道很难的入门题了吧
题目传送门
直接讲思路
从第一天开始,找到第一个价格
代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int days[] = {1, 3, 4, 5, 6};
double d[] = {1.0, 0.9, 0.8, 0.7, 0.6};
double s;
s = a * 1.0;
if (s <= b) {
cout << "1 " << fixed << setprecision(2) << s << endl;
return 0;
}
for (int i = 1; i < 5; i++) {
s = a * d[i];
if (s <= b) {
cout << days[i] << " " << fixed << setprecision(2) << s << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}