Skip to content

Commit a14d826

Browse files
committed
2017年10月26日
1 parent 1c23e64 commit a14d826

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2589
-7
lines changed

.idea/findbugs-idea.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CodeSort.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.ArrayList;
2+
import java.util.Collections;
3+
import java.util.Scanner;
4+
5+
/**
6+
* Created by LXF on 2017/8/15.
7+
*/
8+
public class CodeSort {
9+
public static void main(String[] args) {
10+
Scanner scanner = new Scanner(System.in);
11+
int n = scanner.nextInt();
12+
ArrayList<String> arrayLists = new ArrayList<>();
13+
while (n-->0) {
14+
arrayLists.add(scanner.next());
15+
}
16+
Collections.sort(arrayLists);
17+
for (String arrayList : arrayLists) {
18+
System.out.println(arrayList);
19+
}
20+
}
21+
}

src/Dche.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import java.util.HashMap;
2+
import java.util.Iterator;
3+
import java.util.Map;
4+
5+
/**
6+
* Created by LXF on 2017/8/11.
7+
*/
8+
public class Dche {
9+
public static int qTime(int taxiNum, int[] heng, int[] zong, Point gs, int wt, int tt) {
10+
11+
HashMap<Point, Integer> taxi = new HashMap<Point, Integer>();
12+
int n = heng.length;
13+
int zouLu = (Math.abs(gs.x) + Math.abs(gs.y)) * wt;
14+
if (n == 0) {
15+
return (wt > tt ? tt : wt) * (gs.x + gs.y);
16+
}
17+
for (int i = 0; i < n; i++) {
18+
Point point = new Point(heng[i], zong[i]);
19+
taxi.put(point, 0);
20+
}
21+
22+
Iterator map = taxi.entrySet().iterator();
23+
while (map.hasNext()) {
24+
Map.Entry entry = (Map.Entry) map.next();
25+
Point point = (Point) entry.getKey();
26+
int zouD = (Math.abs(point.x) + Math.abs(point.y)) * wt;
27+
int dacheD = Math.abs((gs.x-point.x) + Math.abs(gs.y-point.y)) * tt;
28+
entry.setValue(Math.min(zouLu, zouD + dacheD));
29+
}
30+
int min = Integer.MAX_VALUE;
31+
Iterator iter = (Iterator) taxi.values();
32+
while (iter.hasNext()) {
33+
int d = (int) iter.next();
34+
min = Math.min(min, d);
35+
}
36+
return min;
37+
}
38+
39+
40+
static class Point{
41+
int x;
42+
int y;
43+
44+
public Point(int x, int y) {
45+
this.x = x;
46+
this.y = y;
47+
}
48+
}
49+
50+
public static void main(String[] args) {
51+
// Scanner scanner = new Scanner(System.in);
52+
// int n = scanner.nextInt();
53+
// String[] h = scanner.nextLine().toCharArray().toString().split(" ");
54+
// String[] z = scanner.nextLine().toCharArray().toString().split(" ");
55+
// int x = scanner.nextInt();
56+
// int y = scanner.nextInt();
57+
Point gs = new Point(-4, -2);
58+
int[] heng = new int[]{-2,-2};
59+
int[] zong = new int[]{0,-2};
60+
//
61+
// for (int i = 0;i<n;i++) {
62+
// heng[i] = Integer.parseInt(h[i]);
63+
// zong[i] = Integer.parseInt(z[i]);
64+
// }
65+
// int w = scanner.nextInt();
66+
// int t = scanner.nextInt();
67+
68+
int n = 2;
69+
70+
System.out.println(qTime(n, heng, zong, gs, 15, 3));
71+
}
72+
73+
}

src/Main.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Created by LXF on 2017/8/10.
3+
*/
4+
import java.util.Scanner;
5+
6+
public class Main {
7+
8+
/** 请完成下面这个函数,实现题目要求的功能 **/
9+
/** 当然,你也可以不按照这个模板来作答,完全按照自己的想法来 ^-^ **/
10+
// static int maxScore(int[] score) {
11+
// int[] max = new int[score.length];
12+
// for(int i=0;i<score.length;i++) {
13+
// if (score[i]!=0) {
14+
// if (i - 1 < 0 || score[i] == 0||score[i+1]>) {
15+
// int left = 1;
16+
// }
17+
// }
18+
// }
19+
//
20+
// }
21+
static int maxScore(int[] score) {
22+
int n = score.length;
23+
int[] nums = new int[n + 2];
24+
for (int i = 0; i < n; i++)
25+
nums[i + 1] = score[i];
26+
nums[0] = nums[n + 1] = 1;
27+
int[][] alibaba = new int[n + 2][n + 2];
28+
for (int k = 1; k <= n; k++) {
29+
for (int i = 1; i <= n - k + 1; i++) {
30+
int j = i + k - 1;
31+
for (int x = i; x <= j; x++) {
32+
alibaba[i][j] = Math.max(alibaba[i][j], alibaba[i][x - 1] + nums[i - 1] * nums[x] * nums[j + 1] + alibaba[x + 1][j]) ;
33+
}
34+
}
35+
}
36+
return alibaba[1][n];
37+
}
38+
public static void main(String[] args){
39+
Scanner in = new Scanner(System.in);
40+
int res;
41+
42+
int _score_size = 0;
43+
_score_size = Integer.parseInt(in.nextLine().trim());
44+
int[] _score = new int[_score_size];
45+
int _score_item;
46+
for(int _score_i = 0; _score_i < _score_size; _score_i++) {
47+
_score_item = Integer.parseInt(in.nextLine().trim());
48+
_score[_score_i] = _score_item;
49+
}
50+
51+
res = maxScore(_score);
52+
System.out.println(String.valueOf(res));
53+
54+
}
55+
}

src/Main1.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import org.junit.Test;
2+
3+
import java.util.*;
4+
5+
/**
6+
* Created by LXF on 2017/8/12.
7+
*/
8+
public class Main1 {
9+
10+
public List<List<Integer>> subsets(int[] nums) {
11+
List<List<Integer>> list = new ArrayList<>();
12+
Arrays.sort(nums);
13+
backtrack(list, new ArrayList<>(), nums, 0);
14+
return list;
15+
}
16+
17+
void backtrack(List<List<Integer>> list , List<Integer> tempList, int [] nums, int start) {
18+
list.add(new ArrayList<>(tempList));
19+
for (int i = start; i < nums.length; i++) {
20+
tempList.add(nums[i]);
21+
backtrack(list, tempList, nums, i + 1);
22+
tempList.remove(tempList.size() - 1);
23+
}
24+
}
25+
26+
@Test
27+
public void test() {
28+
List<List<Integer>> result = subsets(new int[]{1, 2, 3, 4});
29+
System.out.println(result);
30+
}
31+
}

src/Main10.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Created by LXF on 2017/8/15.
3+
*/
4+
public class Main10 {
5+
public static void main(String[] args) {
6+
int[] array = new int[]{0, 1, 2, 3, 4, 5};
7+
int n = array.length;
8+
int[] isdel = new int[n];
9+
int k = 0;
10+
for (int i = 0; ; i = (i+1) % n) {
11+
if (isdel[i] == 0) {
12+
k++;
13+
}
14+
if (k == 3) {
15+
isdel[i]=1;
16+
k=0;
17+
if (getSum(isdel) == n-1) {
18+
break;
19+
}
20+
}
21+
}
22+
for (int i = 0; i < n; i++) {
23+
if (isdel[i] == 0) {
24+
System.out.println(i);
25+
}
26+
}
27+
}
28+
29+
public static int getSum(int[] a) {
30+
int sum = 0;
31+
for (int i : a) {
32+
sum += i;
33+
}
34+
return sum;
35+
}
36+
}

src/Main11.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.Serializable;
2+
import java.util.Scanner;
3+
4+
/**
5+
* Created by LXF on 2017/8/15.
6+
*/
7+
public class Main11 implements Serializable {
8+
public static int get(int n) {
9+
if (n < 2) {
10+
return 0;
11+
}
12+
if (n == 2) {
13+
return 1;
14+
}
15+
int k = n / 3;
16+
return k + get(n % 3+k);
17+
}
18+
19+
public static void main(String[] args) {
20+
Scanner scanner = new Scanner(System.in);
21+
int[] n = new int[10];
22+
for (int i = 0; i < 10; i++) {
23+
int c;
24+
if ((c=scanner.nextInt()) != 0) {
25+
n[i] = c;
26+
} else {
27+
break;
28+
}
29+
}
30+
31+
for (int i = 0; i < n.length; i++) {
32+
if (n[i] != 0) {
33+
if (n[i] < 2) {
34+
System.out.println(0);
35+
} else {
36+
System.out.println(get(n[i]));
37+
}
38+
}
39+
}
40+
}
41+
}

src/Main12.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import java.util.ArrayList;
2+
import java.util.Scanner;
3+
4+
public class Main12 {
5+
static private final int POINT_NUM = 9;
6+
static private int[][] e = new int[Integer.MAX_VALUE/20000][Integer.MAX_VALUE/20000];
7+
8+
9+
static ArrayList<Integer> trace=new ArrayList<Integer>();
10+
static boolean hasCycle=false;
11+
12+
public static void main(String[] args) {
13+
Scanner scanner = new Scanner(System.in);
14+
String str = scanner.nextLine();
15+
String[] s = str.split(",");
16+
System.out.println(s.length);
17+
18+
MouldeIsCycularDependecy(0);
19+
if(!hasCycle)
20+
System.out.println("No Cycle.");
21+
}
22+
23+
static void AddDependency(int mId, int dId) {
24+
e[mId][dId] = 1;
25+
}
26+
27+
static boolean MouldeIsCycularDependecy(int v) {
28+
int j;
29+
if((j=trace.indexOf(v))!=-1) {
30+
hasCycle=true;
31+
return hasCycle;
32+
}
33+
trace.add(v);
34+
35+
for(int i=0;i<POINT_NUM;i++)
36+
{
37+
if(e[v][i]==1)
38+
MouldeIsCycularDependecy(i);
39+
}
40+
trace.remove(trace.size()-1);
41+
if (trace.size() == 1) {
42+
return hasCycle;
43+
}
44+
return hasCycle;
45+
}
46+
}

src/Main2.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Created by LXF on 2017/8/12.
5+
*/
6+
public class Main2 {
7+
8+
public static int getMaxNum(String str) {
9+
int max = 0;
10+
int i = 0;
11+
while (i+1 < str.length()) {
12+
int count = 0;
13+
int j = i;
14+
while (j+1 < str.length()) {
15+
if (str.charAt(j) - str.charAt(j + 1) != 0) {
16+
j++;
17+
count++;
18+
}
19+
else
20+
break;
21+
}
22+
max = Math.max(max, count+1);
23+
i = j+1;
24+
}
25+
return max;
26+
}
27+
28+
public static void main(String[] args) {
29+
Scanner scanner = new Scanner(System.in);
30+
String string = scanner.nextLine();
31+
System.out.println(getMaxNum(string));
32+
}
33+
}

0 commit comments

Comments
 (0)