Untitled
unknown
plain_text
2 years ago
4.4 kB
4
Indexable
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; class Advertise { int length; int point; int start; public Advertise(int leng, int point, int start) { this.length = leng; this.point = point; this.start = start; } public Advertise(int leng, int point) { this.length = leng; this.point = point; } // // public Advertise( int point) { // // this.point = point; // // } public Advertise(int leng) { this.length = leng; } } class Customer { int timeDen; int timeDi; int timeOLai; public Customer(int den, int oLai) { this.timeDen = den; this.timeOLai = oLai; // this.timeDi = di; } } public class QuangCao { static int N, L1, L2, L3, P1, P2, P3; static int thoiGianDen[]; static int thoiGianDi[]; static int arr[][] = { { 0, 1, 2 }, { 0, 2, 1 }, { 1, 2, 0 }, { 1, 0, 2 }, { 2, 0, 1 }, { 2, 1, 0 } }; static int LichTrinh[][]; static Advertise[] ads; static Customer[] customers; static int ans; public static void main(String[] args) { try { System.setIn(new FileInputStream("quangCao")); } catch (FileNotFoundException e) { e.printStackTrace(); } Scanner sc = new Scanner(System.in); int numTest = sc.nextInt(); for (int tc = 1; tc <= numTest; tc++) { N = sc.nextInt(); // // L1 = sc.nextInt(); // // L2 = sc.nextInt(); // // L3 = sc.nextInt(); // P1 = sc.nextInt(); // P2 = sc.nextInt(); // P3 = sc.nextInt(); ads = new Advertise[4]; for (int i = 1; i <= 3; i++) { ads[i] = new Advertise(sc.nextInt()); } for (int i = 1; i <= 3; i++) { ads[i].point = sc.nextInt(); } // thoiGianDen = new int[N + 1]; // thoiGianDi = new int[N + 1]; customers = new Customer[N + 1]; for (int i = 1; i <= N; i++) { // thoiGianDen[i] = sc.nextInt(); // thoiGianDi[i] = sc.nextInt(); customers[i] = new Customer(sc.nextInt(), sc.nextInt()); customers[i].timeDi = customers[i].timeDen + customers[i].timeOLai; } LichTrinh = new int[4][N + 1]; ans = Integer.MIN_VALUE; // System.out.println(arr.length); for (int i = 0; i < arr.length; i++) { // System.out.println(arr[i] + " "); solve(i); } System.out.println("Casr #" + tc); System.out.println(ans); } } // QC1 tu 1->50-L1-L2-L3 // Qc2 tgian bat dau qc1(i)+L1->50-L2-L3 // Qc3 tgian bat dau qc2(j)+L2->50-L3 // tong quat thi i: tgian bat dau cua ads[arr[0]] // k: tgian bat dau cua ads[arr[1]] public static void solve(int index) { int x = arr[index][0] + 1; int y = arr[index][1] + 1; int z = arr[index][2] + 1; for (int i = 1; i <= 50 - ads[x].length - ads[y].length - ads[z].length; i++) { for (int j = i + ads[x].length; j <= 50 - ads[y].length - ads[z].length; j++) { for (int k = j + ads[y].length; j <= 50 - ads[z].length; j++) { // ads[arr[0]].start = i; // ads[arr[1]].start = j; // ads[arr[2]].start = k; // checkWatch(ads[arr[0]].start, ads[arr[1]].start, // ads[arr[2]].start); checkWatch(i, j, k); int sum = tinhDiem(); ans = Math.max(ans, sum); } } } } public static int[][] checkWatch(int startQC1, int startQC2, int startQC3) { for (int i = 1; i <= 3; i++) { for (int j = 1; j <= N; j++) { if (startQC1 >= customers[j].timeDen && (startQC1 + ads[i].length) <= customers[j].timeDi) { // update lai tgian con lai de xem quang cao customers[j].timeDen = customers[j].timeDi - startQC1 + ads[i].length; LichTrinh[i][j] = ads[i].point; } if (startQC2 >= customers[j].timeDen && (startQC2 + ads[i].length) <= customers[j].timeDi) { customers[j].timeDen = customers[j].timeDi - startQC2 + ads[i].length; LichTrinh[i][j] = ads[i].point; } if (startQC3 >= customers[j].timeDen && (startQC3 + ads[i].length) <= customers[j].timeDi) { customers[j].timeDen = customers[j].timeDi - startQC3 + ads[i].length; LichTrinh[i][j] = ads[i].point; } } } return LichTrinh; } public static int tinhDiem() { int sum = 0; for (int j = 1; j <= N; j++) { for (int i = 3; i >= 1; i--) { if (LichTrinh[j][i] != 0) { sum = sum + LichTrinh[j][i]; break; } } } return sum; } }
Editor is loading...