FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 7278 Accepted Submission (s): 3217
Special Judge
Problem DescriptionFatMouse believes that the fatter a mouse is, the faster it runs. to disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing,
But the speeds are decreasing. InputInput contains data for a bunch of mice, one mouse per line, terminated by end of file.
The data for a participating mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. both integers are between 1 and 10000. the data in each test case will contain information
For at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
OutputYour program shocould output a sequence of lines of data; the first line shocould contain a number n; the remaining n lines shocould each contain a single positive integer (each one representing a mouse ). if these n integers are m [1], m [2],...,
M [n] then it must be the case that
W [m [1] <W [m [2] <... <W [m [n]
And
S [m [1]> S [m [2]>...> S [m [n]
In order for the answer to be correct, n shoshould be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be specified correct outputs for a given input, your program only needs to find one.
Sample Input
6008 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900
Sample Output
44597
Code:
Sort the first keyword first to simplify the program
Then find the longest descending subsequence Based on the decreasing speed
This question is special judge, so you don't have to limit it to the sample output given by the question. Just set the number and result pair.
# Include <stdio. h> # include <iostream> # include <algorithm> using namespace std; typedef struct mouse {// dp stores the number of mice that meet the conditions before the current mouse, including yourself, pre stores the mouse int num, dp, pre; int w, s;} mouse that meets the conditions in front of the current mouse; mouse a [1005]; bool cmp (mouse a, mouse B) {if (. w <B. w) return true; else return false;} void print (int loc) {if (a [loc]. pre = loc) {printf ("% d \ n", a [loc]. num); return;} print (a [loc]. pre); printf ("% d \ n", a [loc]. num);} int main () {int I = 1, k, J, max, loc, sum = 0; while (scanf ("% d", & a [I]. w, & a [I]. s )! = EOF) I ++; for (k = 1; k <I; k ++) a [k]. num = k; // here I don't need-1, depressing half-day sort (a + 1, a + k + 1, cmp); // sort for (I = 1; I <= k; I ++) {a [I]. pre = I; a [I]. dp = 0;} a [1]. dp = 1; for (I = 2; I <= k; I ++) {for (j = 1; j <I; j ++) {if (a [j]. w <a [I]. w & a [j]. s> a [I]. s & a [I]. dp <a [j]. dp) {a [I]. dp = a [j]. dp; a [I]. pre = j ;}} a [I]. dp ++; // Add yourself} max = 0; loc =-1; for (I = 1; I <= k; I ++) // find the maximum dp value and its position {if (a [I]. dp> max) {max = a [I]. dp; loc = I ;}} printf ("% d \ n", max); print (loc); return 0 ;}