示例#1
0
 public static void main(String[] args) {
   String z = in.next();
   int k = in.nextInt();
   int s = in.nextInt() - 1;
   int l = in.nextInt();
   int[] t = new int[l];
   for (int i = 0; i < l; ++i) {
     t[i] = in.nextInt() - 1;
   }
   int[][] f = new int[z.length()][k];
   for (int i = 0; i < k; ++i) {
     for (int j = 0; j < z.length(); ++j) {
       f[j][i] = in.nextInt() - 1;
     }
   }
   boolean[][] g = new boolean[z.length()][k];
   for (int i = 0; i < k; ++i) {
     for (int j = 0; j < z.length(); ++j) {
       g[j][i] = (in.nextInt() == 0);
     }
   }
   DFA dfa = new DFA(z.toCharArray(), k, s, t, f, g);
   int n = in.nextInt();
   out.println(dfa.count(n));
   out.flush();
 }
示例#2
0
文件: c.java 项目: ysyshtc/Codeforces
  void run() {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt(), q = in.nextInt();
    int[] v = new int[n], c = new int[n];
    for (int i = 0; i < n; ++i) v[i] = in.nextInt();
    for (int i = 0; i < n; ++i) c[i] = in.nextInt();

    for (int i = 0; i < q; ++i) {
      int a = in.nextInt(), b = in.nextInt();
      long[] dp = new long[n + 1];
      Node[] heap = new Node[2];
      Arrays.fill(dp, -INF);
      for (int j = 0; j < 2; ++j) heap[j] = new Node(-INF, -1);
      for (int j = 0; j < n; ++j) {
        long val = v[j], maxv = val * b;
        int color = c[j];
        maxv = Math.max(dp[color] + val * a, maxv);
        maxv = Math.max(choose(heap, color) + val * b, maxv);
        dp[color] = Math.max(maxv, dp[color]);
        update(heap, dp[color], color);
      }

      long ret = 0;
      for (int j = 1; j <= n; ++j) ret = Math.max(ret, dp[j]);
      out.println(ret);
    }

    out.close();
  }
 public static void pn(Object... l1) {
   for (int i = 0; i < l1.length; i++) {
     if (i != 0) out.print(' ');
     out.print(l1[i].toString());
   }
   out.println();
 }
 public static void pn(Collection l1) {
   boolean first = true;
   for (Object e : l1) {
     if (first) first = false;
     else out.print(' ');
     out.print(e.toString());
   }
   out.println();
 }
示例#5
0
文件: AOJ0081.java 项目: t8m8/AOJ
  public static void main(String[] args) {
    long start = System.currentTimeMillis();

    while (in.hasNext()) solve();
    out.flush();

    long end = System.currentTimeMillis();
    // trace(end-start + "ms");
    in.close();
    out.close();
  }
示例#6
0
文件: AOJ0034.java 项目: t8m8/AOJ
  public static void main(String[] args) throws Exception {
    long start = System.currentTimeMillis();

    solve();
    out.flush();

    long end = System.currentTimeMillis();
    // trace(end-start + "ms");
    br.close();
    out.close();
  }
示例#7
0
文件: AOJ2739.java 项目: t8m8/AOJ
  public static void main(String[] args) {
    debug = args.length > 0;
    long start = System.nanoTime();

    solve();
    out.flush();

    long end = System.nanoTime();
    dump((end - start) / 1000000 + " ms");
    in.close();
    out.close();
  }
示例#8
0
 boolean solve2() {
   int t = nextInt();
   if (t == 0) return false;
   int n = nextInt();
   Tower[] towers = new Tower[t];
   for (int i = 0; i < t; i++) {
     towers[i] = new Tower(new Point(nextInt(), nextInt()), nextInt());
   }
   n++;
   Point[] p = new Point[n];
   for (int i = 0; i < n; i++) {
     p[i] = new Point(nextInt(), nextInt());
   }
   // System.err.println(Arrays.toString(p));
   ArrayList<Point> points = new ArrayList<Point>();
   double r = 1;
   for (int i = 0; i < n - 1; i++) {
     double dist = p[i].dist(p[i + 1]) - (1 - r);
     int e = (int) Math.floor(dist + 1 - EPS);
     Point v = p[i + 1].subtract(p[i]).norm();
     for (int j = 0; j < e; j++) {
       points.add(p[i].add(v.multiply(j).add(v.multiply(1 - r))));
     }
     r = p[i + 1].dist(points.get(points.size() - 1));
   }
   if (p[n - 1].dist(points.get(points.size() - 1)) > 0.5 - EPS) {
     points.add(p[n - 1]);
   }
   // System.err.println(points);
   char last = 0;
   ArrayList<String> ans = new ArrayList<String>();
   for (int i = 0; i < points.size(); i++) {
     double maxP = Integer.MIN_VALUE;
     char here = 0;
     for (int j = 0; j < t; j++) {
       double w = towers[j].get(points.get(i));
       if (maxP < w - EPS) {
         maxP = w;
         here = (char) (j + 'A');
       }
     }
     if (here != last) {
       ans.add("(" + i + "," + here + ")");
     }
     last = here;
   }
   for (int i = 0; i < ans.size(); i++) {
     if (i != 0) out.print(" ");
     out.print(ans.get(i));
   }
   out.println();
   return true;
 }
