Problem
You have just bought a new house, and it has a huge, beautiful lawn. A lawn that needs cutting. Several times. Every week. The whole summer.
After pushing the lawnmower around the lawn during the hottest Saturday afternoon in history, you decided that there must be a better way. And then you saw the ads for the new robotic lawnmovers. But which one should you buy? They all have different cutting speeds, cutting times and recharge times, not to mention different prices!
According to the advertisement, a robotic lawnmover will spend all its time either cutting the lawn or recharging its battery. Starting from a full battery, it will cut the lawn at a given rate of c
square meters per minute for a cutting time of t minutes, after which it has run out of battery. Once out of battery, it will immediately start recharging. After recharging for r minutes the battery is full again and it immediately starts cutting.
You decide that in order for your lawn to look sufficiently prim and proper, the lawnmower that you buy must be powerful enough to cut your whole lawn at least once a week on average. Formally, if we start the mower fully charged at the beginning of the week and run it for exactly T weeks, it needs to cut the whole lawn at least T times, for all positive integers T. But apart from this, you have no specific requirements, so among the ones that satisfy this requirement, you will simply go for the cheapest option. For the purposes of cutting your lawn, you may make the simplifying assumption that a week is always exactly 10080 minutes long.
Input
The first line of input contains two integers ℓ and m (1≤ℓ≤106, 1≤m≤100), the size of your lawn in square meters, and the number of lawnmowers to consider, respectively. Then follow m lines, each containing a string n and 4 integers p, c, t, and r, separated by commas, describing a lawnmower as follows: n is the name of the lawnmower, a string of at most 60 printable characters (ASCII 32 to 126) excluding ‘,’, neither starting nor ending with a space,1≤p≤100000 is the price of the lawnmover,
1≤c≤100 is the cutting rate in square meters per minute,1≤t≤10080 is the cutting time in minutes, and 1≤r≤10080 is the recharge time in minutes.
Output
Output the name of the cheapest lawnmower capable of cutting your whole yard at least once a week on average. If several lawnmovers share the same lowest price, output all of their names, in the same order they were given in the input. If there is no such mower, output “no such mower”.
Sample Input 1 | Sample Output 1 |
---|---|
7000 4 Grass Slayer 2000,9999,10,120,120 Slow-Mowe,999,1,120,240 Eco-cut X2,5499,2,25,35 Mowepower,5499,3,25,35 |
Eco-cut X2 Mowepower |
Sample Input 2 | Sample Output 2 |
---|---|
100000 4 Grass Slayer 2000,9999,10,120,120 Slow-Mowe,999,1,120,240 Eco-cut X2,5499,2,25,35 Mowepower,5499,3,25,35 |
no such mower |
题意:在符合条件T的情况下,选取最小价格,按输入顺序输出。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
char ss[10005];
struct node
{
char name[105];
ll m;
ll p, c, t, g;
double need;
}a[100005];
ll are, n;
bool cmp(struct node a, struct node b)
{
return a.p < b.p;
}
ll ojbk(ll x)
{
ll we = a[x].c * a[x].t;
double ti = are / we * a[x].g + are / we * a[x].t + ((are % we) * 1.0)/ a[x].c;
if(are % we != 0)
{
ti += (are % we) * 1.0 / we * a[x].g;
}
a[x].need = ti;
if(ti <= 10080)return 1;
else return 0;
}
int main()
{
scanf("%lld %lld", &are, &n);
getchar();
ll i, j, k;
ll minn = 0x3f3f3f3f;
for(i = 0; i < n; i++)
{
ll len = 0;
for(len = 0; (ss[len] = getchar()) != '
'; len++);
a[i].m = 0;
a[i].p = a[i].t = a[i].c = a[i].g = 0;
for(j = 0; j< len; j++)
{
if(ss[j] == ',')
{
a[i].name[a[i].m] = ' ';
break;
}
else
{
a[i].name[a[i].m++] = ss[j];
}
}
for(j++; j < len; j++)
{
if(ss[j] == ',')break;
else
{
a[i].p *= 10;
a[i].p += ss[j] - '0';
}
}
for(j++; j < len; j++)
{
if(ss[j] == ',')break;
else
{
a[i].c *= 10;
a[i].c += ss[j] - '0';
}
}
for(j++; j < len; j++)
{
if(ss[j] == ',')break;
else
{
a[i].t *= 10;
a[i].t += ss[j] - '0';
}
}
for(j++; j < len; j++)
{
if(ss[j] == ',')break;
else
{
a[i].g *= 10;
a[i].g += ss[j] - '0';
}
}
if(ojbk(i) == 1)
{
minn = min(minn,a[i].p);
}
}
if(minn == 0x3f3f3f3f)
{
printf("no such mower
");
}
else
{
for(i = 0; i < n; i++)
{
if(a[i].p == minn)
{
if(a[i].need <= 10080)
{
printf("%s
", a[i].name);
}
}
}
}
return 0;
}