Skip to content

Commit ad434fa

Browse files
committed
fdsa
1 parent e12ee56 commit ad434fa

File tree

5 files changed

+316
-0
lines changed

5 files changed

+316
-0
lines changed

2dvector.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
vector< vector<int> > field;
7+
8+
int main(void){
9+
field.resize(5);
10+
for (int c = 5; c--;){
11+
field[c].push_back(c);
12+
}
13+
vector<int>::iterator it;
14+
for(int o = 5; o--;){
15+
for(it = field[o].begin(); it != field[o].end(); it++){
16+
cout << *it << endl;
17+
}
18+
}
19+
}

BOARDCOVER.cpp

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
vector< vector<bool> > field;
7+
int nophi;
8+
int width;
9+
10+
const int bType[4][3][2] = {
11+
{ {0, 0}, {0, 1}, {1, 1} },
12+
{ {0, 0}, {1, 0}, {1, 1} },
13+
{ {0, 0}, {1, 0}, {1, -1} },
14+
{ {0, 0}, {0, 1}, {1, 0} }
15+
};
16+
17+
bool isValid(int y, int x){
18+
if (y >= nophi || y < 0 || x >= width || x < 0){
19+
return false;
20+
}
21+
return true;
22+
}
23+
24+
bool isFit(int y, int x, int type){
25+
for(int blk = 0; blk < 3; blk++){
26+
int newY = y + bType[type][blk][0];
27+
int newX = x + bType[type][blk][1];
28+
if (!isValid(newY, newX)){
29+
return false;
30+
}
31+
if (field[newY][newX]){
32+
return false;
33+
}
34+
}
35+
return true;
36+
}
37+
38+
void blockSet(int y, int x, int type){
39+
for(int blk = 0; blk < 3; blk++){
40+
int newY = y + bType[type][blk][0];
41+
int newX = x + bType[type][blk][1];
42+
field[newY][newX] = !field[newY][newX];
43+
}
44+
}
45+
46+
int prob();
47+
48+
int main(void){
49+
int C;
50+
cin >> C;
51+
for(;C--;){
52+
cin >> nophi >> width;
53+
field.clear();
54+
field.resize(nophi);
55+
for(int N = 0; N < nophi; N++){
56+
char data[21];
57+
cin >> data;
58+
field[N].clear();
59+
for(int W = 0; W < width; W++){
60+
if (data[W] == '#'){
61+
field[N].push_back(true);
62+
}
63+
else{
64+
field[N].push_back(false);
65+
}
66+
}
67+
}
68+
cout << prob() << endl;
69+
}
70+
}
71+
72+
void printField(){
73+
for(int N = 0; N < nophi; N++){
74+
cout << endl;
75+
for(int W = 0; W < width; W++){
76+
cout << field[N][W];
77+
}
78+
}
79+
cout << endl;
80+
}
81+
82+
int prob(){
83+
84+
int y = -1, x = -1;
85+
//find upper-leftmost blank position.
86+
for (int yy = 0; yy < nophi; yy++){
87+
for (int xx = 0; xx < width; xx++){
88+
if (!field[yy][xx]){
89+
y = yy;
90+
x = xx;
91+
goto OUT;
92+
}
93+
}
94+
}
95+
OUT:
96+
//base case
97+
if (y == -1 && x == -1){
98+
return 1;
99+
}
100+
int sum = 0;
101+
for(int T = 0; T < 4; T++){
102+
if (isFit(y, x, T)){
103+
blockSet(y, x, T);
104+
sum = sum + prob();
105+
blockSet(y, x, T);
106+
}
107+
}
108+
return sum;
109+
}

BOGGLE.cpp

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <iostream>
2+
#include <string.h>
3+
4+
using namespace std;
5+
6+
const int dx[8] = {-1, -1, -1, 1, 1, 1, 0, 0};
7+
const int dy[8] = {-1, 0, 1, -1, 0, 1, -1, 1};
8+
int D[5][5];
9+
bool deadEnd[10][5][5];
10+
int target[10];
11+
int targetLen;
12+
13+
bool probStart();
14+
void init(){
15+
memset((void*)deadEnd, (int)false, sizeof(bool) * 10 * 5 * 5);
16+
}
17+
18+
int main(void){
19+
int C;
20+
cin >> C;
21+
char data[5][6];
22+
for (;C--;){
23+
for(int row = 0; row < 5; row++){
24+
cin >> data[row];
25+
for(int col = 0; col < 5; col++){
26+
D[row][col] = (int)data[row][col];
27+
}
28+
}
29+
int wordNum;
30+
char word[11];
31+
cin >> wordNum;
32+
for(;wordNum--;){
33+
init();
34+
cin >> word;
35+
targetLen = strlen(word);
36+
for(int strIdx = 0; strIdx < targetLen; strIdx++){
37+
target[strIdx] = (int)word[strIdx];
38+
}
39+
cout << word << ' ' << (probStart() ? "YES" : "NO") << endl;
40+
}
41+
}
42+
return 0;
43+
}
44+
45+
bool prob(int ynext, int xnext, int curLen){
46+
//Exceptional cases.
47+
if (ynext >= 5 || xnext >= 5 || ynext < 0 || xnext < 0){
48+
return false;
49+
}
50+
//DP
51+
if (deadEnd[curLen][ynext][xnext]){
52+
return false;
53+
}
54+
//base case
55+
if (D[ynext][xnext] != target[curLen]){
56+
//dead End, fail to find word.
57+
deadEnd[curLen][ynext][xnext] = true;
58+
return false;
59+
}
60+
else if (curLen + 1 == targetLen){
61+
//successful case, no more calculations needed.
62+
return true;
63+
}
64+
//Recursive
65+
for(int direction = 0; direction < 8; direction++){
66+
if (prob(ynext + dy[direction], xnext + dx[direction], curLen + 1)){
67+
return true;
68+
}
69+
}
70+
deadEnd[curLen][ynext][xnext] = true;
71+
return false;
72+
}
73+
74+
bool probStart(){
75+
for(int Y = 0;Y < 5; Y++){
76+
for(int X = 0;X < 5; X++){
77+
if (prob(Y, X, 0)){
78+
return true;
79+
}
80+
}
81+
}
82+
return false;
83+
}

FESTIVAL.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <vector>
2+
#include <stdio.h>
3+
4+
//FESTIVAL
5+
6+
double prob(void);
7+
8+
int main(void){
9+
int C;
10+
scanf("%d", &C);
11+
for (int i = 0; i < C; i++){
12+
printf("%.11f\n", prob());
13+
}
14+
}
15+
16+
double prob(void){
17+
int N, teams;
18+
scanf("%d %d", &N, &teams);
19+
std::vector<int> priceAcc(N + 1, 0);
20+
priceAcc[0] = 0;
21+
for(int idx = 1; idx < N + 1; idx++){
22+
int curPrice;
23+
scanf("%d", &curPrice);
24+
priceAcc[idx] = priceAcc[idx - 1] + curPrice;
25+
}
26+
double minAva = 101;
27+
short from = 0, ends;
28+
for(; from <= N - teams; from++){
29+
for(ends = from + teams; ends <= N; ends++){
30+
double newAva = (priceAcc[ends] - priceAcc[from]) / (double)(ends - from);
31+
if (minAva > newAva){
32+
minAva = newAva;
33+
}
34+
}
35+
}
36+
return minAva;
37+
}

PICNIC.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int elemCnt;
6+
bool friendData[10][10];
7+
8+
int prob(bool[10]);
9+
10+
void init(){
11+
for(int i = 0; i < 10; i++){
12+
for(int j = 0; j < 10; j++){
13+
friendData[i][j] = false;
14+
}
15+
}
16+
}
17+
18+
int main(void){
19+
int C;
20+
cin >> C;
21+
for(;C--;){
22+
int pcnt;
23+
cin >> elemCnt >> pcnt;
24+
init();
25+
for(;pcnt--;){
26+
int f, s;
27+
cin >> f >> s;
28+
if (f > s){
29+
int tmp = f;
30+
f = s;
31+
s = tmp;
32+
}
33+
friendData[f][s] = true;
34+
//friendData[s][f] = true;
35+
}
36+
bool taken[10] = {false, };
37+
cout << prob(taken) << endl;
38+
}
39+
return 0;
40+
}
41+
42+
int prob(bool taken[10]){
43+
//base case
44+
int firstFree = -1;
45+
for(int idx = 0; idx < elemCnt; idx++){
46+
if (!taken[idx]){
47+
firstFree = idx;
48+
break;
49+
}
50+
}
51+
if (firstFree == -1){
52+
//A single case found.
53+
return 1;
54+
}
55+
//recursive
56+
int sum = 0;
57+
for(int with = firstFree + 1; with < elemCnt; with++){
58+
if (friendData[firstFree][with] && !taken[with]){
59+
//Can be friend.
60+
taken[firstFree] = true;
61+
taken[with] = true;
62+
sum = sum + prob(taken);
63+
taken[firstFree] = false;
64+
taken[with] = false;
65+
}
66+
}
67+
return sum;
68+
}

0 commit comments

Comments
 (0)