2013
11-12

# Speed Reading

All K (1 ≤ K ≤ 1,000) of the cows are participating in Farmer John's annual reading contest. The competition consists of reading a single book with N (1 ≤ N ≤ 100,000) pages as fast as possible while understanding it.

Cow i has a reading speed Si (1 ≤ Si ≤ 100) pages per minute, a maximum consecutive reading time Ti (1 ≤ Ti ≤ 100) minutes, and a minimum rest time Ri (1 ≤ Ri ≤ 100) minutes. The cow can read at a rate of Si pages per minute, but only for Ti minutes at a time. After she stops reading to rest, she must rest for Ri minutes before commencing reading again.

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

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

* 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.

10 3
2 4 1
6 1 5
3 3 3

6
7
7

import java.util.*;
import java.io.*;
/*
* n 工作量;
* s[i] 每分钟可完成的工作量
* t[i] 一次性连续工作最多坚持的时间
* r[i] 一次连续工作后需要休息的时间
*/
public class Main{

public static void main(String rgs[]) throws Exception
{
BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
String line = stdin.readLine();
StringTokenizer st = new StringTokenizer(line);
int k,s,t,r,i,j,n,m,l,p;
n = Integer.parseInt(st.nextToken());
k = Integer.parseInt(st.nextToken());
for(i=0;i< k;i++){
m=l=p=0;
line = stdin.readLine();
st = new StringTokenizer(line);
s = Integer.parseInt(st.nextToken());
t = Integer.parseInt(st.nextToken());
r = Integer.parseInt(st.nextToken());
while(l< n){
while(l< n && p< t){
l+=s;
m++;
p++;
}
if(l< n){
m+=r;
p=0;
}
}
System.out.println(m);
}
}
}

1. 问题3是不是应该为1/4 .因为截取的三段，无论是否能组成三角形， x， y-x ，1-y,都应大于0，所以 x<y,基础应该是一个大三角形。小三角是大三角的 1/4.

2. #include <cstdio>

int main() {
//answer must be odd
int n, u, d;
while(scanf("%d%d%d",&n,&u,&d)==3 && n>0) {
if(n<=u) { puts("1"); continue; }
n-=u; u-=d; n+=u-1; n/=u;
n<<=1, ++n;
printf("%dn",n);
}
return 0;
}