Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* USER: u199
- LANG: Java
- TASK: hydrocarbons */
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.util.*;
- public class hydrocarbons {
- static String inputFilename = "hydrocarbons.in";
- static String outputFilename = "hydrocarbons.out";
- static class Solver {
- Scanner in = new Scanner(System.in);
- double a = 0, b = 0, c = 0;
- int profit = 0;
- int n = Integer.parseInt(in.nextLine());
- double total[] = new double[n];
- double temp[] = new double[n];
- int profitable[] = new int[n];
- Map<Double, Double> pr = new HashMap<>();
- public void solve() {
- for(int i = 0; i <= n-1; i++) {
- a = in.nextDouble();
- b = in.nextDouble();
- c = in.nextDouble();
- total[i] = a-a*(b/3000) - c*a/40;
- }
- int used[][] = new int[n][n];
- for (int e = 0; e <= n-1; e++) {
- for (int x = 1; x <= n-1; x++) {
- if ( ((total[e] - total[x]) <= 0.0000001) && ((total[e] - total[x]) >= 0 )) {
- if ((x != e) && (used[x][e] != 1) && (used[e][x] != 1) ) {
- total[e] = total[e] + e + x * 0.2;
- used[e][x] = 1;
- used[x][e] = 1;
- }
- }
- }
- }
- for (int i = 0; i <= n-1; i++) {
- pr.put( total[i], (double) i);
- }
- Arrays.sort(total);
- for (int z = 0; z <= n-1; z++) {
- if (total[z] > 0) {
- temp[profit] = pr.get(total[z]);
- profit++;
- }
- }
- for (int y = 0; y <= profit-1; y++) {
- profitable[y] = (int) Math.round(temp[y]);
- }
- if (profit == 0) {
- System.out.println("0");
- } else if (profit == 1) {
- System.out.println("1");
- System.out.println(profitable[0] + 1);
- }
- else {
- System.out.println(profit);
- for (int x = profit-1; x >= 0; x--) {
- System.out.print(profitable[x] + 1 + " ");
- }
- }
- }
- }
- public static void main(String args[]) {
- try ( FileInputStream instream = new FileInputStream(inputFilename);
- PrintStream outstream = new PrintStream( new FileOutputStream(outputFilename) );
- )
- {
- System.setIn(instream);
- System.setOut(outstream);
- Solver solver = new Solver();
- solver.solve();
- instream.close();
- outstream.close();
- } catch (IOException ioe) {
- System.err.println("IOException: " + ioe);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement