// int frame = 0; public void paint(Graphics g) { // System.out.println("frame: " + (frame++)); lStatus.setText( "t = " + df.format(md.dt * md.step) + ", " + "N = " + md.N + ", " + "E/N = " + df.format(md.E / md.N) + ", " + "U/N = " + df.format(md.U / md.N) + ", " + "K/N = " + df.format(md.K / md.N) + ", " + "p = " + df.format(md.p) + ";"); tAvK.setText(df.format(md.avK.getAve() / md.N) + " "); tAvU.setText(df.format(md.avU.getAve() / md.N) + " "); tTemp.setText(df.format((2 * md.K) / (3 * (md.N - 1))) + " "); tAvp.setText(df.format(md.avp.getAve()) + " "); canvas.refresh(md.getXWrap(), md.N, true, false); cpnl.repaint(); spnl.repaint(); try { PrintWriter wavefunc = new PrintWriter(new FileOutputStream(new File("energyData.txt"), true)); wavefunc.print(md.E / md.N + " " + md.K / md.N + " " + md.U / md.N); wavefunc.println(); wavefunc.close(); } catch (IOException ex) { } try { PrintWriter tempwriter = new PrintWriter(new FileOutputStream(new File("tempData.txt"), true)); tempwriter.print(df.format((2 * md.K) / (3 * (md.N - 1)))); tempwriter.println(); tempwriter.close(); } catch (IOException ex) { } }
public void solve() throws Exception { int x = sc.nextInt(); int y = sc.nextInt(); StringBuilder sb = new StringBuilder(); String p = null; String m = null; if (x >= 0) { p = "E"; m = "W"; } else { p = "W"; m = "E"; } x = abs(x); for (int i = 0; i < x; i++) { sb.append(m + p); } if (y >= 0) { p = "N"; m = "S"; } else { p = "S"; m = "N"; } y = abs(y); for (int i = 0; i < y; i++) { sb.append(m + p); } out.println(sb); }
public void solve() throws Exception { int n = in.nextInt(); int[] a = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); sum += a[i]; } sum /= 2; boolean[] dp = new boolean[sum + 1]; dp[0] = true; for (int tmp : a) { for (int i = sum; i >= tmp; i--) { if (dp[i - tmp]) { dp[i] = true; } } } String ans = dp[sum] ? "YES" : "NO"; out.println(ans); }
public void solve() throws Exception { long a = in.nextLong(); long b = in.nextLong(); long ans = 0; while (a != 0 && b != 0) { if (a > b) { ans += a / b; a = a % b; } else { ans += b / a; b = b % a; } } out.println(ans); }
void solve() throws IOException { n = ni(); k = ni(); w = new int[n]; c = new int[n]; for (int i = 0; i < n; ++i) { w[i] = ni(); c[i] = ni(); } for (int i = 0; i < list.length; i++) { list[i] = new ArrayList<Integer>(); } for (int i = 0; i < n; ++i) { weight[w[i]]++; list[w[i]].add(c[i]); } for (int i = 0; i < list.length; i++) { Collections.sort(list[i]); } int ret = count(); out.println(ret + " " + calc(ret)); }
public void solve() throws Exception { String str = in.readLine(); int n = str.length(); int t = Integer.parseInt(in.readLine()); int[][] dp = new int[26][n]; dp[str.charAt(0) - 'a'][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < 26; j++) { if (str.charAt(i) == 'a' + j) { dp[j][i] = dp[j][i - 1] + 1; } else { dp[j][i] = dp[j][i - 1]; } } } while (t-- > 0) { st = new StringTokenizer(in.readLine()); char a = st.nextToken().toCharArray()[0]; char b = st.nextToken().toCharArray()[0]; int l = parseInt(st.nextToken()) - 1; int r = parseInt(st.nextToken()) - 1; int ans = 0; for (int i = l; i <= r; i++) { if (str.charAt(i) == a) { ans += dp[b - 'a'][r] - dp[b - 'a'][i]; } } out.println(ans); } }
public void solve() throws Exception { n = in.nextInt(); m = in.nextInt(); graph = new char[n][m]; cracked = new boolean[n][m]; for (int i = 0; i < n; i++) { graph[i] = in.next().trim().toCharArray(); } sx = in.nextInt() - 1; sy = in.nextInt() - 1; gx = in.nextInt() - 1; gy = in.nextInt() - 1; cracked[sx][sy] = true; if (sx == gx && sy == gy) { if (graph[sx][sy] == 'X') {} } int scount = 0; for (int i = 0; i < 4; i++) { int nx = sx + dx[i]; int ny = sy + dy[i]; if (nx < 0 || nx > n - 1 || ny < 0 || ny > m - 1) { continue; } if (graph[nx][ny] == '.') { scount++; } } int gcount = 0; for (int i = 0; i < 4; i++) { int nx = gx + dx[i]; int ny = gy + dy[i]; if (nx < 0 || nx > n - 1 || ny < 0 || ny > m - 1) { continue; } if (graph[nx][ny] == '.') { gcount++; } } boolean isNeighbors = false; for (int i = 0; i < 4 && !isNeighbors; i++) { int nx = sx + dx[i]; int ny = sy + dy[i]; if (nx < 0 || nx > n - 1 || ny < 0 || ny > m - 1) { continue; } if (nx == gx && ny == gy) { isNeighbors = true; } } if (sx == gx && sy == gy) { if (graph[sx][sy] == 'X') { if (scount >= 1) { out.println("YES"); } else { out.println("NO"); } } else { if (scount >= 2) { out.println("YES"); } else { out.println("NO"); } } } else if (isNeighbors) { if (graph[gx][gy] == 'X') { out.println("YES"); } else { if (gcount >= 1) { out.println("YES"); } else { out.println("NO"); } } } else if (dfs(sx, sy)) { if (graph[gx][gy] == 'X') { out.println("YES"); } else { if (gcount >= 2) { out.println("YES"); } else { out.println("NO"); } } } else { out.println("NO"); } }
public void nextTimeStep() { births = 0; deaths = 0; // for (int i=0;i<o2perTS;i++) iterateOxygen(); // oh dear iterateCells(); radiotherapy = false; stem_cells_this_TS = 0; // counter to track population dynamics non_stem_cells_this_TS = 0; // counter to track population dynamics // NEW int totalCells = 0; int totalHealthy = 0; int totalStem = 0; int totalProgenitor = 0; int totalMature = 0; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) if (Cells[i][j] < 4) { totalCells++; if (Cells[i][j] == 0) totalHealthy++; else if (Cells[i][j] == 1) totalStem++; else if (Cells[i][j] == 2) totalProgenitor++; else if (Cells[i][j] == 3) totalMature++; else System.err.println("wrong cell type"); } // Not so new if (timestep == 0) System.out.println( +size + ", " + mutfreq + ", " + lengthGenome + ", " + asymmetricRatio); // print (parent,child) pair // System.out.println ("% Timestep\t Cells\t Stem Cells \t Progenitor\t Mature"); if (timestep % dataReportStep == 0) { // System.out.println(timestep+"\t"+totalCells+"\t"+totalStem+"\t"+totalProgenitor+"\t"+totalMature+"\t"+births+"\t"+deaths+"\t"+((float)births/deaths)); // System.err.println(asymmetricRatio+" "+maxProDivisions+" "+totalCells+" "+totalStem);} // System.err.println(mutationNum+" "+totalStem); } timestep++; // Finally let's write down the data if ((timestep % dataWriteStep == 0) && (timestep > dataWriteStartTime)) { try { File dir = new File("./text"); dir.mkdir(); // cell matrix FileWriter outFile1 = new FileWriter("./text/cells" + timestep); PrintWriter outCells = new PrintWriter(outFile1); // attempt at hashtable // FileWriter outFileHm = new FileWriter("./text/pairs"+timestep); // new // PrintWriter outTable = new PrintWriter(outFileHm); // new // carriedGenome // FileWriter outFilecG = new FileWriter("./text/genomes"+timestep); // new // PrintWriter outcG = new PrintWriter(outFilecG); // new // attempt at hashtable // FileWriter outFileHm2 = new FileWriter("./text/timepairs"+timestep); // new // PrintWriter outTable2 = new PrintWriter(outFileHm2); // new // oxygen matrix // FileWriter outFile2 = new FileWriter("./text/oxygen"+timestep); // PrintWriter outO2 = new PrintWriter(outFile2); // stem age matrix // FileWriter outFile3 = new FileWriter("./text/stemBirthCounter"+timestep); // PrintWriter outSBC = new PrintWriter(outFile3); // carried mutation matrix FileWriter outFile2 = new FileWriter("./text/carriedmutation" + timestep); PrintWriter outCM = new PrintWriter(outFile2); /* // stem total birth matrix //FileWriter outFile4 = new FileWriter("./text/stemBirthsTotal"+timestep); //PrintWriter outSBM = new PrintWriter(outFile4); // stem death matrix //FileWriter outFile5 = new FileWriter("./text/stemDeathCounter"+timestep); //PrintWriter outSD = new PrintWriter(outFile5); // TAC birth matrix //FileWriter outFile6 = new FileWriter("./text/TACBirthCounter"+timestep); //PrintWriter outTB = new PrintWriter(outFile6); // TAC death matrix //FileWriter outFile7 = new FileWriter("./text/TACDeathCounter"+timestep); //PrintWriter outTD = new PrintWriter(outFile7); //write hashtable for (Integer key : tree.keySet()) { outTable.print(+key+", "+tree.get(key)+"\r\n"); } //new outTable.println(""); //new outTable.close(); //new //write hashtable for (Integer value : tree.valueSet()) { outTableNew.print(+tree.get(value)+", "+value+"\r\n"); } //new outTableNew.println(""); //new outTableNew.close(); //new //write hashtable for (Integer key : timeTree.keySet()) { outTable2.print(+key+", "+timeTree.get(key)+"\r\n"); } //new outTable2.println(""); //new outTable2.close(); //new */ for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { outCells.print(Cells[i][j] + ", "); // outcG.print(carriedGenome[i][j]+", "); // outO2.print(Oxygen[i][j]+", "); // outSBC.print(stemBirthCounter[i][j]+", "); outCM.print(carriedmutation[i][j] + ", "); // outSBM.print(stemBirthsTotal[i][j]+", "); // outSD.print(stemDeathCounter[i][j]+", "); // outTB.print(TACBirthCounter[i][j]+", "); // outTD.print(TACDeathCounter[i][j]+", "); } outCells.println(""); // outcG.println(""); outCM.println(""); // outO2.println(""); // outSBC.println(""); // outSBM.println(""); // outSD.println(""); // outTB.println(""); // outTD.println(""); } outCells.close(); // outcG.close(); outCM.close(); // outO2.close(); // outSBC.close(); // outSBM.close(); // outSD.close(); // outTB.close(); // outTD.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } } }
public void println(Object... objects) { print(objects); writer.println(); }