コード例 #1
1
ファイル: EmuThread.java プロジェクト: rexut/jkcemu
 public synchronized byte[] getExtendedRAM(int size) {
   byte[] rv = null;
   if (size > 0) {
     if (this.ramExtended != null) {
       if (size > this.ramExtended.length) {
         rv = new byte[size];
         Arrays.fill(rv, (byte) 0);
         System.arraycopy(this.ramExtended, 0, rv, 0, this.ramExtended.length);
         this.ramExtended = rv;
       } else {
         rv = this.ramExtended;
       }
     } else {
       rv = new byte[size];
       Arrays.fill(rv, (byte) 0);
       this.ramExtended = rv;
     }
   }
   return rv;
 }
コード例 #2
0
  int Query() {
    int minimum = 100001;

    visited = new boolean[V];
    Arrays.fill(visited, false);

    depth = new int[V];
    Arrays.fill(depth, -1);

    low = new int[V];
    Arrays.fill(low, -1);

    parent = new int[V];
    Arrays.fill(parent, -1);

    articulationPoints = new TreeMap<Integer, Boolean>();

    getArticulationPoints(0, 0);

    for (Map.Entry<Integer, Boolean> entry : articulationPoints.entrySet()) {
      int i = (int) entry.getKey();
      if (RatingScore[i] < minimum) {
        minimum = RatingScore[i];
      }
    }

    return minimum != 100001 ? minimum : -1;
  }
  public static void main(String[] args) throws Exception {

    /*  BufferedReader br=new BufferedReader(new FileReader("input.txt"));
        BufferedWriter out=new BufferedWriter(new FileWriter("output.txt"));
    */
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 2000);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 2000);
    String[] s = br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    int q = Integer.parseInt(s[1]);
    int num[] = new int[n + 1];
    int[] m = new int[3 * n + 1]; // size = 2*n+1
    Arrays.fill(num, -1);
    s = br.readLine().split(" ");
    for (int i = 1; i <= n; i++) num[i] = Integer.parseInt(s[i - 1]);
    /// build tree
    maketree(1, 1, n, m, num);

    for (int qq = 1; qq <= q; qq++) {
      s = br.readLine().split(" ");
      int i = Integer.parseInt(s[0]);
      int j = Integer.parseInt(s[1]);
      int ans = query(1, 1, n, m, num, i, j);
      out.write("" + num[ans] + "\n");
      out.flush();
    }
  }
コード例 #4
0
ファイル: GIDE.java プロジェクト: rexut/jkcemu
 public synchronized void reset() {
   if (this.debugLevel > 0) {
     System.out.println("GIDE: reset");
   }
   this.pendingCmd = Command.NONE;
   this.resetFlag = false;
   this.ioTaskNoWait = false;
   this.ioTaskThread.interrupt();
   if (this.disks != null) {
     boolean sizeOK = false;
     if ((this.cylinders != null)
         && (this.heads != null)
         && (this.sectorsPerTrack != null)
         && (this.totalSectors != null)) {
       if ((this.cylinders.length >= this.disks.length)
           && (this.heads.length >= this.disks.length)
           && (this.sectorsPerTrack.length >= this.disks.length)
           && (this.totalSectors.length >= this.disks.length)) {
         sizeOK = false;
       }
     }
     if (!sizeOK) {
       this.cylinders = new int[this.disks.length];
       this.heads = new int[this.disks.length];
       this.sectorsPerTrack = new int[this.disks.length];
       this.totalSectors = new long[this.disks.length];
     }
     int maxSectsPerTrack = 0;
     for (int i = 0; i < this.disks.length; i++) {
       this.cylinders[i] = disks[i].getCylinders();
       this.heads[i] = disks[i].getHeads();
       this.sectorsPerTrack[i] = disks[i].getSectorsPerTrack();
       this.totalSectors[i] =
           (long) this.cylinders[i] * (long) this.heads[i] * (long) this.sectorsPerTrack[i];
       if (this.sectorsPerTrack[i] > maxSectsPerTrack) {
         maxSectsPerTrack = this.sectorsPerTrack[i];
       }
     }
     int bufSize = Math.max(maxSectsPerTrack, 1) * SECTOR_SIZE;
     if (this.ioBuf != null) {
       if (this.ioBuf.length < bufSize) {
         this.ioBuf = null;
       }
     }
     if (this.ioBuf == null) {
       this.ioBuf = new byte[bufSize];
     }
   }
   if (this.ioBuf != null) {
     Arrays.fill(this.ioBuf, (byte) 0);
   }
   softReset();
 }
コード例 #5
0
ファイル: GIDE.java プロジェクト: rexut/jkcemu
 private void fireFetchSectors() {
   if ((this.curDisk != null) && (this.curDiskIdx >= 0)) {
     long pos = calcFilePos();
     if (pos < 0) {
       this.errorReg = ERROR_CMD_ABORTED;
       this.statusReg |= STATUS_ERROR;
     } else {
       Arrays.fill(this.ioBuf, (byte) 0xE5);
       File file = this.curDisk.getFile();
       if (file != null) {
         int nSec =
             Math.min(this.sectorsPerTrack[this.curDiskIdx] - this.sectorNum + 1, this.sectorCnt);
         startIOTask(file, pos, nSec * SECTOR_SIZE);
       }
     }
   }
 }
コード例 #6
0
ファイル: EmuThread.java プロジェクト: rexut/jkcemu
 public EmuThread(ScreenFrm screenFrm, Properties props) {
   super("JKCEMU CPU");
   this.screenFrm = screenFrm;
   this.z80cpu = new Z80CPU(this, this);
   this.monitor = "a monitor object for synchronization";
   this.joyFrm = null;
   this.joyThreads = new JoystickThread[2];
   this.ram = new byte[0x10000];
   this.ramExtended = null;
   this.ramFloppy1 = new RAMFloppy();
   this.ramFloppy2 = new RAMFloppy();
   this.printMngr = new PrintMngr();
   this.audioIn = null;
   this.audioOut = null;
   this.loadData = null;
   this.resetLevel = ResetLevel.POWER_ON;
   this.emuRunning = false;
   this.emuSys = null;
   Arrays.fill(this.joyThreads, null);
   applySettings(props);
 }
コード例 #7
0
ファイル: GIDE.java プロジェクト: rexut/jkcemu
  private void execCmdIdentifyDrive() {
    if (this.curDisk != null) {
      Arrays.fill(this.ioBuf, 0, SECTOR_SIZE, (byte) 0);
      setIOBufWord(0, 0x015A);
      setIOBufWord(2, this.curDisk.getCylinders());
      setIOBufWord(6, this.curDisk.getHeads());
      setIOBufWord(8, this.curDisk.getSectorsPerTrack() * SECTOR_SIZE);
      setIOBufWord(10, SECTOR_SIZE);
      setIOBufWord(12, this.curDisk.getSectorsPerTrack());
      setIOBufASCII(20, Main.VERSION, 20);
      setIOBufWord(42, 1); // 1 Sektor Puffer
      setIOBufASCII(46, "JKCEMU", 8);

      String model = this.curDisk.getDiskModel();
      if (model != null) {
        if (model.isEmpty()) {
          model = null;
        }
      }
      if (model == null) {
        model =
            String.format(
                "Sonstige (%dx%dx%d)",
                this.curDisk.getCylinders(),
                this.curDisk.getHeads(),
                this.curDisk.getSectorsPerTrack());
      }
      setIOBufASCII(54, model, 40);
      File file = this.curDisk.getFile();
      if (file != null) {
        if (!file.canWrite()) {
          setIOBufWord(98, 1); // schreibgeschuetzt
        }
      }
      this.ioBufPos = 0;
      this.pendingCmd = Command.IDENTIFY_DISK;
      this.statusReg |= STATUS_DATA_REQUEST;
      fireInterrupt();
    }
  }
コード例 #8
0
  // sieve
  public static int[] primes(int n)
      throws Exception { // for(int i=1;i<=arr.length-1;i++)out.write(""+arr[i]+" ");
    boolean arr[] = new boolean[n + 1];
    Arrays.fill(arr, true);
    for (int i = 1; i <= Math.sqrt(n); i++) {
      if (!arr[i]) continue;
      for (int j = 2 * i; j <= n; j += i) {
        arr[i] = false;
      }
    }
    LinkedList<Integer> ll = new LinkedList<Integer>();
    for (int i = 1; i <= n; i++) {
      if (arr[i]) ll.add(i);
    }
    n = ll.size();

    int primes[] = new int[n + 1];
    for (int i = 1; i <= n; i++) {
      primes[i] = ll.removeFirst();
    }
    return primes;
  }
コード例 #9
0
ファイル: GIDE.java プロジェクト: rexut/jkcemu
 private void writeFormatByte(int value) {
   if ((this.curDisk != null) && (this.curDiskIdx >= 0)) {
     if (this.ioBufPos < SECTOR_SIZE) {
       this.ioBuf[this.ioBufPos++] = (byte) value;
       if (this.ioBufPos == this.ioBuf.length) {
         boolean cmdFinished = true;
         /*
          * Da das verwendete Dateiformat die Sektornummern nicht speichert,
          * muessen diese mit eins beginnen und fortlaufend sein.
          * Nachfolgend wird geprueft, ob diese Bedingung erfuellt ist.
          */
         int spt = this.sectorsPerTrack[this.curDiskIdx];
         boolean[] sectors = new boolean[spt];
         Arrays.fill(sectors, false);
         int ptr = 0;
         boolean err = false;
         for (int i = 0; !err && (i < sectors.length); i++) {
           if ((ptr + 1) < SECTOR_SIZE) {
             // jeweils 1. Byte muss 00 (good sector) sein
             if (this.ioBuf[ptr++] != 0) {
               err = true;
             }
             // jeweils 2. Byte gibt Sektornummer an
             int v = (int) this.ioBuf[ptr++] & 0xFF;
             if (v < sectors.length) {
               if (sectors[v]) {
                 err = true; // Sektornummer zweimal angegeben
               } else {
                 sectors[v] = true;
               }
             } else {
               err = true; // Sktornummer ausserhalb des Bereichs
             }
           } else {
             err = true; // sollte niemals vorkommen
           }
         }
         if (!err) {
           for (int i = 0; i < sectors.length; i++) {
             if (!sectors[i]) {
               err = true; // Sektornummer fehlt
               break;
             }
           }
         }
         if (err) {
           this.errorReg = ERROR_UNCORRECTABLE_DATA;
           this.statusReg |= STATUS_ERROR;
         } else {
           // Sektoren loeschen
           int heads = this.heads[this.curDiskIdx];
           long headNum = this.sdhReg & 0x0F;
           if ((this.cylNum >= 0)
               && (this.cylNum < this.cylinders[this.curDiskIdx])
               && (headNum >= 0)
               && (headNum < heads)) {
             long sectOffs = (this.cylNum * heads * spt) + (headNum * spt);
             startIOTask(
                 this.curDisk.getFile(),
                 0x0100 + (sectOffs * ((long) SECTOR_SIZE)),
                 spt * SECTOR_SIZE);
             cmdFinished = false;
           }
         }
         if (cmdFinished) {
           fireInterrupt();
         }
       }
     }
   }
 }
コード例 #10
0
ファイル: EmuThread.java プロジェクト: rexut/jkcemu
  @Override
  public void run() {
    this.emuRunning = true;
    while (this.emuRunning) {
      try {

        /*
         * Pruefen, ob ein Programm geladen oder der Emulator
         * tatsaechlich zurueckgesetzt werden soll
         */
        LoadData loadData = null;
        synchronized (this.monitor) {
          loadData = this.loadData;
          if (loadData != null) {
            this.loadData = null;
          } else {
            if (this.resetLevel == ResetLevel.POWER_ON) {
              Arrays.fill(this.ram, (byte) 0);
            }
          }
        }
        if (loadData != null) {
          loadData.loadIntoMemory(this);
          this.z80cpu.setRegPC(loadData.getStartAddr());
          if (this.emuSys != null) {
            int spInitValue = this.emuSys.getAppStartStackInitValue();
            if (spInitValue > 0) {
              this.z80cpu.setRegSP(spInitValue);
            }
          }
        } else {
          if ((this.resetLevel == ResetLevel.COLD_RESET)
              || (this.resetLevel == ResetLevel.POWER_ON)) {
            this.z80cpu.resetCPU(true);
          } else {
            this.z80cpu.resetCPU(false);
          }
          if (this.emuSys != null) {
            this.emuSys.reset(this.resetLevel, Main.getProperties());
            this.z80cpu.setRegPC(this.emuSys.getResetStartAddress(this.resetLevel));
          }
        }

        // RAM-Floppies und Druckmanager zuruecksetzen
        this.printMngr.reset();
        this.ramFloppy1.reset();
        this.ramFloppy2.reset();
        if ((this.emuSys != null)
            && (this.resetLevel == ResetLevel.POWER_ON)
            && Main.getBooleanProperty("jkcemu.ramfloppy.clear_on_power_on", false)) {
          if (this.emuSys.supportsRAMFloppy1() && (this.ramFloppy1.getUsedSize() > 0)) {
            this.ramFloppy1.clear();
          }
          if (this.emuSys.supportsRAMFloppy2() && (this.ramFloppy2.getUsedSize() > 0)) {
            this.ramFloppy2.clear();
          }
        }

        // Fenster informieren
        final Frame[] frms = Frame.getFrames();
        if (frms != null) {
          EventQueue.invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  for (Frame f : frms) {
                    if (f instanceof BasicFrm) {
                      ((BasicFrm) f).resetFired();
                    }
                  }
                }
              });
        }

        // in die Z80-Emulation verzweigen
        this.resetLevel = ResetLevel.NO_RESET;
        this.z80cpu.run();
      } catch (Z80ExternalException ex) {
      } catch (Exception ex) {
        this.emuRunning = false;
        EventQueue.invokeLater(new ErrorMsg(this.screenFrm, ex));
      }
    }
  }
