Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. /* USER: u199
  2. LANG: Java
  3. TASK: hydrocarbons */
  4.  
  5. import java.io.FileInputStream;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.PrintStream;
  9. import java.util.*;
  10.  
  11. public class hydrocarbons {
  12.  
  13. static String inputFilename = "hydrocarbons.in";
  14. static String outputFilename = "hydrocarbons.out";
  15.  
  16. static class Solver {
  17. Scanner in = new Scanner(System.in);
  18.  
  19. double a = 0, b = 0, c = 0;
  20.  
  21. int profit = 0;
  22.  
  23. int n = Integer.parseInt(in.nextLine());
  24. double total[] = new double[n];
  25. double temp[] = new double[n];
  26. int profitable[] = new int[n];
  27.  
  28. Map<Double, Double> pr = new HashMap<>();
  29.  
  30.  
  31. public void solve() {
  32.  
  33.  
  34. for(int i = 0; i <= n-1; i++) {
  35. a = in.nextDouble();
  36. b = in.nextDouble();
  37. c = in.nextDouble();
  38.  
  39. total[i] = a-a*(b/3000) - c*a/40;
  40. }
  41.  
  42. int used[][] = new int[n][n];
  43. for (int e = 0; e <= n-1; e++) {
  44. for (int x = 1; x <= n-1; x++) {
  45. if ( ((total[e] - total[x]) <= 0.0000001) && ((total[e] - total[x]) >= 0 )) {
  46. if ((x != e) && (used[x][e] != 1) && (used[e][x] != 1) ) {
  47. total[e] = total[e] + e + x * 0.2;
  48. used[e][x] = 1;
  49. used[x][e] = 1;
  50. }
  51. }
  52. }
  53. }
  54.  
  55. for (int i = 0; i <= n-1; i++) {
  56. pr.put( total[i], (double) i);
  57. }
  58.  
  59. Arrays.sort(total);
  60.  
  61. for (int z = 0; z <= n-1; z++) {
  62. if (total[z] > 0) {
  63. temp[profit] = pr.get(total[z]);
  64. profit++;
  65. }
  66. }
  67.  
  68. for (int y = 0; y <= profit-1; y++) {
  69. profitable[y] = (int) Math.round(temp[y]);
  70. }
  71.  
  72.  
  73. if (profit == 0) {
  74. System.out.println("0");
  75.  
  76. } else if (profit == 1) {
  77.  
  78. System.out.println("1");
  79. System.out.println(profitable[0] + 1);
  80. }
  81. else {
  82. System.out.println(profit);
  83. for (int x = profit-1; x >= 0; x--) {
  84. System.out.print(profitable[x] + 1 + " ");
  85. }
  86. }
  87. }
  88.  
  89. }
  90.  
  91.  
  92. public static void main(String args[]) {
  93.  
  94. try ( FileInputStream instream = new FileInputStream(inputFilename);
  95. PrintStream outstream = new PrintStream( new FileOutputStream(outputFilename) );
  96. )
  97. {
  98. System.setIn(instream);
  99. System.setOut(outstream);
  100.  
  101. Solver solver = new Solver();
  102. solver.solve();
  103.  
  104. instream.close();
  105. outstream.close();
  106. } catch (IOException ioe) {
  107. System.err.println("IOException: " + ioe);
  108. }
  109.  
  110. }
  111.  
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement