Skip to content

Commit 3ac5899

Browse files
committed
template skiplist
1 parent 603ef7a commit 3ac5899

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

poj/volume-20/2918.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <iostream>
2+
#include <stdio.h>
3+
4+
using namespace std;
5+
6+
char b[9][10];
7+
8+
bool check(int x, int y){
9+
int i, j ;
10+
for(i = 0 ; i < 9 ; ++ i){
11+
if(i != y && b[x][i] == b[x][y] ) return false;
12+
if(i != x && b[i][y] == b[x][y] ) return false;
13+
}
14+
for(i = 0 ; i < 3 ; ++ i){
15+
for(j = 0 ; j < 3 ; ++ j){
16+
int si = i + x / 3 * 3 , sj = j + y / 3 * 3 ;
17+
if( !(si == x && sj == y) && b[si][sj] == b[x][y])
18+
return false;
19+
}
20+
}
21+
return true;
22+
}
23+
24+
void dfs(int t){
25+
if(t >= 9 * 9 ) {
26+
for(int i = 0 ; i < 9 ; ++ i){
27+
for(int j = 0 ; j < 9 ; ++ j)
28+
putchar(b[i][j]);
29+
putchar('\n');
30+
}
31+
putchar('\n');
32+
return ;
33+
}
34+
int x = t / 9 , y = t % 9 ;
35+
if(b[x][y] != '0'){
36+
dfs(t+1);
37+
return ;
38+
}
39+
for(int i = 1 ; i <= 9 ; ++ i){
40+
b[x][y] = i + '0' ;
41+
if(check(x,y))
42+
dfs(t + 1);
43+
b[x][y] = '0' ;
44+
}
45+
}
46+
47+
int main(){
48+
int n;
49+
while(scanf("%d", &n) != EOF && n){
50+
for(int i = 0 ; i < n ; ++ i){
51+
for(int k = 0 ; k < 9 ; ++ k){
52+
scanf("%s", b[k]);
53+
}
54+
printf("Scenario #%d:\n", i + 1);
55+
dfs(0);
56+
}
57+
}
58+
return 0 ;
59+
}

poj/volume-20/2926.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
#include <math.h>
3+
#include <time.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
using namespace std;
8+
9+
#define MAXN 100005
10+
11+
int n ;
12+
double a[MAXN][5] ;
13+
14+
int main(){
15+
int x , y, check;
16+
double l , r , mid;
17+
scanf("%d", &n);
18+
srand(time(NULL));
19+
for(int i = 0 ; i < n ; ++ i){
20+
for(int j = 0 ; j < 5 ; ++ j)
21+
scanf("%lf", &a[i][j]);
22+
}
23+
l = 0.0 ; r = 1e20;
24+
for(int i = 0 ; i < 100 ; ++ i){
25+
mid = (l + r ) / 2.0;
26+
check = true;
27+
for(int k = 0 ; check && k < 100000 ; ++ k){
28+
x = rand() % n ;
29+
y = rand() % n ;
30+
double sum = 0 ;
31+
for(int j = 0 ; j < 5 ; ++j)
32+
sum += fabs(a[x][j] - a[y][j]);
33+
if(sum > mid){
34+
check = false;
35+
}
36+
}
37+
if(check){
38+
r = mid;
39+
}else{
40+
l = mid;
41+
}
42+
}
43+
printf("%0.2lf\n", mid);
44+
return 0;
45+
}

poj/volume-20/2973.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <iostream>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
using namespace std;
6+
7+
#define MAXN 1005
8+
9+
int n, hit[MAXN];
10+
char s[MAXN][8], t[8], cur[8];
11+
12+
13+
bool streq(char *pattern, char *target){
14+
while(*pattern && *target){
15+
if(*pattern == '_' || *pattern == *target){
16+
pattern ++ ;
17+
target ++ ;
18+
}else{
19+
return false;
20+
}
21+
}
22+
if(*target == '\0') return true;
23+
return false;
24+
}
25+
26+
27+
void calc(){
28+
for(int i = 0 ; i < n ; ++ i)
29+
if( 0 == hit[i] && streq(cur, s[i]) ){
30+
hit[i] = 1;
31+
}
32+
}
33+
34+
void dfs(int i){
35+
if(i >= strlen(cur)){
36+
calc();
37+
}
38+
for(int k = i ; k < strlen(cur); ++ k){
39+
swap(cur[i], cur[k]);
40+
dfs(i+1);
41+
swap(cur[i], cur[k]);
42+
}
43+
}
44+
45+
46+
int main(){
47+
int ans = 0 ;
48+
while(scanf("%d", &n)!= EOF && n){
49+
for(int i = 0 ; i < n ; ++ i){
50+
scanf("%s", s[i]);
51+
}
52+
scanf("%s", t);
53+
memset(hit, 0, sizeof(hit));
54+
strcpy(cur, t);
55+
dfs(0);
56+
ans = 0 ;
57+
for(int i = 0 ;i < n ; ++ i)
58+
ans += hit[i];
59+
printf("%d\n", ans);
60+
}
61+
return 0 ;
62+
}

0 commit comments

Comments
 (0)