POJ 3619 SpeedReading 水题

本文介绍了一种算法解决方案,用于计算不同速度、时间和休息限制下的牛群完成特定长度书籍阅读的时间。该算法考虑了两种特殊情况,并提供了完整的C++代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpeedReading

Time Limit: 1000MS

Memory Limit: 65536K

Total Submissions: 9743

Accepted: 4584

Description

All K (1 ≤ K ≤ 1,000) of the cows are participatingin Farmer John's annual reading contest. The competition consists of reading asingle book with N (1 ≤ N ≤ 100,000) pages as fast as possiblewhile understanding it.

Cow i has a reading speed Si (1 ≤ Si ≤ 100) pages per minute, a maximumconsecutive reading time Ti (1 ≤ Ti ≤ 100) minutes, and a minimum resttime Ri (1 ≤ Ri ≤ 100) minutes. The cow can read at arate of Si pages per minute, but only for Ti minutes at a time. After she stopsreading to rest, she must rest for Ri minutes before commencing readingagain.

Determine the number of minutes (rounded up to the nearest fullminute) that it will take for each cow to read the book.

Input

* Line 1: Two space-separated integers: N and K
* Lines 2..K+1: Line i+1contains three space-separated integers: Si , Ti , and Ri

Output

* Lines 1..K: Line i should indicate how many minutes(rounded up to the nearest full minute) are required for cow i to read the whole book.

SampleInput

10 3
2 4 1
6 1 5
3 3 3

SampleOutput

6
7
7

Source

USACO 2007 November Bronze

算法分析:

水题一枚

注意两种情况。

情况一:刚好整数个回合看完
 
情况二:不用花一个回合就看完了

 

代码实现:

 

#include<iostream>  
#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<algorithm>  
#include<string>  
#include<cstdlib>  
#include<queue>  
#include<vector>  
#define INF 0x7fffffff  
#define PI acos(-1.0)  

#define MOD 2520  
#define E 1e-12 
using namespace std;
#define N  150
int n,m;
int main()
{

    while(scanf("%d%d",&n,&m)!=EOF)
    {
	  for(int i=1;i<=m;i++)
	  {
	  	int s,t,r;
	  	scanf("%d%d%d",&s,&t,&r);
	  	int sum=0;
	  	
	  	for(int j=0;j<n;)
		{   if(j!=0)sum+=r;
		   if(j+s*t<n)
			{j+=s*t;
			sum+=t;
			}
			else 
			{
				if((n-j)/s!=((n-j)/(s*1.0)))
				sum+=(n-j)/s+1;
				else 
					sum+=(n-j)/s;
				break;
			}
		}
		cout<<sum<<endl;
	  }
	  
	  	 
    }
        return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值