POJ C Programming Advanced Programming Problem # #: Bacterial grouping experiment

Source: Internet
Author: User

Programming Question # #: Bacterial Experiment Grouping

Source: POJ (Coursera statement: The exercises completed on POJ will not count against the final results of Coursera. )

Note: Total time limit: 1000ms memory limit: 65536kB

Describe

There is a bacteria divided into a, b two subspecies, their external characteristics are almost identical, only in the reproductive capacity of the significant difference, a subspecies reproductive ability is very strong, b subspecies of the reproductive capacity is very weak. In a one-hour bacterial breeding experiment, the experimenter messed up the petri dish due to negligence, and asked you to write a program that would split the petri dishes of two subspecies into two groups according to the experimental results.

Input

The input has multiple lines, and the first behavior is an integer n (n≤100), which indicates that there are n petri dishes.

The remaining n rows have three integers per line, representing the petri dish number, the number of bacteria before the test, and the number of bacteria after the test.

Output

Output has multiple lines:

The first line outputs the number of petri dishes of a subspecies, followed by the number of each row of petri dishes, sorted in ascending order of reproduction rate.

The number of petri dishes of b subspecies is then output, followed by the number of each row of the B subspecies culture dish, and also by the breeding rate in ascending order.

Sample input

5 1 10 3456 2 10 5644 3 10 4566 4 20 234 5 20 232

Sample output

3 1 3 2 2 5 4  

Tips

Within subspecies, the difference of bacterial reproduction ability is much smaller than that of the subspecies.

In other words, the difference between the reproductive rates of any two groups of bacteria in the subspecies is greater than that of the two groups of bacteria within the subspecies.

1#include <iostream>2 using namespacestd;3 intMain () {4   intN//N is the number of bacteria5   //ID records the number of bacteria, rate records bacterial fertility, the first bacteria corresponds to Id[i] and Rate[i]6   intid[ -];7   Doublerate[ -];8 9CIN >>N;Ten    for(inti =0; I < n; i++) { One     intinitial, final; ACIN >> Id[i] >> initial >>final; -Rate[i] = (Double) Final/initial; -   }   the  - //sequencing the whole bacterium -    for(inti =0; I < n; i++) { -      for(intj =0; J < N-i-1; J + +) { +       if(Rate[j +1] >Rate[j]) { -         intTmpid =Id[j]; +ID[J] = id[j +1]; AId[j +1] =tmpid; at         DoubleTmprate =Rate[j]; -RATE[J] = rate[j +1]; -Rate[j +1] =tmprate; -       } -     } -   }   in  - //record the maximum difference to   DoubleMaxDiff =0; +   //and the maximum difference subscript -   intMaxdiffindex =0; the    for(inti =0; I < n-1; i++) { *     Doublediff = rate[i]-rate[i +1]; $     if(MaxDiff <diff) {Panax NotoginsengMaxDiff =diff; -Maxdiffindex =i; the     }   +   } A    the   //The group of bacteria with a large output reproduction rate +cout << Maxdiffindex +1<<Endl; -    for(inti = Maxdiffindex; I >=0; i--) { $cout << Id[i] <<Endl; $   } -  -   //the group of bacteria with a smaller output reproduction rate thecout << N-maxdiffindex-1<<Endl; -    for(inti = n-1; I >= Maxdiffindex +1; i--) {Wuyicout << Id[i] <<Endl; the   } -   return 0; Wu}

POJ C Programming Advanced Programming Problem # #: Bacterial grouping experiment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.