コード例 #11
0
ファイル: Main.java プロジェクト: MathBunny/ccc-solutions
  public Main() {
    try {
      in = new BufferedReader(new InputStreamReader(System.in));
      // minimum distance from D to K
      int numCities = nextInt();
      int tradeRoutes = nextInt();
      int[][] adjacencyMatrix = new int[numCities][numCities];
      int[] minDistance = new int[numCities];
      Arrays.fill(minDistance, 100000000);
      // Arrays.fill(adjacencyMatrix, -1);

      // int [] pencilCosts = new int[
      Node[] cities = new Node[numCities];
      for (int x = 0; x < tradeRoutes; x++) {
        int cityA = nextInt() - 1;
        int cityB = nextInt() - 1;
        int cost = nextInt();

        if (cities[cityA] == null) cities[cityA] = new Node(cityA);
        if (cities[cityB] == null) cities[cityB] = new Node(cityB);
        adjacencyMatrix[cityA][cityB] = cost;
        adjacencyMatrix[cityB][cityA] = cost;

        // cities[cityA].routes.add(new Edge(cost, cities[cityB]));
        // cities[cityB].routes.add(new Edge(cost, cities[cityA]));
      }

      int numStores = nextInt();
      int[] pencilCosts = new int[numCities];
      Arrays.fill(pencilCosts, -1);
      for (int x = 0; x < numStores; x++) {
        int ID = nextInt() - 1;
        int cost = nextInt();
        pencilCosts[ID] = cost;
      }
      int destination = nextInt() - 1;
      // if (isGood[destination]){

      // }
      int minCost = 100000000;

      Queue<Node> Q = new LinkedList<Node>();
      // PriorityQueue<Node> Q = new PriorityQueue<Node>();
      minDistance[destination] = 0;
      // cities[destination].distance = 0;
      Q.offer(cities[destination]);
      while (!Q.isEmpty()) {
        Node temp = Q.poll();
        for (int x = 0; x < numCities; x++) {
          if (adjacencyMatrix[temp.ID][x] != 0
              && (minDistance[x] == 100000000
                  || minDistance[x] > minDistance[temp.ID] + adjacencyMatrix[temp.ID][x])) {
            minDistance[x] = minDistance[temp.ID] + adjacencyMatrix[temp.ID][x];
            if (pencilCosts[x] != -1 && minDistance[x] < minCost) {
              // System.out.println(minCost);
              minCost = Math.min(minDistance[x] + pencilCosts[x], minCost);
              Q.offer(cities[x]);
            } else {
              if (pencilCosts[x] == -1) { // why>
                Q.offer(cities[x]);
              }
            }
            // Q.offer(temp.routes.get(x).destination);
          }
        }
      }

      for (int x = 0; x < numCities; x++) {
        if (pencilCosts[x] != -1
            && pencilCosts[x] + minDistance[x] < minCost
            && minDistance[x] != 100000000) {
          minCost = minDistance[x] + pencilCosts[x];
        }
      }
      System.out.println(minCost);

    } catch (IOException e) {
      System.out.println("IO: General");
    }
  }