Skip to content

Commit a4a7844

Browse files
committed
BZOJ folder added
1 parent 0517230 commit a4a7844

File tree

10 files changed

+525
-0
lines changed

10 files changed

+525
-0
lines changed

SGU/253.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* SGU 253: Theodore Roosevelt
3+
* Computational Geometry: whether a point lies in an ORDERED (counter-clockwise) convex polygon
4+
*
5+
* Created on: 2012-3-31
6+
* Author: shuo
7+
*/
8+
9+
#include <cstdio>
10+
#include <cmath>
11+
#include <algorithm>
12+
using namespace std;
13+
14+
const double eps = 1e-15;
15+
const int N = 100010;
16+
inline int _sign(double x) { return x > eps ? 1 : (fabs(x) < eps ? 0 : -1); }
17+
18+
struct Point { double x, y;}cv[N];
19+
double xmult (Point O, Point A, Point B) {
20+
return ((A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x));
21+
}
22+
23+
inline bool online (Point t, Point A, Point B) {
24+
return t.x >= min (A.x, B.x) && t.x <= max (A.x, B.x) && t.y >= min (A.y, B.y) && t.y <= max (A.y, B.y);
25+
}
26+
27+
// Points are listed counter-clockwisely, all points are distinct.
28+
bool insidePolygon (const Point cv[], int n, const Point A) {
29+
if (_sign(xmult (cv[0], cv[1], A)) < 0) return false;
30+
if (_sign(xmult (cv[0], cv[n-1], A)) > 0) return false;
31+
int up = n - 1, low = 1;
32+
while (up > low) {
33+
int mid = (up + low) >> 1;
34+
if (_sign(xmult (cv[0], A, cv[mid]) >= 0)) up = mid;
35+
else low = mid + 1;
36+
}
37+
if (up == 1 && !online (A, cv[0], cv[1]) ) return false;
38+
return _sign (xmult (A, cv[up - 1], cv[up])) >= 0;
39+
}
40+
41+
int main ()
42+
{
43+
int i, n, m, q;
44+
scanf ("%d%d%d", &n, &m, & q);
45+
for (i = 0; i < n; i++)
46+
scanf ("%lf%lf", &cv[i].x, &cv[i].y);
47+
int ans = 0;
48+
for (; m; m--) {
49+
Point tmp;
50+
scanf ("%lf%lf", &tmp.x, &tmp.y);
51+
if (insidePolygon (cv, n, tmp))
52+
ans++;
53+
}
54+
return ans >= q ? printf ("YES\n") : printf ("NO\n"), 0;
55+
}
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+

SGU/374.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.math.BigInteger;
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Solution {
6+
7+
8+
public static void main(String[] args) {
9+
Scanner in = new Scanner (new BufferedInputStream (System.in));
10+
int a, b, k;
11+
a = in.nextInt(); b = in.nextInt(); k = in.nextInt();
12+
BigInteger x = BigInteger.valueOf(a + b);
13+
System.out.print(x.pow(k));
14+
15+
}
16+
17+
}

SGU/508.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
public class Solution {
5+
6+
public static void main (String [] args) {
7+
Scanner in = new Scanner (new BufferedInputStream (System.in));
8+
long C[][] = new long [51][51];
9+
int n, l1, l2, rho;
10+
n = in.nextInt ();
11+
l1 = in.nextInt ();
12+
l2 = in.nextInt ();
13+
rho = in.nextInt ();
14+
int a = 0, d, b = 0, i, j;
15+
16+
for (i = 0; i <= 50; ++i) {
17+
C[i][i] = 1;
18+
C[i][0] = 1;
19+
}
20+
for (i = 1; i <= 50; ++i)
21+
for (j = 1; j < i; ++j)
22+
C[i][j] = C[i-1][j] + C[i-1][j-1];
23+
24+
boolean flag = false;
25+
for (d = 1; !flag && d <= n + 1; ++d) {
26+
for (a = 0; a <= n && a + d - 1 <= n; ++a){
27+
b = a + d - 1;
28+
double nu = 0, de = 0;
29+
for (int x = l1; x <= n - l2; ++x) {
30+
if (x >= a && x <= b)
31+
nu += C[x][l1] * C[n-x][l2];
32+
de += C[x][l1] * C[n-x][l2];
33+
}
34+
if (nu * 100 >= rho * de) {
35+
flag = true;
36+
break;
37+
}
38+
}
39+
}
40+
System.out.printf("%d %d\n", a, b);
41+
}
42+
43+
}
44+

