2013
11-10

# Does This Make Me Look Fat?

As the host of a popular daytime television talk show, you are working through the details of an upcoming episode on dieting. Your guest is the controversial Dr. Kevorkian, who has recently invented his own weight-loss plan, “Do You Want To Diet?” that guarantees to reduce your body weight by 1 pound every day.

You have a number of dieters scheduled to be on the show who have all been using Dr. Kevorkian?s new plan. You want to make the episode more dramatic by introducing your guests in decreasing order of their weights on the day of the show. The problem is that the forms you had them fill out only requested the following information: Name, Days on the diet, Weight at start of diet. Hopefully you can dredge up those long-forgotten math skills before the filming time tonight!

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.

A single data set has 3 components:

1. Start line – A single line, “START”
2. Dieter list – A series of 1 to 10 (inclusive) single lines consisting of three fields, with each field separated from the others by a single space:
• Name – The dieter?s first name. This will be a text string containing 1 to 20 (inclusive) alphanumeric characters (no spaces).
• Days On Diet – The number of days the dieter has been on the “Do You Want To Diet” as of the day of the talk show. This will be a non-zero positive integer strictly less than 1000.
• Starting Weight – The weight, in pounds, of the dieter just before starting the diet. This will be a non-zero positive integer strictly less than 10,000.

3. End line – A single line, “END”

Here are some facts that may be useful:

• All dieters lost exactly 1 pound every day they were on the diet, as advertised.
• Nobody stayed on the diet long enough to weigh less than 1 pound at the time of the show.
• All dieters in a given input set will have different weights on the day of the show.
• All dieters in a given input set will have different names.

For each input data set, there will be exactly one output set, and there will be exactly one blank line separating output sets.

A single output set consists of a series of lines, each containing the Name of one of the dieters from the Dieter list. The list will be sorted in descending order according to weight at the time of the TV show. All dieters must be listed.

START
Joe 10 110
END
START
James 100 150
Laura 100 140
Hershey 100 130
END
START
Hershey0 1 5
Hershey2 1 3
Hershey1 1 4
Hershey3 1 2
END


Joe

James
Laura
Hershey

Hershey0
Hershey1
Hershey2
Hershey3


//* @author: ccQ.SuperSupper
import java.io.*;
import java.util.*;
class WHO implements Comparable{
String name;
int index;
public int compareTo(Object temp){
WHO tmp = (WHO)temp;
if(tmp.index< this.index) return -1;
return 1;
}
}
public class Main {
static final int N = 100000;
static WHO who[] = new WHO[N];
static void start(){
for(int i=0;i< N;++i)
who[i] = new WHO();
}

public static void main(String[]args) throws Exception{
int i,j,n,t=0;
start();
Scanner cin = new Scanner(System.in);
//Scanner cin = new Scanner(new FileInputStream("input.txt"));
while(cin.hasNext()){
n = 0;
who[n].name = cin.next();
who[n].name = cin.next();
while(!who[n].name.equals("END")){
j = cin.nextInt();
i = cin.nextInt();
who[n].index = i-j;
++n;
who[n].name = cin.next();
}
Arrays.sort(who,0,n);
if(t>0) System.out.println();
for(i=0;i< n;++i)
System.out.println(who[i].name);
t = 1;
}
}
}

1. 约瑟夫也用说这么长……很成熟的一个问题了，分治的方法解起来o(n)就可以了，有兴趣可以看看具体数学的第一章，关于约瑟夫问题推导出了一系列的结论，很漂亮

2. 很高兴你会喜欢这个网站。目前还没有一个开发团队，网站是我一个人在维护，都是用的开源系统，也没有太多需要开发的部分，主要是内容整理。非常感谢你的关注。