【NCPC - 2018】H - House Lawn

H - House Lawn

 

题目大意:

有一个 l 平方米的草坪,给你 m 台割草机。

选择其中一台,在一周(10080分钟)的时间内割完草坪。

每台割草机输入格式为:“名字,价格,割草效率,工作时间,充电时间” ;

割草效率单位:平方米每分钟;

工作时间单位:分钟;

充电时间单位:分钟。

要求选出价格最低的满足条件的一台,如果有多台满足条件且价格相同,按照输入顺序输出割草机名字。

如果没有满足条件的输出 “no such mover”

题解:

字符串切割之后,把数据存入结构体中,排序一遍。

再循环判断一下就好,注意有精度问题要用用double。

代码:

#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;
const int INF = 1e9;
int l, m;
int w = INF;
char s[200];

struct cut{
	char name[65];
	int price;
	int rate;
	int work;
	int rest;
	int id;
}temp[105];

int cmp(cut a, cut b){
	if(a.price == b.price)
		return a.id < b.id;
	return a.price < b.price;
}

int main(){
	const char *d = ",";
	char *p;
	scanf("%d %d", &l, &m);
		for(int i = 0; i <= m; ++i){
			int j = 0;
			memset(s, '\0', sizeof(s));
			gets(s);
			p = strtok(s, d);
			temp[i].id = i;
			while(p){
				if(j==0){
					strcpy(temp[i].name, p);
					//printf("%s\n", temp[i].name);
				}
				else if(j==1){
					temp[i].price = atoi(p);
					//printf("%d\n", temp[i].price);
				}
				else if(j==2){
					temp[i].rate = atoi(p);
					//printf("%d\n", temp[i].rate);
				}
				else if(j==3){
					temp[i].work = atoi(p);
					//printf("%d\n", temp[i].work);
				}
				else{
					temp[i].rest = atoi(p);
					//printf("%d\n", temp[i].rest);
				}
				p = strtok(NULL, d);
				++j;
			}
		}
		sort(temp+1, temp+m+1, cmp);
		for(int i = 1; i <= m; ++i){
			if((double)((double)10080 / (double)(temp[i].work+temp[i].rest )) * (double)(temp[i].rate*temp[i].work) >= (double)l ){
				if(w == INF || w == temp[i].price){
					printf("%s\n", temp[i].name);
					w = temp[i].price;
				}
			}
		}
		if(w==INF){
			printf("no such mower\n");
		}
		//getchar();
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值