SGU/515.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#include <cstdio>
2+
#include <queue>
3+
#include <set>
4+
#include <vector>
5+
#include <cstring>
6+
#include <algorithm>
7+
8+
using namespace std;
9+
10+
const int N = 100010;
11+
const int M = 2 * N;
12+
int dis[N], pre[N], pe[N], last[N];
13+
bool ped[N], yy[N];
14+
int to[M], w[M], nxt[M], id[M];
15+
int en, eb[N];
16+
int n, m, nn;
17+
18+
void adde (int x, int y, int t, int d) {
19+
to[en] = y; w[en] = t; nxt[en] = eb[x]; id[en] = d;
20+
eb[x] = en ++;
21+
22+
to[en] = x; w[en] = t; nxt[en] = eb[y]; id[en] = d;
23+
eb[y] = en ++;
24+
}
25+
26+
void Dijkstra (int s) {
27+
int i, j, k;
28+
memset (dis, 0x7f, sizeof (dis));
29+
memset (last, 0, sizeof (last));
30+
memset (ped, false, sizeof (ped));
31+
dis[0] = -1; dis[s] = 0; pe[s] = 0; pre[s] = 0;
32+
priority_queue <pair<pair<int,int> , int> > pq;
33+
pq.push (make_pair(make_pair (0, 0), s));
34+
35+
int cnt = 0;
36+
while (!pq.empty () && cnt < n) {
37+
pair<pair<int,int>,int> hd = pq.top ();
38+
pq.pop ();
39+
i = hd.second;
40+
if (ped[i]) continue;
41+
else {
42+
ped[i] = true;
43+
cnt ++;
44+
}
45+
if (yy[i]) last[i] = i;
46+
for (int e = eb[i]; e != -1; e = nxt[e]) {
47+
j = to[e];
48+
if (dis[i] + w[e] < dis[j] || (dis[i] + w[e] == dis[j] && dis[last[i]] > dis[last[j]])) {
49+
dis[j] = dis[i] + w[e];
50+
last[j] = last[i];
51+
pre[j] = i; pe[j] = id[e];
52+
pq.push (make_pair (make_pair(-dis[j], dis[last[j]]), j));
53+
}
54+
}
55+
}
56+
}
57+
58+
void output (int x) {
59+
if (pe[x] == 0) {
60+
return;
61+
}
62+
output (pre[x]);
63+
printf ("%d ", pe[x]);
64+
}
65+
66+
67+
int a[N];
68+
69+
70+
int main () {
71+
int i, j, k;
72+
en = 0;
73+
memset (eb, -1, sizeof (eb));
74+
75+
scanf ("%d%d", &n, &m);
76+
for (int cnt = 1; cnt <= m; ++cnt) {
77+
scanf ("%d%d%d", &i, &j, &k);
78+
adde (i, j, k, cnt);
79+
}
80+
scanf ("%d", &nn);
81+
for (i = 1; i <= nn; ++i) {
82+
scanf ("%d", &a[i]);
83+
yy[a[i]] = true;
84+
}
85+
Dijkstra (a[1]);
86+
int sc, ma = -1;
87+
for (i = 1; i <= nn; ++i) if (dis[a[i]] > ma) {
88+
ma = dis[a[i]];
89+
sc = a[i];
90+
}
91+
Dijkstra (sc);
92+
int des; ma = -1;
93+
for (i = 1; i <= nn; ++i) if (dis[a[i]] > ma) {
94+
ma = dis[a[i]];
95+
des = a[i];
96+
}
97+
j = des; k = 0;
98+
while (j != sc) {j = pre[j]; k++;}
99+
printf ("%d\n", k);
100+
output (des); printf ("\n");
101+
return 0;
102+
}
103+
104+
105+
106+
107+
108+

SGU/518.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* 518.cpp
3+
*
4+
* Created on: Jul 11, 2012 5:17 pm, Accepted 5:28 pm
5+
* Author: shuo
6+
*/
7+
8+
#include <cstdio>
9+
#include <algorithm>
10+
11+
using namespace std;
12+
13+
const int N = 210;
14+
15+
int a[N][N], n;
16+
int b[N], m;
17+
bool d[N][N];
18+
bool st[N];
19+
20+
void DFS (int x, int y) {
21+
d[x][y] = true;
22+
if (y == m + 1) {
23+
st[x] = true;
24+
return;
25+
}
26+
for (int i = 1; i <= n; ++i) {
27+
if (a[x][i] == b[y] && !d[i][y+1]) {
28+
DFS (i, y + 1);
29+
}
30+
}
31+
}
32+
33+
int main () {
34+
int i, j, k;
35+
scanf ("%d", &n);
36+
for (i = 1; i <= n; ++i)
37+
for (j = 1; j <= n; ++j)
38+
scanf ("%d", &a[i][j]);
39+
scanf ("%d", &m);
40+
for (i = 1; i <= m; ++i)
41+
scanf ("%d", &b[i]);
42+
DFS (1, 1);
43+
int ans = 0;
44+
for (i = 1; i <= n; ++i) if (st[i])
45+
++ans;
46+
printf ("%d\n", ans);
47+
for (i = 1, j = 0; i <= n; i++) if (st[i]) {
48+
++ j;
49+
printf ("%d%c", i, j == ans ? '\n' : ' ');
50+
}
51+
return 0;
52+
}
53+
54+
55+
56+
57+

SGU/523.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Solution {
5+
public static void main (String args[]) {
6+
int i, j, k, n, cur;
7+
int [] a = new int [101];
8+
boolean [] st = new boolean [101];
9+
boolean [] pos = new boolean [101];
10+
Scanner in = new Scanner (new BufferedInputStream (System.in));
11+
n = in.nextInt(); cur = in.nextInt ();
12+
for (i = 1; i <= n; ++i) {
13+
a[i] = in.nextInt ();
14+
st[i] = false;
15+
}
16+
for (i = 1; i <= n; ++i) {
17+
Arrays.fill (pos, false);
18+
for (j = 1; j <= n && st[j]; ++j);
19+
if (j == n + 1) break;
20+
for (k = 1; k <= n; ++k) if (!st[k]) {
21+
if (a[k] > cur && a[k] < a[j] || a[k] > a[j] && a[k] < cur) {
22+
pos[a[k]] = true;
23+
st[k] = true;
24+
}
25+
}
26+
if (a[j] > cur) {
27+
for (k = 1; k <= 100; ++k)
28+
if (pos[k])
29+
System.out.printf ("%d ", k);
30+
}
31+
else {
32+
for (k = 100; k >= 1; --k)
33+
if (pos[k])
34+
System.out.printf ("%d ", k);
35+
}
36+
System.out.printf ("%d ", a[j]);
37+
cur = a[j]; st[j] = true;
38+
}
39+
System.out.println();
40+
}
41+
}

0 commit comments

Comments
 (0)