Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

阅读全文

Codeforces Round 479 (Div. 3) 宣布一下我转C++了

D - Divide by three, multiply by two
待更

C - Less or Equal
又卡输入输出。。连续卡了好几次,我再也不想写JAVA了。。
看不到图是RP问题
C++代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <bits/stdc++.h>
using namespace std;
#define N 200010
int* vec;
void mat(int num){
if(num>1000000000){
printf("-1");
}else{
printf("%d",num);
}
}
int main(){
int n;int k;
scanf("%d %d",&n,&k);
vec=new int[n];
for(int i=0;i<n;i++){
scanf("%d",&vec[i]);
}
sort(vec,vec+n);
int num;
if(k==0)num=1;
else num=vec[k-1];
if(n<=k) mat(num);
else if(num<vec[k]) mat(num);
else mat(-1);
return 0;
}

阅读全文

安全编程 笔记一

###第0章 绪论
安全策略集SD3: 设计安全(Security by Design)、默认安全(Security by Default)、部署安全(Security by Deployment)

基于SD3的安全法则:从错误中吸取教训;尽可能缩小攻击面;采用安全的默认设置;纵深防御;使用最小特权;向下兼容总是不安全的;假设外部系统总是不安全的;失败的应对计划;失败时进入安全模式;安全特性不等于安全的特性;绝不要将安全仅维系于隐匿;不要将代码与数据混在一起;正确地解决安全。

阅读全文

Codeforces Round 478 (Div. 2)

体会:如果内存不超,最好还是先把输入存起来,会比较快。o(=•ェ•=)m
依稀记得系统中断什么的

When Who Problem Lang Verdict Time Memory
1
2
3
4
5
6

这是先全部输入再处理
37902235 2018-05-05 12:56:07 miaodzz C - Valhalla Siege Java 8 Time limit exceeded on test 26 2000 ms 20800 KB

这是一边输入一边处理
37902210 2018-05-05 12:54:46 miaodzz C - Valhalla Siege Java 8 Accepted 1855 ms 20800 KB

阅读全文

Educational Codeforces Round 42 (Rated for Div. 2)

962A Equator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.*;
public class Main962A {
public static Scanner sc=new Scanner(System.in);
public static void main(String[] args){
int n=sc.nextInt();
long[] sum=new long[n+1];
//考虑1
sum[1]=sc.nextInt();
for(int i=2;i<=n;i++){
sum[i]=sum[i-1]+sc.nextInt();
}
long cnt=(sum[n]+1)/2;
int i=0;
while(sum[i]<cnt){
i++;
}
//考虑最后一个数比一半大
//如果最后一个数很大,会停在那一个大的
System.out.println(i);


}
}

阅读全文

Codeforces Round 475 (Div. 2) 964

第一次实际参赛,只做出第一题。。好吧,第二题没看懂题目,第三题超时

964A Splits
所有能出现的weight值,都考虑为 [weight个大数,1…..1]就行了
所以就全都设为[weight个2,大量的1]就好了

1
2
3
4
5
6
7
8
9
10
11
import java.util.*;
public class Main964A {
public static Scanner sc=new Scanner(System.in);
public static Set<Integer> map=new HashSet<Integer>();
public static void main(String[] args){
int n=sc.nextInt();
int ans=n/2+1;
System.out.println(ans);

}
}

阅读全文

PAT甲级1002

在2和4测试点上卡了七八次…

终于发现了一些玄学错误点

题目:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1002. A+B for Polynomials (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
This time, you are supposed to find A+B where A and B are two polynomials.

Input

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 100 <= NK < ... < N2 < N1 <=1000.

Output

For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

Sample Input
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output
3 2 1.5 1 2.9 0 3.2

阅读全文

开始刷poj和pat

poj刷题指南:

OJ上的一些水题(可用来练手和增加自信) 
(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 
初期: 
一.基本算法:  

阅读全文

CSP第十三次 260分

第一题

import java.util.*;

public class Main {
    public static void main(String[] args) {

阅读全文

csp17124 dijkstra

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.*;

public class Csp17124 {
public static double dist[];// 当前到i走了多少小道。
public static double exp[];// 1到i的劳累度
public static boolean visited[];// 是否已经过
public static double Max = Integer.MAX_VALUE;
private static List<LinkedList<Edge1>> list = new ArrayList<LinkedList<Edge1>>();// 邻接表

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int n = sc.nextInt();// 路口数
int m = sc.nextInt();// 道路数

for (int i = 0; i < n + 1; i++) {
list.add(new LinkedList<Edge1>());
}
dist = new double[n + 1];// 当前到i走了多少小道。
exp = new double[n + 1];// 1到i的劳累度
visited = new boolean[n + 1];// 是否已经过

int lexp = 0;
int t, a, b;
double len;
for (int i = 1; i <= m; i++) {

t = sc.nextInt();
a = sc.nextInt();
b = sc.nextInt();
len = sc.nextInt();
list.get(a).push(new Edge1(t, a, b, len));
list.get(b).push(new Edge1(t, b, a, len));
}

Arrays.fill(exp, Max);
Arrays.fill(dist, 0);
Arrays.fill(visited, false);

dist[1] = 0;
exp[1] = 0;
visited[1] = true;
int now = 1;

while (!visited[n]) {// 只要n没被访问就一直走
// 加边
double tmpexp = Max;

// System.out.println("now=" + now + " ");
for (Edge1 edge : list.get(now)) {
int i = edge.end;
if (visited[i])
continue;

if (edge.xiaodao == 1) {
tmpexp = exp[now] - Math.pow(dist[now], 2) + Math.pow(dist[now] + edge.len, 2);
if (tmpexp < exp[i]) {
dist[i] = dist[now] + edge.len;
exp[i] = tmpexp;
// System.out.println("修改"+i+"的exp为"+exp[i]+"
// 修改dist为"+dist[i]);
}
} else {
tmpexp = exp[now] + edge.len;
if (exp[now] + edge.len < exp[i]) {
dist[i] = 0;
exp[i] = tmpexp;
// System.out.println("修改"+i+"的exp为"+exp[i]);
}
}

}

lexp = 0;
for (int i1 = 1; i1 <= n; i1++) {
if (!visited[i1] && exp[i1] < exp[lexp]) {
lexp = i1;
}
}
if (lexp == 0)
break;
now = lexp;
visited[now] = true;

}

System.out.print((long) exp[n]);

}

}

class Edge1 {
public int xiaodao = 1;
public double len;
public int start;
public int end;

public Edge1(int xiaodao, int start, int end, double len) {
this.xiaodao = xiaodao;
this.start = start;
this.end = end;
this.len = len;
}
}

阅读全文