Codeforce #384 Div2 A~C
問題
codeforces.com
・Hackされた
考察
・0か1しかない。
・なので、AとBが同じcompanyを示すなら0,そうでない場合は0と1は必ず隣接するため1になる
ソースコード
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; public class A { int N,A,B; String s; public void solve() { N = nextInt(); A = nextInt() - 1; B = nextInt() - 1; s = next(); if(s.charAt(A) == s.charAt(B)){ out.println(0); }else{ out.println(1); } } public static void main(String[] args) { out.flush(); new A().solve(); out.close(); } /* Input */ private static final InputStream in = System.in; private static final PrintWriter out = new PrintWriter(System.out); private final byte[] buffer = new byte[2048]; private int p = 0; private int buflen = 0; private boolean hasNextByte() { if (p < buflen) return true; p = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) return false; return true; } public boolean hasNext() { while (hasNextByte() && !isPrint(buffer[p])) { p++; } return hasNextByte(); } private boolean isPrint(int ch) { if (ch >= '!' && ch <= '~') return true; return false; } private int nextByte() { if (!hasNextByte()) return -1; return buffer[p++]; } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = -1; while (isPrint((b = nextByte()))) { sb.appendCodePoint(b); } return sb.toString(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
考察
・愚直にstepごとに数列を書きなぐってみると同一の数字ごとに一定の間隔で現れることがなんとなくわかった。
・あとは1からNまでの数値を試していき、Kがその間隔にマッチするかをみていく
ソースコード
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; public class B { int N; long K; public void solve() { N = nextInt(); K = nextLong(); if(K % 2 == 1){ out.println(1); return; } for(int i = 1;i < N;i++){ long a = K - ((1L << i)); long b = (1L << (i + 1)); if(a % b == 0){ out.println(i + 1); break; } } } public static void main(String[] args) { out.flush(); new B().solve(); out.close(); } }
考察
・
・
・
・
・
・
・
やっとこどふぉのC理解した気がする。
— tookunn (@tookunn_1213) 2016年12月15日
2/n = 1/n + 1/n , 1/n = 1/x = 1/y + 1/z , ってことは1/yは1/nより小さいから仮に1/y = 1/(n+1)とすると1/z = 1/n(n+1)になるってことか
ソースコード
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; public class C { int N; public void solve() { N = nextInt(); if(N == 1){ out.println(-1); return; } long x = N; long y = N + 1; long z = (long)N * (N + 1); out.println(x + " " + y + " " + z); } public static void main(String[] args) { out.flush(); new C().solve(); out.close(); } }