当前位置: 代码迷 >> 综合 >> POJ 3619 SpeedReading 水题
  详细解决方案

POJ 3619 SpeedReading 水题

热度:68   发布时间:2024-01-15 08:14:38.0

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;
}

  相关解决方案