Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
3.8 kB
2
Indexable
Never
import java.io.*;
import java.util.*;

import javax.swing.plaf.synth.SynthSplitPaneUI;

public class Main {
    public static int noOfDivaOneRoles = 0;
    public static int noOfDivaTwoRoles = 0;

    public static int d1Index = 0;
    public static int d2Index = 0;

    public static void main(String args[]) throws FileNotFoundException {

        InputStream is = new FileInputStream("testinput.txt");
        // Kattio io = new Kattio(System.in, System.out);
        Kattio io = new Kattio(is, System.out);
        int actorsUsed = 0; // Antal skådespelare som fått roller

        int n = io.getInt(); // Antal roller i problemet.
        int s = io.getInt(); // Antal scener i problemet.
        int k = io.getInt(); // Antal skådespelare i problemet.

        int rolesActors[][] = new int[n][k + 1];
        int scenesRoles[][] = new int[s][n + 1];
        int divaOneRoles[] = new int[n];
        int divaTwoRoles[] = new int[n];

        int sol[][] = new int[n][n + 2]; // Lösningsarray.

        // Fyll 2d array med alla roller och vilka skådisar som kan spela respektive
        // roll.
        int available = 0;
        for (int i = 0; i < n; i++) {
            available = io.getInt();
            rolesActors[i][0] = available;
            for (int j = 1; j <= available; j++) {
                rolesActors[i][j] = io.getInt();
                if (rolesActors[i][j] == 1) {
                    divaOneRoles[noOfDivaOneRoles] = i + 1;
                    noOfDivaOneRoles++;
                } else if (rolesActors[i][j] == 2) {
                    divaTwoRoles[noOfDivaTwoRoles] = i + 1;
                    noOfDivaTwoRoles++;
                }
            }
        }
        // Fyll 2d array med alla scener och vilka roller som är i respektive scen.
        for (int i = 0; i < s; i++) {
            available = io.getInt();
            scenesRoles[i][0] = available;
            for (int j = 1; j <= available; j++) {
                scenesRoles[i][j] = io.getInt();
            }
        }

        if (noOfDivaOneRoles == 1) {
            sol[0][0] = 1;
            sol[0][1] = 1;
            sol[0][2] = divaOneRoles[0];
        }
        if (noOfDivaTwoRoles == 1) {
            sol[1][0] = 2;
            sol[1][1] = 1;
            sol[1][2] = divaTwoRoles[0];
        }

        int d1d2[] = new int[2];

        d1d2 = getDivas(divaOneRoles, divaTwoRoles);

        while (checkDivaScenes(d1d2, scenesRoles)) {
            d1d2 = getDivas(divaOneRoles, divaTwoRoles);
        }

        io.close();
    }

    private static boolean checkDivaScenes(int[] d1d2, int[][] sr) {
        boolean dOneInScene = false;
        boolean dTwoInScene = false;
        for (int i = 0; i < sr.length; i++) {
            for (int j = 1; j <= sr[i][0]; j++) {
                if (sr[i][j] == d1d2[0]) {
                    dOneInScene = true;
                } else if (sr[i][j] == d1d2[1]) {
                    dTwoInScene = true;
                }
                if (dOneInScene == true && dTwoInScene == true) {
                    return true;
                }
            }
            dOneInScene = dTwoInScene = false;
        }
        return false;
    }

    private static int[] getDivas(int[] d1r, int[] d2r) {
        int[] d1d2 = new int[2];
        for (int i = d1Index; i < noOfDivaOneRoles; i++) {
            d1Index++;
            for (int j = d2Index; j < noOfDivaTwoRoles; j++) {
                d2Index++;
                if (d1r[i] != d2r[j]) {
                    d1d2[0] = d1r[i];
                    d1d2[1] = d2r[j];
                    return d1d2;
                }
            }
        }
        return d1d2;

    }
}