2018-02-13 22:59:02 +08:00
<!-- GFM - TOC -->
2018-02-22 14:47:54 +08:00
* [ǰ<EFBFBD> <EFBFBD> ](#ǰ<> <C7B0> )
* [1. С <> <D0A1> -С <> <D0A1> Git ](#1-С <> <D0A1> -С <> <D0A1> git )
* [2. С <> <D0A1> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ](#2-С <> <D0A1> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
* [3. С <> <D0A1> -<2D> й<EFBFBD> ţ<EFBFBD> <C5A3> ](#3-С <> <D0A1> -<2D> й<EFBFBD> ţ<EFBFBD> <C5A3> )
* [4. <> <CEA2> -LUCKY STRING ](#4-<> <CEA2> -lucky-string )
* [5. <> <CEA2> -Numeric Keypad ](#5-<> <CEA2> -numeric-keypad )
* [6. <> <CEA2> -Spring Outing ](#6-<> <CEA2> -spring-outing )
* [7. <> <CEA2> -S-expression ](#7-<> <CEA2> -s-expression )
* [8. <20> <> Ϊ-<2D> <> <EFBFBD> ߷<EFBFBD> <DFB7> Ƕ<EFBFBD> <C7B6> <EFBFBD> ](#8-<2D> <> Ϊ-<2D> <> <EFBFBD> ߷<EFBFBD> <DFB7> Ƕ<EFBFBD> <C7B6> <EFBFBD> )
* [9. <20> <> Ϊ-<2D> <EFBFBD> <F2B5A5B4> <EFBFBD> <EFBFBD> <EFBFBD> ¼ ](#9-<2D> <> Ϊ-<2D> <EFBFBD> <F2B5A5B4> <EFBFBD> <EFBFBD> <EFBFBD> ¼ )
* [10. <20> <> Ϊ-<2D> ˿<EFBFBD> <CBBF> ƴ<EFBFBD> С ](#10-<2D> <> Ϊ-<2D> ˿<EFBFBD> <CBBF> ƴ<EFBFBD> С )
* [11. ȥ<> Ķ<EFBFBD> -<2D> <> <EFBFBD> ֲ<EFBFBD> <D6B2> <EFBFBD> ](#11-ȥ<> Ķ<EFBFBD> -<2D> <> <EFBFBD> ֲ<EFBFBD> <D6B2> <EFBFBD> )
* [12. ȥ<> Ķ<EFBFBD> -<2D> <EFBFBD> <D7B8> ظ<EFBFBD> <D8B8> ַ<EFBFBD> ](#12-ȥ<> Ķ<EFBFBD> -<2D> <EFBFBD> <D7B8> ظ<EFBFBD> <D8B8> ַ<EFBFBD> )
* [13. ȥ<> Ķ<EFBFBD> -Ѱ<> <D1B0> Coder ](#13-ȥ<> Ķ<EFBFBD> -Ѱ<> <D1B0> coder )
* [14. <20> <> <EFBFBD> <EFBFBD> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֵ ](#14-<2D> <> <EFBFBD> <EFBFBD> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֵ )
* [15. <20> <> <EFBFBD> <EFBFBD> -<2D> <> <EFBFBD> ӷ<EFBFBD> ת ](#15-<2D> <> <EFBFBD> <EFBFBD> -<2D> <> <EFBFBD> ӷ<EFBFBD> ת )
* [16. <20> <> <EFBFBD> <EFBFBD> -<2D> ݷ<EFBFBD> ](#16-<2D> <> <EFBFBD> <EFBFBD> -<2D> ݷ<EFBFBD> )
* [17. <20> <> <EFBFBD> <EFBFBD> -ֱ<> <D6B1> ͼ<EFBFBD> <CDBC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ](#17-<2D> <> <EFBFBD> <EFBFBD> -ֱ<> <D6B1> ͼ<EFBFBD> <CDBC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
* [18. <20> <> <EFBFBD> <EFBFBD> -<2D> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ](#18-<2D> <> <EFBFBD> <EFBFBD> -<2D> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
* [19. <20> <> <EFBFBD> <EFBFBD> -ƽ <> <C6BD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ](#19-<2D> <> <EFBFBD> <EFBFBD> -ƽ <> <C6BD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
* [20. <20> ٶ<EFBFBD> -<2D> ﷸת<EFB7B8> <D7AA> ](#20-<2D> ٶ<EFBFBD> -<2D> ﷸת<EFB7B8> <D7AA> )
* [22. <20> ٶ<EFBFBD> -<2D> ü<EFBFBD> <C3BC> <EFBFBD> <EFBFBD> <EFBFBD> ֽ ](#22-<2D> ٶ<EFBFBD> -<2D> ü<EFBFBD> <C3BC> <EFBFBD> <EFBFBD> <EFBFBD> ֽ )
* [23. <20> ٶ<EFBFBD> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ](#23-<2D> ٶ<EFBFBD> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
* [24. <20> ٶ<EFBFBD> -Ģ<> <C4A2> <EFBFBD> <EFBFBD> ](#24-<2D> ٶ<EFBFBD> -Ģ<> <C4A2> <EFBFBD> <EFBFBD> )
2018-02-13 22:59:02 +08:00
<!-- GFM - TOC -->
2018-02-22 14:47:54 +08:00
# ǰ<> <C7B0>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
ʡ<EFBFBD> ԵĴ<EFBFBD> <EFBFBD> 룺
2018-02-13 22:59:02 +08:00
```java
import java.util.*;
```
```java
public class Solution {
}
```
```java
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
}
}
}
```
2018-02-22 14:47:54 +08:00
# 1. С <> <D0A1> -С <> <D0A1> Git
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
- <20> ؽ<EFBFBD> <D8BD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
- ʹ <> <CAB9> LCA
2018-02-13 22:59:02 +08:00
```java
private class TreeNode {
int id;
List< TreeNode > childs = new ArrayList< >();
TreeNode(int id) {
this.id = id;
}
}
public int getSplitNode(String[] matrix, int indexA, int indexB) {
int n = matrix.length;
2018-02-22 14:47:54 +08:00
boolean[][] linked = new boolean[n][n]; // <20> ؽ<EFBFBD> <D8BD> ڽӾ<DABD> <D3BE> <EFBFBD>
2018-02-13 22:59:02 +08:00
for (int i = 0; i < n ; i + + ) {
for (int j = 0; j < n ; j + + ) {
linked[i][j] = matrix[i].charAt(j) == '1';
}
}
TreeNode tree = constructTree(linked, 0);
TreeNode ancestor = LCA(tree, new TreeNode(indexA), new TreeNode(indexB));
return ancestor.id;
}
private TreeNode constructTree(boolean[][] linked, int root) {
TreeNode tree = new TreeNode(root);
for (int i = 0; i < linked [ root ] . length ; i + + ) {
if (linked[root][i]) {
2018-02-22 14:47:54 +08:00
linked[i][root] = false; // <20> <> Ϊ<EFBFBD> <CEAA> Ŀ<EFBFBD> <C4BF> <EFBFBD> <EFBFBD> <EFBFBD> ڽӾ<DABD> <D3BE> <EFBFBD> <EFBFBD> <EFBFBD> ˫<EFBFBD> <CBAB> <EFBFBD> ģ<EFBFBD> <C4A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> <D2AA> <EFBFBD> <EFBFBD> תΪ<D7AA> <CEAA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
tree.childs.add(constructTree(links, i));
}
}
return tree;
}
private TreeNode LCA(TreeNode root, TreeNode p, TreeNode q) {
if (root == null || root.id == p.id || root.id == q.id) return root;
TreeNode ancestor = null;
int cnt = 0;
for (int i = 0; i < root.childs.size ( ) ; i + + ) {
TreeNode tmp = LCA(root.childs.get(i), p, q);
if (tmp != null) {
ancestor = tmp;
cnt++;
}
}
return cnt == 2 ? root : ancestor;
}
```
2018-02-22 14:47:54 +08:00
# 2. С <> <D0A1> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ķ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʊ<EFBFBD> ʾ Ϊ 1 <20> <> <EFBFBD> <EFBFBD> һ λ<D2BB> <CEBB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͬ<EFBFBD> <CDAC> λ<EFBFBD> <CEBB>
2018-02-13 22:59:02 +08:00
```java
public int countBitDiff(int m, int n) {
return Integer.bitCount(m ^ n);
}
```
2018-02-22 14:47:54 +08:00
# 3. С <> <D0A1> -<2D> й<EFBFBD> ţ<EFBFBD> <C5A3>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ⣬<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> һ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> С Ϊ 2 <20> ı <EFBFBD> <C4B1> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
״̬ת<EFBFBD> Ʒ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> £<EFBFBD>
2018-02-13 22:59:02 +08:00
```html
dp[i, j] = max(dp[i, j-1], prices[j] - prices[jj] + dp[i-1, jj]) { jj in range of [0, j-1] } = max(dp[i, j-1], prices[j] + max(dp[i-1, jj] - prices[jj]))
```
```java
public int calculateMax(int[] prices) {
int n = prices.length;
int[][] dp = new int[3][n];
for (int i = 1; i < = 2; i++) {
int localMax = dp[i - 1][0] - prices[0];
for (int j = 1; j < n ; j + + ) {
dp[i][j] = Math.max(dp[i][j - 1], prices[j] + localMax);
localMax = Math.max(localMax, dp[i - 1][j] - prices[j]);
}
}
return dp[2][n - 1];
}
```
2018-02-22 14:47:54 +08:00
# 4. <> <CEA2> -LUCKY STRING
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
- 쳲<> <ECB3B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> п<EFBFBD> <D0BF> <EFBFBD> Ԥ<EFBFBD> <D4A4> <EFBFBD> 㣻
- <20> <> ͷ<EFBFBD> <CDB7> β<EFBFBD> <CEB2> <EFBFBD> <EFBFBD> <EFBFBD> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> Ĺ<EFBFBD> <C4B9> ̣<EFBFBD> ÿһ <C3BF> <D2BB> ѭ<EFBFBD> <D1AD> <EFBFBD> <EFBFBD> ʹ <EFBFBD> <CAB9> һ <EFBFBD> <D2BB> Set <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> i <20> <> j <20> <> <EFBFBD> ֵ<EFBFBD> <D6B5> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Set <20> <> ֤<EFBFBD> <D6A4> <EFBFBD> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> ͬ<EFBFBD> <CDAC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Set <20> Ĵ<EFBFBD> С <EFBFBD> <D0A1> <EFBFBD> Dz<EFBFBD> ͬ<EFBFBD> ַ<EFBFBD> <D6B7> ĸ<EFBFBD> <C4B8> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
Set< Integer > fibSet = new HashSet< >(Arrays.asList(1, 2, 3, 5, 8, 13, 21, 34, 55, 89));
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int n = str.length();
Set< String > ret = new HashSet< >();
for (int i = 0; i < n ; i + + ) {
Set< Character > set = new HashSet< >();
for (int j = i; j < n ; j + + ) {
set.add(str.charAt(j));
int cnt = set.size();
if (fibSet.contains(cnt)) {
ret.add(str.substring(i, j + 1));
}
}
}
String[] arr = ret.toArray(new String[ret.size()]);
Arrays.sort(arr);
for (String s : arr) {
System.out.println(s);
}
```
2018-02-22 14:47:54 +08:00
# 5. <> <CEA2> -Numeric Keypad
2018-02-13 22:59:02 +08:00
```java
private static int[][] canReach = {
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 0
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // 1
{1, 0, 1, 1, 0, 1, 1, 0, 1, 1}, // 2
{0, 0, 0, 1, 0, 0, 1, 0, 0, 1}, // 3
{1, 0, 0, 0, 1, 1, 1, 1, 1, 1}, // 4
{1, 0, 0, 0, 0, 1, 1, 0, 1, 1}, // 5
{0, 0, 0, 0, 0, 0, 1, 0, 0, 1}, // 6
{1, 0, 0, 0, 0, 0, 0, 1, 1, 1}, // 7
{1, 0, 0, 0, 0, 0, 0, 0, 1, 1}, // 8
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1} // 9
};
private static boolean isLegal(char[] chars, int idx) {
if (idx >= chars.length || idx < 0 ) return true ;
int cur = chars[idx] - '0';
int next = chars[idx + 1] - '0';
return canReach[cur][next] == 1;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = Integer.valueOf(in.nextLine());
for (int i = 0; i < T ; i + + ) {
String line = in.nextLine();
char[] chars = line.toCharArray();
for (int j = 0; j < chars.length - 1 ; j + + ) {
while (!isLegal(chars, j)) {
if (--chars[j + 1] < '0') {
chars[j--]--;
}
for (int k = j + 2; k < chars.length ; k + + ) {
chars[k] = '9';
}
}
}
System.out.println(new String(chars));
}
}
```
2018-02-22 14:47:54 +08:00
# 6. <> <CEA2> -Spring Outing
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> N = 3<> <33> K = 4 <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ۡ<EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> ʼ ʱ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 0 <20> <> <EFBFBD> ط<EFBFBD> <D8B7> <EFBFBD> Ϊ<EFBFBD> <CEAA> <EFBFBD> <EFBFBD> <EFBFBD> ص㣬Ҳ<E3A3AC> <D2B2> <EFBFBD> Ǵ<EFBFBD> <C7B4> ڼ<EFBFBD> <DABC>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> ӵ<EFBFBD> 4 <20> <> <EFBFBD> ص㿪ʼ ͶƱ<CDB6> <C6B1> ÿ<EFBFBD> <C3BF> <EFBFBD> <EFBFBD> ֻ<EFBFBD> <D6BB> Ҫ<EFBFBD> Ƚϵ<C8BD> 4 <20> <> <EFBFBD> ط<EFBFBD> <D8B7> ͵<EFBFBD> 0 <20> <> <EFBFBD> ط<EFBFBD> <D8B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> <C8BC> <EFBFBD> <EFBFBD> <EFBFBD> <EFA3AC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ѡ <EFBFBD> <D1A1> <EFBFBD> ˵<EFBFBD> 4 <20> <> <EFBFBD> ط<EFBFBD> <D8B7> <EFBFBD> <EFBFBD> <EFBFBD> ô<EFBFBD> <C3B4> <EFBFBD> µ<EFBFBD> 4 <20> <> <EFBFBD> ط<EFBFBD> <D8B7> <EFBFBD> Ϊ<EFBFBD> <CEAA> <EFBFBD> <EFBFBD> <EFBFBD> ص㡣
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> Ӻ<EFBFBD> <EFBFBD> <EFBFBD> ǰ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ظ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ϲ <EFBFBD> <EFBFBD> 裬<EFBFBD> <EFBFBD> <EFBFBD> ϸ<EFBFBD> <EFBFBD> ´ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ص㣬ֱ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> е ط<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ѿ<EFBFBD> ͶƱ<EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> У <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 0 <20> <> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> Ϊ<EFBFBD> <CEAA> <EFBFBD> <EFBFBD> <EFBFBD> ص㣬<D8B5> <E3A3AC> <EFBFBD> <EFBFBD> Ϊ<EFBFBD> <CEAA> <EFBFBD> <EFBFBD> <EFBFBD> Ļ<EFBFBD> <C4BB> <EFBFBD> 4 <20> <> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> ֻ<EFBFBD> <D6BB> Ҫ<EFBFBD> <D2AA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> <EFBFBD> б Ƚϣ<C8BD> <CFA3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ÿ<EFBFBD> <C3BF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʼ <EEBFAA> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 1 <20> <> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> Ϊ<EFBFBD> <CEAA> <EFBFBD> <EFBFBD> <EFBFBD> ص㣬<D8B5> <E3A3AC> ô<EFBFBD> ڶԵ<DAB6> 2 <20> <> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> <EFBFBD> <EFBFBD> ͶƱʱ<C6B1> <CAB1> ÿ<EFBFBD> <C3BF> <EFBFBD> ˲<EFBFBD> <CBB2> <EFBFBD> Ҫ<EFBFBD> <D2AA> <EFBFBD> ǵ<EFBFBD> 2 <20> <> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> <EFBFBD> <EFBFBD> 1 <20> <> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> <C8BC> <EFBFBD> ҲҪ<D2B2> <D2AA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͶƱ<CDB6> ص<EFBFBD> <D8B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ȼ<EFBFBD> <C8BC> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
int N = in.nextInt();
int K = in.nextInt();
int[][] votes = new int[N][K + 1];
for (int i = 0; i < N ; i + + ) {
for (int j = 0; j < K + 1 ; j + + ) {
int place = in.nextInt();
votes[i][place] = j;
}
}
int ret = 0;
for (int place = K; place > 0; place--) {
int cnt = 0;
for (int i = 0; i < N ; i + + ) {
if (votes[i][place] < votes [ i ] [ ret ] ) {
cnt++;
}
}
if (cnt > N / 2) {
ret = place;
}
}
System.out.println(ret == 0 ? "otaku" : ret);
```
2018-02-22 14:47:54 +08:00
# 7. <> <CEA2> -S-expression
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
# 8. <20> <> Ϊ-<2D> <> <EFBFBD> ߷<EFBFBD> <DFB7> Ƕ<EFBFBD> <C7B6> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
int N = in.nextInt();
int M = in.nextInt();
int[] scores = new int[N];
for (int i = 0; i < N ; i + + ) {
scores[i] = in.nextInt();
}
for (int i = 0; i < M ; i + + ) {
String str = in.next();
if (str.equals("U")) {
int id = in.nextInt() - 1;
int newScore = in.nextInt();
scores[id] = newScore;
} else {
int idBegin = in.nextInt() - 1;
int idEnd = in.nextInt() - 1;
int ret = 0;
if (idBegin > idEnd) {
int t = idBegin;
idBegin = idEnd;
idEnd = t;
}
for (int j = idBegin; j < = idEnd; j++) {
ret = Math.max(ret, scores[j]);
}
System.out.println(ret);
}
}
```
2018-02-22 14:47:54 +08:00
# 9. <20> <> Ϊ-<2D> <EFBFBD> <F2B5A5B4> <EFBFBD> <EFBFBD> <EFBFBD> ¼
2018-02-13 22:59:02 +08:00
```java
HashMap< String , Integer > map = new LinkedHashMap< >();
while (in.hasNextLine()) {
String s = in.nextLine();
String key = s.substring(s.lastIndexOf('\\') + 1);
map.put(key, map.containsKey(key) ? map.get(key) + 1 : 1);
}
List< Map.Entry < String , Integer > > list = new LinkedList< >(map.entrySet());
Collections.sort(list, (o1, o2) -> o2.getValue() - o1.getValue());
for (int i = 0; i < 8 & & i < list . size ( ) ; i + + ) {
String[] token = list.get(i).getKey().split(" ");
String filename = token[0];
String line = token[1];
if (filename.length() > 16) filename = filename.substring(filename.length() - 16);
System.out.println(filename + " " + line + " " + list.get(i).getValue());
}
```
2018-02-22 14:47:54 +08:00
# 10. <20> <> Ϊ-<2D> ˿<EFBFBD> <CBBF> ƴ<EFBFBD> С
2018-02-13 22:59:02 +08:00
```java
public class Main {
private Map< String , Integer > map = new HashMap< >();
public Main() {
map.put("3", 0);
map.put("4", 1);
map.put("5", 2);
map.put("6", 3);
map.put("7", 4);
map.put("8", 5);
map.put("9", 6);
map.put("10", 7);
map.put("J", 8);
map.put("Q", 9);
map.put("K", 10);
map.put("A", 11);
map.put("2", 12);
map.put("joker", 13);
map.put("JOKER ", 14);
}
private String play(String s1, String s2) {
String[] token1 = s1.split(" ");
String[] token2 = s2.split(" ");
CardType type1 = computeCardType(token1);
CardType type2 = computeCardType(token2);
if (type1 == CardType.DoubleJoker) return s1;
if (type2 == CardType.DoubleJoker) return s2;
if (type1 == CardType.Bomb & & type2 != CardType.Bomb) return s1;
if (type2 == CardType.Bomb & & type1 != CardType.Bomb) return s2;
if (type1 != type2 || token1.length != token2.length) return "ERROR";
for (int i = 0; i < token1.length ; i + + ) {
int val1 = map.get(token1[i]);
int val2 = map.get(token2[i]);
if (val1 != val2) return val1 > val2 ? s1 : s2;
}
return "ERROR";
}
private CardType computeCardType(String[] token) {
boolean hasjoker = false, hasJOKER = false;
for (int i = 0; i < token.length ; i + + ) {
if (token[i].equals("joker")) hasjoker = true;
else if (token[i].equals("JOKER")) hasJOKER = true;
}
if (hasjoker & & hasJOKER) return CardType.DoubleJoker;
int maxContinueLen = 1;
int curContinueLen = 1;
String curValue = token[0];
for (int i = 1; i < token.length ; i + + ) {
if (token[i].equals(curValue)) curContinueLen++;
else {
curContinueLen = 1;
curValue = token[i];
}
maxContinueLen = Math.max(maxContinueLen, curContinueLen);
}
if (maxContinueLen == 4) return CardType.Bomb;
if (maxContinueLen == 3) return CardType.Triple;
if (maxContinueLen == 2) return CardType.Double;
boolean isStraight = true;
for (int i = 1; i < token.length ; i + + ) {
if (map.get(token[i]) - map.get(token[i - 1]) != 1) {
isStraight = false;
break;
}
}
if (isStraight & & token.length == 5) return CardType.Straight;
return CardType.Sigal;
}
private enum CardType {
DoubleJoker, Bomb, Sigal, Double, Triple, Straight;
}
public static void main(String[] args) {
Main main = new Main();
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
String s = in.nextLine();
String[] token = s.split("-");
System.out.println(main.play(token[0], token[1]));
}
}
}
```
2018-02-22 14:47:54 +08:00
# 11. ȥ<> Ķ<EFBFBD> -<2D> <> <EFBFBD> ֲ<EFBFBD> <D6B2> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ظ<EFBFBD> Ԫ<EFBFBD> ص<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 飬<EFBFBD> <EFBFBD> <EFBFBD> ֲ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫע<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> 㣺
2018-02-13 22:59:02 +08:00
- if (val < = A[m]) h = m;
2018-02-22 14:47:54 +08:00
- <20> <> Ϊ h <20> ĸ<EFBFBD> ֵΪ m <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> m - 1<> <31> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> while ѭ<> <D1AD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҳ<EFBFBD> <D2B2> Ϊ l < h <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> m - 1 ѭ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϊ l <= h <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
public int getPos(int[] A, int n, int val) {
int l = 0, h = n - 1;
while (l < h ) {
int m = l + (h - l) / 2;
if (val < = A[m]) h = m;
else l = m + 1;
}
return A[h] == val ? h : -1;
}
```
2018-02-22 14:47:54 +08:00
# 12. ȥ<> Ķ<EFBFBD> -<2D> <EFBFBD> <D7B8> ظ<EFBFBD> <D8B8> ַ<EFBFBD>
2018-02-13 22:59:02 +08:00
```java
public char findFirstRepeat(String A, int n) {
boolean[] hasAppear = new boolean[256];
for (int i = 0; i < n ; i + + ) {
char c = A.charAt(i);
if(hasAppear[c]) return c;
hasAppear[c] = true;
}
return ' ';
}
```
2018-02-22 14:47:54 +08:00
# 13. ȥ<> Ķ<EFBFBD> -Ѱ<> <D1B0> Coder
2018-02-13 22:59:02 +08:00
```java
public String[] findCoder(String[] A, int n) {
List< Pair < String , Integer > > list = new ArrayList< >();
for (String s : A) {
int cnt = 0;
String t = s.toLowerCase();
int idx = -1;
while (true) {
idx = t.indexOf("coder", idx + 1);
if (idx == -1) break;
cnt++;
}
if (cnt != 0) {
list.add(new Pair< >(s, cnt));
}
}
Collections.sort(list, (o1, o2) -> (o2.getValue() - o1.getValue()));
String[] ret = new String[list.size()];
for (int i = 0; i < list.size ( ) ; i + + ) {
ret[i] = list.get(i).getKey();
}
return ret;
}
2018-02-22 14:47:54 +08:00
// ţ<> <C5A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <DEB7> <EFBFBD> <EFBFBD> <EFBFBD> javafx.util.Pair<69> <72> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Լ<EFBFBD> ʵ<EFBFBD> <CAB5> һ <EFBFBD> <D2BB> Pair <20> <>
2018-02-13 22:59:02 +08:00
private class Pair< T , K > {
T t;
K k;
Pair(T t, K k) {
this.t = t;
this.k = k;
}
T getKey() {
return t;
}
K getValue() {
return k;
}
}
```
2018-02-22 14:47:54 +08:00
# 14. <20> <> <EFBFBD> <EFBFBD> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֵ
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
̰<EFBFBD> IJ<EFBFBD> <EFBFBD> ԡ<EFBFBD>
2018-02-13 22:59:02 +08:00
```java
public int getDis(int[] A, int n) {
int max = 0;
int soFarMin = A[0];
for (int i = 1; i < n ; i + + ) {
if(soFarMin > A[i]) soFarMin = A[i];
else max = Math.max(max, A[i]- soFarMin);
}
return max;
}
```
2018-02-22 14:47:54 +08:00
# 15. <20> <> <EFBFBD> <EFBFBD> -<2D> <> <EFBFBD> ӷ<EFBFBD> ת
2018-02-13 22:59:02 +08:00
```java
public int[][] flipChess(int[][] A, int[][] f) {
int[][] direction = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
for (int[] ff : f) {
for (int[] dd : direction) {
int r = ff[0] + dd[0] - 1, c = ff[1] + dd[1] - 1;
if(r < 0 | | r > 3 || c < 0 | | c > 3) continue;
A[r][c] ^= 1;
}
}
return A;
}
```
2018-02-22 14:47:54 +08:00
# 16. <20> <> <EFBFBD> <EFBFBD> -<2D> ݷ<EFBFBD>
2018-02-13 22:59:02 +08:00
```java
private Set< String > paths;
private List< Integer > curPath;
public int countPath(int[][] map, int n, int m) {
paths = new HashSet< >();
curPath = new ArrayList< >();
for (int i = 0; i < n ; i + + ) {
for (int j = 0; j < m ; j + + ) {
if (map[i][j] == 1) {
map[i][j] = -1;
int[][] leftRightDirection = {{1, 0}, {-1, 0}};
int[][] topDownDirection = {{0, 1}, {0, -1}};
for (int[] lr : leftRightDirection) {
for (int[] td : topDownDirection) {
int[][] directions = {lr, td};
backtracking(map, n, m, i, j, directions);
}
}
return paths.size();
}
}
}
return 0;
}
private void backtracking(int[][] map, int n, int m, int r, int c, int[][] directions) {
if (map[r][c] == 2) {
String path = "";
for (int num : curPath) {
path += num;
}
paths.add(path);
return;
}
for (int i = 0; i < directions.length ; i + + ) {
int nextR = r + directions[i][0];
int nextC = c + directions[i][1];
if (nextR < 0 | | nextR > = n || nextC < 0 | | nextC > = m || map[nextR][nextC] == -1) continue;
map[nextR][nextC] = map[nextR][nextC] == 2 ? 2 : -1;
curPath.add(nextR);
curPath.add(nextC);
backtracking(map, n, m, nextR, nextC, directions);
curPath.remove(curPath.size() - 1);
curPath.remove(curPath.size() - 1);
map[nextR][nextC] = map[nextR][nextC] == 2 ? 2 : 0;
}
}
```
2018-02-22 14:47:54 +08:00
# 17. <20> <> <EFBFBD> <EFBFBD> -ֱ<> <D6B1> ͼ<EFBFBD> <CDBC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
public int countArea(int[] A, int n) {
int max = 0;
for (int i = 0; i < n ; i + + ) {
int min = A[i];
for (int j = i; j < n ; j + + ) {
min = Math.min(min, A[j]);
max = Math.max(max, min * (j - i + 1));
}
}
return max;
}
```
2018-02-22 14:47:54 +08:00
# 18. <20> <> <EFBFBD> <EFBFBD> -<2D> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> ַ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> С д<EFBFBD> ַ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ַ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 26 <20> <> <EFBFBD> ơ<EFBFBD> <C6A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֵ<EFBFBD> <D6B5> <EFBFBD> <EFBFBD> ı ȽϺ <C8BD> <CFBA> <EFBFBD> ͨ<EFBFBD> <CDA8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ƚϲ <C8BD> ͬ<EFBFBD> <CDAC> <EFBFBD> Ǵ<EFBFBD> <C7B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ҽ <EFBFBD> <D2BD> б Ƚϣ<C8BD> <CFA3> <EFBFBD> <EFBFBD> <EFBFBD> "ac" <20> <> "abc"<22> <> <EFBFBD> ֵ<EFBFBD> <D6B5> <EFBFBD> <EFBFBD> ı ȽϽ<C8BD> <CFBD> <EFBFBD> Ϊ "ac" > "abc"<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ƚϣ<C8BD> <CFA3> <EFBFBD> Ϊ "abc" <20> <> <EFBFBD> <EFBFBD> λ<EFBFBD> <CEBB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ȼ<EFBFBD> <C8BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ַ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ij<EFBFBD> <EFBFBD> ȿ<EFBFBD> <EFBFBD> ܲ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ȣ <EFBFBD> <EFBFBD> <EFBFBD> s1 <20> հ ײ<D5B0> <D7B2> ֺ<EFBFBD> s2 <20> <> Ӧ<EFBFBD> <D3A6> <EFBFBD> ֽ<EFBFBD> <D6BD> б Ƚ<D0B1> ʱ<EFBFBD> <CAB1> Ӧ<EFBFBD> ð<EFBFBD> s1 <20> Ŀհ ײ<D5B0> <D7B2> ֿ<EFBFBD> <D6BF> <EFBFBD> <EFBFBD> <EFBFBD> 'a' <20> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ġ<EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> һ <EFBFBD> <EFBFBD> Ҫע<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ǣ<EFBFBD> s1 <20> <> s2 <20> <> <EFBFBD> <EFBFBD> Ϊ len< sub > i< / sub > <20> <> <EFBFBD> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֻ<EFBFBD> Ƚ<EFBFBD> ǰ<EFBFBD> <C7B0> i <20> <> <EFBFBD> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 'aaa' <20> <> 'bbb' <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϊ 2 <20> ĸ<EFBFBD> <C4B8> <EFBFBD> Ϊ 'aa' <20> <> 'bb' <20> <> <EFBFBD> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> <D2AA> <EFBFBD> Ǻ<EFBFBD> <C7BA> 沿<EFBFBD> ֵ<EFBFBD> <D6B5> ַ<EFBFBD> <D6B7> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> ͳ<EFBFBD> Ƹ<EFBFBD> <EFBFBD> <EFBFBD> ʱ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> len1 <20> <> ʼ һ ֱ<D2BB> <D6B1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϸ<EFBFBD> <CFB7> <EFBFBD> <EFBFBD> ȣ <EFBFBD> ÿ<EFBFBD> <C3BF> ѭ<EFBFBD> <D1AD> <EFBFBD> <EFBFBD> ͳ<EFBFBD> Ƴ<EFBFBD> <C6B3> <EFBFBD> Ϊ i <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ַ<EFBFBD> <D6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
String s1 = in.next();
String s2 = in.next();
int len1 = in.nextInt();
int len2 = in.nextInt();
int len = Math.min(s2.length(), len2);
int[] subtractArr = new int[len];
for (int i = 0; i < len ; i + + ) {
char c1 = i < s1.length ( ) ? s1 . charAt ( i ) : ' a ' ;
char c2 = s2.charAt(i);
subtractArr[i] = c2 - c1;
}
int ret = 0;
for (int i = len1; i < = len; i++) {
for (int j = 0; j < i ; j + + ) {
ret += subtractArr[j] * Math.pow(26, i - j - 1);
}
}
System.out.println(ret - 1);
```
2018-02-22 14:47:54 +08:00
# 19. <20> <> <EFBFBD> <EFBFBD> -ƽ <> <C6BD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
int W = in.nextInt();
double Y = in.nextDouble();
double x = in.nextDouble();
int N = in.nextInt();
while (N-- > 0) {
2018-02-22 14:47:54 +08:00
Y++; // <20> <> Ա<EFBFBD> <D4B1> ÿ<EFBFBD> <C3BF> <EFBFBD> <EFBFBD> <EFBFBD> 䶼Ҫ<E4B6BC> <D2AA> 1
2018-02-13 22:59:02 +08:00
Y += (21 - Y) * x;
}
System.out.println((int) Math.ceil(Y));
```
2018-02-22 14:47:54 +08:00
# 20. <20> ٶ<EFBFBD> -<2D> ﷸת<EFB7B8> <D7AA>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> ֺ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ⣬<EFBFBD> <EFBFBD> ÿ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> IJ<EFBFBD> <EFBFBD> ֺͻ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
int n = in.nextInt();
int t = in.nextInt();
int c = in.nextInt();
int[] values = new int[n];
for (int i = 0; i < n ; i + + ) {
values[i] = in.nextInt();
}
int cnt = 0;
int totalValue = 0;
for (int s = 0, e = c - 1; e < n ; s + + , e + + ) {
if (s == 0) {
for (int j = 0; j < c ; j + + ) totalValue + = values [ j ] ;
} else {
totalValue = totalValue - values[s - 1] + values[e];
}
if (totalValue < = t) cnt++;
}
System.out.println(cnt);
```
2018-02-22 14:47:54 +08:00
# 22. <20> ٶ<EFBFBD> -<2D> ü<EFBFBD> <C3BC> <EFBFBD> <EFBFBD> <EFBFBD> ֽ
2018-02-13 22:59:02 +08:00
```java
int n = in.nextInt();
int minX, minY, maxX, maxY;
minX = minY = Integer.MAX_VALUE;
maxX = maxY = Integer.MIN_VALUE;
for (int i = 0; i < n ; i + + ) {
int x = in.nextInt();
int y = in.nextInt();
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}
System.out.println((int) Math.pow(Math.max(maxX - minX, maxY - minY), 2));
```
2018-02-22 14:47:54 +08:00
# 23. <20> ٶ<EFBFBD> -<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
P ( <20> <> <EFBFBD> ٵ<EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> <EFBFBD> ) = 1 - P ( һ <> <D2BB> Ҳ<EFBFBD> <D2B2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> ӣ<EFBFBD> <EFBFBD> <EFBFBD> ȡ<EFBFBD> <EFBFBD> <EFBFBD> ʾ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʱ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫһ <EFBFBD> <EFBFBD> һ <EFBFBD> н<EFBFBD> <EFBFBD> ж<EFBFBD> ȡ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֱ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> in.nextDouble()<29> <>
2018-02-13 22:59:02 +08:00
```java
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
int m = in.nextInt();
int x = in.nextInt();
int y = in.nextInt();
int t = in.nextInt();
2018-02-22 14:47:54 +08:00
in.nextLine(); // <20> <>
2018-02-13 22:59:02 +08:00
double pcc = 0.0;
double sum = 0.0;
for (int i = 1; i < = n; i++) {
2018-02-22 14:47:54 +08:00
String[] token = in.nextLine().split(" "); // <20> <>
2018-02-13 22:59:02 +08:00
for (int j = 1; j < = m; j++) {
double p = Double.parseDouble(token[j - 1]);
// double p = in.nextDouble();
sum += p;
if (i == x & & j == y) {
pcc = p;
}
}
}
double pss = sum / (n * m);
pcc = computePOfIRT(pcc, t);
pss = computePOfIRT(pss, t);
System.out.println(pcc > pss ? "cc" : pss > pcc ? "ss" : "equal");
System.out.printf("%.2f\n", Math.max(pcc, pss));
}
}
// compute probability of independent repeated trials
private static double computePOfIRT(double p, int t) {
return 1 - Math.pow((1 - p), t);
}
```
2018-02-22 14:47:54 +08:00
# 24. <20> ٶ<EFBFBD> -Ģ<> <C4A2> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> û<EFBFBD> <EFBFBD> ݻᳬʱ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> <EFBFBD> DP<44> <50>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
dp[i][j] <20> <> ʾ <EFBFBD> <CABE> <EFBFBD> <EFBFBD> (i,j) λ<> ò<EFBFBD> <C3B2> ᴥ<EFBFBD> <E1B4A5> Ģ<EFBFBD> <C4A2> <EFBFBD> ĸ<EFBFBD> <C4B8> ʡ<EFBFBD> <CAA1> <EFBFBD> <EFBFBD> <EFBFBD> N\*M <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> i == N || j == M<> <4D> <EFBFBD> <EFBFBD> ô (i,j) ֻ<> <D6BB> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> ƶ<EFBFBD> <C6B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ƶ<EFBFBD> <C6B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2018-02-13 22:59:02 +08:00
2018-02-22 14:47:54 +08:00
<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ¾<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> е <EFBFBD> 3 <20> к͵<D0BA> 3 <20> <> ֻ<EFBFBD> <D6BB> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ƶ<EFBFBD> <C6B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ<EFBFBD> ÿ<EFBFBD> <C3BF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ƶ<EFBFBD> <C6B6> <EFBFBD>
2018-02-13 22:59:02 +08:00
```java
int N = in.nextInt();
int M = in.nextInt();
int K = in.nextInt();
boolean[][] mushroom = new boolean[N][M];
while (K-- > 0) {
int x = in.nextInt();
int y = in.nextInt();
mushroom[x - 1][y - 1] = true;
}
double[][] dp = new double[N][M];
dp[0][0] = 1;
for (int i = 0; i < N ; i + + ) {
for (int j = 0; j < M ; j + + ) {
if (mushroom[i][j]) dp[i][j] = 0;
else {
double cur = dp[i][j];
if (i == N - 1 & & j == M - 1) break;
if (i == N - 1) dp[i][j + 1] += cur;
else if (j == M - 1) dp[i + 1][j] += cur;
else {
dp[i][j + 1] += cur / 2;
dp[i + 1][j] += cur / 2;
}
}
}
}
System.out.printf("%.2f\n", dp[N - 1][M - 1]);
```