示例#9
0
文件: B.java 项目: t8m8/AtCoder
  public static void main(String[] args) {
    debug = args.length > 0;
    long start = System.currentTimeMillis();

    solve();
    out.flush();

    long end = System.currentTimeMillis();
    dump((end - start) + "ms");
    in.close();
    out.close();
  }
  public static void main(String[] args) throws java.lang.Exception {
    // let_me_start

    String s = s();
    String t = s();
    int c[] = new int[150];
    int d[] = new int[150];
    String S = s.toUpperCase();
    String T = t.toUpperCase();
    int C[] = new int[150];
    int D[] = new int[150];

    int n = s.length();
    int m = t.length();

    // int arr[] = is((int)n);

    long ans = 0;
    for (int i = 1; i <= n; i++) {
      c[s.charAt(i - 1)]++;
    }

    for (int i = 1; i <= m; i++) {
      d[t.charAt(i - 1)]++;
    }
    for (int i = 1; i <= n; i++) {
      C[S.charAt(i - 1)]++;
    }

    for (int i = 1; i <= m; i++) {
      D[T.charAt(i - 1)]++;
    }

    int b = 0;
    int min = 1000000000;
    for (int i = 1; i <= 149; i++) {
      b += Math.min(c[i], d[i]);
      d[i] -= Math.min(c[i], d[i]);
    }
    int a = 0;
    min = 1000000000;
    for (int i = 1; i <= 149; i++) {
      a += Math.min(C[i], D[i]);
      D[i] -= Math.min(C[i], D[i]);
    }
    a = a - b;
    out.write("" + b + " " + a + "\n");
    out.flush();
    return;
  }
示例#11
0
文件: b.java 项目: ysyshtc/Codeforces
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
    disjoint = new int[n];
    for (int i = 0; i < n; ++i) disjoint[i] = i;

    for (int i = 0; i <= n - k; ++i) for (int j = 0; j < k; ++j) merge(i + j, i + k - 1 - j);

    long ret = 1;
    for (int i = 0; i < n; ++i) if (disjoint[i] == i) ret = ret * m % MD;
    out.println(ret);
    out.close();
  }
示例#12
0
文件: 433.java 项目: jmankhan/ACM
  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);
  }
示例#13
0
文件: AOJ0034.java 项目: t8m8/AOJ
  static void solve() throws IOException {
    String str;
    while ((str = br.readLine()) != null) {
      String[] s = str.split(",");
      int[] a = new int[10];
      int sum = 0;
      for (int i = 0; i < 10; i++) {
        a[i] = Integer.parseInt(s[i]);
        sum += a[i];
      }

      int v1 = Integer.parseInt(s[10]);
      int v2 = Integer.parseInt(s[11]);

      double r = (double) sum * v1 / (v1 + v2);

      sum = 0;
      for (int i = 0; i < 10; i++) {
        sum += a[i];
        if (r <= sum) {
          out.println((i + 1));
          break;
        }
      }
    }
  }
示例#14
0
  // **********************************************************************************
  //
  // Theoretically, you shouldn't have to alter anything below this point in this file
  //      unless you want to change the color of your agent
  //
  // **********************************************************************************
  public void getConnected(String args[]) {
    try {
      // initial connection
      int port = 3000 + Integer.parseInt(args[1]);
      s = new Socket(args[0], port);
      sout = new PrintWriter(s.getOutputStream(), true);
      sin = new BufferedReader(new InputStreamReader(s.getInputStream()));

      // read in the map of the world
      numNodes = Integer.parseInt(sin.readLine());
      int i, j;
      for (i = 0; i < numNodes; i++) {
        world[i] = new node();
        String[] buf = sin.readLine().split(" ");
        world[i].posx = Double.valueOf(buf[0]);
        world[i].posy = Double.valueOf(buf[1]);
        world[i].numLinks = Integer.parseInt(buf[2]);
        // System.out.println(world[i].posx + ", " + world[i].posy);
        for (j = 0; j < 4; j++) {
          if (j < world[i].numLinks) {
            world[i].links[j] = Integer.parseInt(buf[3 + j]);
            // System.out.println("Linked to: " + world[i].links[j]);
          } else world[i].links[j] = -1;
        }
      }
      currentNode = Integer.parseInt(sin.readLine());

      String myinfo =
          args[2] + "\n" + "0.7 0.45 0.45\n"; // name + rgb values; i think this is color is pink
      // send the agents name and color
      sout.println(myinfo);
    } catch (IOException e) {
      System.out.println(e);
    }
  }
示例#15
0
  public static void main(String[] args) {
    PrintWriter pw;
    Scanner sc;
    try {
      sc = new Scanner(new File("input.txt"));
      BigInteger a, b, c;
      a = sc.nextBigInteger();
      b = sc.nextBigInteger();
      c = a.divide(b);
      // System.out.println(firstTeam+" "+secondTeam);
      pw = new PrintWriter(new File("output.txt"));
      pw.print(c);

      pw.close();
    } catch (IOException e) {
    }
  }
  public static void main(String[] args) throws IOException {
    // in = new BufferedReader(new FileReader("input.txt"));
    // out = new PrintWriter(new FileWriter("output.txt"));
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);

    Main.solve();
    out.close();
    in.close();
  }
示例#17
0
 public void run() {
   try {
     int n = reader.nextInt();
     Point[] points = new Point[n];
     for (int i = 0; i < n; ++i) {
       int x = reader.nextInt();
       int y = reader.nextInt();
       points[i] = new Point(x, y);
     }
     double answer = solve(points);
     for (int i = 0; i < n; ++i) {
       points[i] = points[i].flip();
     }
     answer += solve(points);
     writer.println(String.format("%.8f", answer));
   } catch (IOException ex) {
   }
   writer.close();
 }
  public static void main(String[] args) throws java.lang.Exception {
    // let_me_start
    /*  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
     BufferedReader br=new BufferedReader(new FileReader("input.txt"));
        BufferedWriter out=new BufferedWriter(new FileWriter("output.txt"));
    */

    int n = i();
    int m = i();
    // int arr[] = is((int)n);
    // String ans = "NO";
    long ans = 0;
    for (int i = 1; i <= n; i++) {}

    out.write("" + ans + "\n");
    out.flush();
    return;
  }
示例#19
0
  static void solve() {
    int n = in.nextInt();
    int m = in.nextInt();
    boolean[] p = new boolean[m];
    for (int i = 0; i < n; i++) {
      int x = in.nextInt();
      for (int j = 0; j < x; j++) {
        p[in.nextInt() - 1] = true;
      }
    }

    for (int i = 0; i < m; i++) {
      if (!p[i]) {
        out.println("NO");
        return;
      }
    }

    out.println("YES");
  }
  public static void main(String[] args) throws IOException {
    input = new BufferedReader(new InputStreamReader(System.in));
    output = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    int cases = Integer.parseInt(read());

    for (int i = 0; i < cases; i++) {
      int value = Integer.parseInt(read());

      BigInteger factorial = new BigInteger("" + 1);

      for (int j = value; j >= 1; j--) {
        factorial = factorial.multiply(new BigInteger("" + j));
      }

      output.println(factorial);
    }

    output.close();
  }
示例#21
0
  // You shouldn't need to modify this function
  public void act() {
    int a = selectAction();

    // visit the node if it has positive utility
    String buf;
    int destination = world[currentNode].links[a];
    if (currentUtilitiesforVisitingNodes[destination] > 0) buf = a + " Y\n";
    else buf = a + " N\n";

    System.out.print("Sent: " + buf);
    sout.println(buf);
  }
