2014 ACM/ICPC Asia Regional Anshan Online

hdu 5001 Walk 概率dp
其实就是这么直白,正难则反

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
/** Sep 2, 2015 8:29:38 PM
* PrjName:hdu5001
* @author Semprathlon
*/
import java.io.*;
import java.util.*;

public class Main {

/**
* @param args
*/
static int n, m, d;
static int[] deg;
static int[][] u;
static double[][] f;

static double solve(int x) {
f = new double[d + 1][n + 1];
for (int i = 1; i <= n; i++)
f[0][i] = 1.0 / n;
for (int i = 1; i <= d; i++)
for (int j = 1; j <= n; j++) {
if (j == x)
continue;
for (int k = 1; k <= u[j][0]; k++)
f[i][u[j][k]] += f[i - 1][j] / u[j][0];
}
double ans = 0;
for (int i = 1; i <= n; i++)
if (i != x)
ans += f[d][i];
return ans;
}

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
while (T-- > 0) {
n = in.nextInt();
m = in.nextInt();
d = in.nextInt();
u = new int[n + 1][m + 1];
deg = new int[n + 1];
for (int i = 1; i <= m; i++) {
int x = in.nextInt();
deg[x]++;
int y = in.nextInt();
deg[y]++;
u[x][++u[x][0]] = y;
u[y][++u[y][0]] = x;
}

for (int i = 1; i <= n; i++)
out.println(String.format("%.6f", solve(i)));
}
out.flush();
out.close();
}

}

不知为何,printf+格式字符串会出现莫名的PE

hdu 4998 Rotate

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/** Sep 2, 2015 5:58:24 PM
* PrjName:hdu4998
* @author Semprathlon
*/
import java.io.*;
import java.util.*;

public class Main {

/**
* @param args
*/
final static double eps = 1e-5;
final static double pi = Math.acos(-1.0);

static int dcmp(double d) {
if (Math.abs(d) < eps)
return 0;
return d > 0 ? 1 : -1;
}

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
while (T-- > 0) {
int n = in.nextInt();
Point p1 = new Point(0, 0), q1 = new Point(p1);
Point p2 = new Point(0, 1), q2 = new Point(p2);
for (int i = 1; i <= n; i++) {
double x = in.nextDouble();
double y = in.nextDouble();
double a = in.nextDouble();
q1 = q1.rotate(x, y, a);
q2 = q2.rotate(x, y, a);
}
Vector v1 = new Vector(p1, q1).normal();
Vector v2 = new Vector(p2, q2).normal();
Point o = Vector.GetLineIntersection(Point.mid(p1, q1), v1, Point.mid(p2, q2), v2);
double ans = Vector.angle(o, p1, q1);
if (Vector.cross(new Vector(o, p1), new Vector(o, q1)) < 0)
ans = 2 * pi - ans;
out.printf("%.5f %.5f %.5f\n", o.x, o.y, ans);
}
out.flush();
out.close();
}

static class Point {
double x, y;

Point() {
}

Point(double _x, double _y) {
x = _x;
y = _y;
}

Point(Point p) {
this(p.x, p.y);
}

boolean equals(Point p) {
return dcmp(x - p.x) == 0 && dcmp(y - p.y) == 0;
}

Point add(Point r) {
return new Point(x + r.x, y + r.y);
}

Point sub(Point r) {
return new Point(x - r.x, y - r.y);
}

Point mul(double r) {
return new Point(x * r, y * r);
}

Point move(double dx, double dy) {
return new Point(x + dx, y + dy);
}

Point rotate(double a) {
return new Point(x * Math.cos(a) - y * Math.sin(a), x * Math.sin(a) + y * Math.cos(a));
}

Point rotate(double dx, double dy, double a) {
return this.move(-dx, -dy).rotate(a).move(dx, dy);
}

static Point mid(Point a, Point b) {
return new Point((a.x + b.x) / 2.0, (a.y + b.y) / 2.0);
}
}

static class Vector extends Point {
Vector(double _x, double _y) {
x = _x;
y = _y;
}

Vector(Point a, Point b) {
this(b.x - a.x, b.y - a.y);
}

Vector(Point p) {
this(p.x, p.y);
}

static double angle(Vector a, Vector b) {
return Math.acos(dot(a, b) / a.length() / b.length());
}

static double angle(Point o, Point a, Point b) {
return angle(new Vector(o, a), new Vector(o, b));
}

double dot(Vector r) {
return x * r.x + y * r.y;
}

double cross(Vector r) {
return x * r.y - y * r.x;
}

double length() {
return Math.sqrt(this.dot(this));
}

Vector normal() {
double len = this.length();
return new Vector(-y / len, x / len);
}

static Point GetLineIntersection(Point p, Vector v, Point q, Vector w) {// 求直线交点
Vector u = new Vector(p.sub(q));
double t = cross(w, u) / cross(v, w);
return p.add(v.mul(t));
}

static Point GetLineIntersection(Point p, Point v, Point q, Point w) {
return GetLineIntersection(p, new Vector(v), q, new Vector(w));
}

static Vector add(Vector a, Vector b) {
return new Vector(a.add(b));
}

static double dot(Vector a, Vector b) {
return a.dot(b);
}

static double cross(Vector a, Vector b) {
return a.cross(b);
}

static double cross(Point o, Point a, Point b) {
return cross(new Vector(o, a), new Vector(o, b));
}

static double length(Vector r) {
return r.length();
}
}
}

说得好像很繁的样子

hdu 5000

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
/** Sep 3, 2015 9:43:43 PM
* PrjName:hdu5000
* @author Semprathlon
*/
import java.io.*;
import java.util.*;
public class Main {

/**
* @param args
*/
final static int mod=1000000007;
static int[] a,f;
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
InputReader in=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
int T=in.nextInt();
while(T-->0){
int n=in.nextInt();
int sum=0;
a=new int[n+1];
for(int i=1;i<=n;i++){
a[i]=in.nextInt();
sum+=a[i];
}
sum>>=1;
f=new int[sum+1];
f[0]=1;
for(int i=1;i<=n;i++)
for(int j=sum;j>=0;j--)
for(int k=1;k<=j&&k<=a[i];k++){
f[j]+=f[j-k];
f[j]%=mod;
}
out.println(f[sum]);
}
out.flush();
out.close();
}

}
class InputReader{
public BufferedReader reader;
public StringTokenizer tokenizer;

public InputReader(InputStream stream){
reader = new BufferedReader(
new InputStreamReader(stream), 32768);
tokenizer = null;
}

public String next(){
while(tokenizer == null || !tokenizer.hasMoreTokens()){
try{
tokenizer = new StringTokenizer(
reader.readLine());
}catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}

public int nextInt() {
return Integer.parseInt(next());
}

public long nextLong() {
return Long.parseLong(next());
}

}

非常奇怪,找到sum/2可得最优解这个规律就算是成功了一半了

2014 ACM/ICPC Asia Regional Anshan Online

https://devblog.citruxonve.net/posts/65c4bded/

Author

Semprathlon / Simfae Dean

Posted on

09/02/2015

Updated on

07/19/2023

Licensed under

Comments