http://poj.org/problem?id=2586
题意有点难读懂,看这篇https://blog.csdn.net/lyy289065406/article/details/6642603
思路很简单,需要注意的是判断s的时候要从小到大判断,否则需要进行双重判断较麻烦
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float s, d, total;
while (scanf_s("%f %f", &s, &d) != EOF)
{
if (4 * s < d)
total = 10 * s - 2 * d;
else if (3 * s < 2 * d)
total = 8 * s - 4 * d;
else if (2 * s < 3 * d)
total = 6 * s - 6 * d;
else if (s < 4 * d)
total = 3 * s - 9 * d;
else if (s >= 4 * d)
total = -1;
if (total <= 0)
cout << "Deficit" << endl;
else
cout << total << endl;
}
}