示例#22
0
文件: Check.java 项目: alexkats/Code
    public void run() {
        try {
            in = new FastScanner(new File(".in"));
            out = new PrintWriter(new File(".out"));

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
示例#23
0
文件: AOJ0081.java 项目: t8m8/AOJ
 static void solve() {
   String[] s = in.next().split(",");
   Point p =
       reflect(
           new Line(
               Double.parseDouble(s[0]),
               Double.parseDouble(s[1]),
               Double.parseDouble(s[2]),
               Double.parseDouble(s[3])),
           new Point(Double.parseDouble(s[4]), Double.parseDouble(s[5])));
   out.println(p.getX() + " " + p.getY());
 }
示例#24
0
 public void run() {
   Locale.setDefault(Locale.US);
   try {
     sc = new FastScanner("access.in");
     out = new PrintWriter("access.out");
     solve();
     sc.close();
     out.close();
   } catch (Throwable e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
示例#25
0
 public void run() {
   // long time = System.currentTimeMillis();
   try {
     br = new BufferedReader(new FileReader(new File("cell.in")));
     out = new PrintWriter("cell.out");
     solve();
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(111);
   }
   // System.err.println(System.currentTimeMillis() - time);
   out.close();
 }
示例#26
0
  public Duder(String args[]) {

    getConnected(args);

    play();

    try {
      sin.close();
      sout.close();
      s.close();
    } catch (IOException e) {
      System.out.println(e);
    }
  }
示例#27
0
 public void save() throws Exception {
   // save out the RSA information
   PrintWriter fileout = new PrintWriter(new FileWriter(AUTHFILE));
   fileout.flush();
   fileout.println(p);
   fileout.println(q);
   fileout.println(n);
   fileout.println(phiN);
   // fileout.println(e);
   // fileout.println(d);
   fileout.println(S);
   fileout.println(V);
   fileout.close();
 }
示例#28
0
 void solve() {
   int n = nextInt();
   HashMap<Long, Integer>[] hm = new HashMap[33];
   for (int i = 0; i < hm.length; i++) {
     hm[i] = new HashMap<Long, Integer>();
   }
   boolean[] allows = new boolean[n];
   for (int i = 0; i < n; i++) {
     String s = nextToken();
     nextToken();
     String ip = nextToken();
     if (ip.indexOf("/") == -1) {
       ip = ip + "/32";
     }
     allows[i] = s.equals("allow");
     int p = ip.indexOf("/");
     String s1 = ip.substring(0, p);
     String s2 = ip.substring(p + 1);
     int e = Integer.parseInt(s2);
     long r = ipToInteger(s1);
     r &= ~((1L << (32 - e)) - 1);
     if (!hm[e].containsKey(r)) hm[e].put(r, i);
     // System.err.println("Query " + i + " = " + r);
   }
   int m = nextInt();
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < m; i++) {
     String ip = nextToken();
     long r = ipToInteger(ip);
     int min = Integer.MAX_VALUE;
     // System.err.println("Cur = " + i);
     for (int j = 0; j <= 32; j++) {
       long e = r;
       e &= ~((1L << (32 - j)) - 1);
       // System.err.println(e + " " + j);
       if (hm[j].containsKey(e)) {
         min = Math.min(min, hm[j].get(e));
       }
     }
     if (min == Integer.MAX_VALUE || allows[min]) {
       sb.append("A");
     } else {
       sb.append("D");
     }
   }
   out.println(sb);
 }
示例#29
0
文件: A.java 项目: jmankhan/ACM
  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);
  }
示例#30
0
文件: A.java 项目: t8m8/AtCoder
  static void solve() {
    int r = in.nextInt();
    int c = in.nextInt();
    int sy = in.nextInt() - 1;
    int sx = in.nextInt() - 1;
    int gy = in.nextInt() - 1;
    int gx = in.nextInt() - 1;
    char[][] t = new char[r][c];
    for (int i = 0; i < r; i++) {
      t[i] = in.next().toCharArray();
    }

    ArrayDeque<int[]> que = new ArrayDeque<>();
    BitSet visited = new BitSet();

    que.add(new int[] {sy, sx, 0});
    visited.set(sy * c + sx);

    int[] dx = {0, 1, 0, -1};
    int[] dy = {1, 0, -1, 0};
    int[][] dist = new int[r][c];

    while (!que.isEmpty()) {
      int[] p = que.pollFirst();
      int cy = p[0];
      int cx = p[1];
      int d = p[2];
      dist[cy][cx] = d;

      for (int i = 0; i < 4; i++) {
        int ny = cy + dy[i];
        int nx = cx + dx[i];
        if (ny < 0 || nx < 0 || r <= ny || c <= nx) continue;
        if (visited.get(ny * c + nx) || t[ny][nx] == '#') continue;
        que.add(new int[] {ny, nx, d + 1});
        visited.set(ny * c + nx);
      }
    }

    out.println(dist[gy][gx]);
  }