Created
December 8, 2011 01:00
-
-
Save hamadu/1445588 to your computer and use it in GitHub Desktop.
Codeforces #96(div2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemA { | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
String line = s.readLine(); | |
for (int i = 0 ; i < line.length() ; i ++) { | |
char x = line.charAt(i); | |
if (x == 'H' || x == 'Q' || x == '9') { | |
System.out.println("YES"); | |
return; | |
} | |
} | |
System.out.println("NO"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemB { | |
public static int[] map; | |
public static long[] prec; | |
public static long MOD = 1000003; | |
public static void main(String[] args) throws IOException { | |
map = new int[512]; | |
map['>'] = 8; | |
map['<'] = 9; | |
map['+'] = 10; | |
map['-'] = 11; | |
map['.'] = 12; | |
map[','] = 13; | |
map['['] = 14; | |
map[']'] = 15; | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
String line = s.readLine(); | |
prec = new long[500]; | |
prec[0] = 1; | |
for (int i = 1 ; i < 500 ; i++) { | |
prec[i] = (prec[i-1] * 16) % MOD; | |
} | |
long value = 0; | |
for (int i = line.length() - 1 ; i >= 0 ; i--) { | |
int x = line.charAt(i); | |
int keta = line.length() - 1 - i; | |
value = (value + map[x] * prec[keta]) % MOD; | |
} | |
value = value % MOD; | |
System.out.println(value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemC { | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
String line = s.readLine(); | |
int prev = 0; | |
for (int i = 0 ; i < line.length() ; i++) { | |
int x = line.charAt(i); | |
String n = Integer.toBinaryString(x); | |
StringBuffer buff = new StringBuffer(n); | |
int addlen = 8 - n.length(); | |
for (int a = 0 ; a < addlen ; a++) { | |
buff.insert(0, "0"); | |
} | |
String revn = buff.reverse().toString(); | |
int value = 0; | |
for (int a = 0 ; a < 8 ; a++) { | |
if (revn.charAt(a) == '1') { | |
value += (1 << (7 - a)); | |
} | |
} | |
int out = (prev - value + 256) % 256; | |
System.out.println(out); | |
prev = value; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemE { | |
public static int NONE = -99999; | |
public static String _line; | |
public static int _n; | |
public static int[][][][] memo; | |
public static int dfs(int l, int c, int d, int now) { | |
if (c > _n) { | |
return NONE; | |
} | |
if (l == _line.length()) { | |
if (c != _n) { | |
return NONE; | |
} | |
return Math.abs(100 - now); | |
} | |
int dd = (d == -1) ? 0 : 1; | |
if (memo[l][c][dd][now] >= 1) { | |
return memo[l][c][dd][now]; | |
} | |
int max = NONE; | |
boolean isforward = (_line.charAt(l) == 'F'); | |
for (int change = 0 ; change <= _n ; change++) { | |
int val = 0; | |
if (change % 2 == 0) { | |
if (isforward) { | |
val = dfs(l+1, c+change, d, now+d); | |
} else { | |
val = dfs(l+1, c+change, -d, now); | |
} | |
} else { | |
if (isforward) { | |
val = dfs(l+1, c+change, -d, now); | |
} else { | |
val = dfs(l+1, c+change, d, now+d); | |
} | |
} | |
max = Math.max(max, val); | |
} | |
memo[l][c][dd][now] = max; | |
return max; | |
} | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
_line = s.readLine(); | |
_n = Integer.valueOf(s.readLine()); | |
memo = new int[101][51][2][201]; | |
System.out.println(dfs(0, 0, 1, 100)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment