Skip to content

Commit 4367bf4

Browse files
committed
add more
1 parent d48544e commit 4367bf4

39 files changed

+240699
-25
lines changed

.DS_Store

6 KB
Binary file not shown.

cf/105/a.out

9.8 KB
Binary file not shown.

cf/105/div2_D.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <iostream>
2+
#include <iomanip>
3+
4+
5+
using namespace std;
6+
7+
8+
const int MAXN = 1001;
9+
double dp[MAXN][MAXN][2];
10+
const double INF = 999999999.99;
11+
int white, black;
12+
13+
14+
double get_ans(int w, int b, int who){
15+
if(dp[w][b][who]!=INF){
16+
return dp[w][b][who];
17+
}
18+
if(w>0 && b<=0){
19+
return 1.0;
20+
}
21+
if(w<=0 || w+b<=0){
22+
return 0.0;
23+
}
24+
double w_prob = w*1.0/(w+b);
25+
if(who==0){
26+
double res = w_prob;
27+
res += (1-w_prob)*(1-get_ans(w,b-1,1-who));
28+
dp[w][b][who] = res;
29+
return res;
30+
}else{
31+
double res = w_prob;
32+
33+
//take one black out
34+
int cur_b = b-1;
35+
int cur_w = w;
36+
37+
//black jump
38+
if(cur_b-1 >= 0){
39+
res += (1-w_prob) * (cur_b*1.0/(cur_b + cur_w))*(1-get_ans(cur_w, cur_b-1, 1-who));
40+
}
41+
42+
//white jump
43+
if(cur_w-1 >= 0){
44+
res += (1-w_prob) * (cur_w*1.0/(cur_w + cur_b))*(1-get_ans(cur_w-1,cur_b, 1-who));
45+
}
46+
dp[w][b][who] = res;
47+
return res;
48+
}
49+
}
50+
51+
52+
53+
void work(){
54+
for(int i=0; i<=white; i++){
55+
for(int j=0;j<=black; j++){
56+
dp[i][j][0] = dp[i][j][1] = INF;
57+
}
58+
}
59+
60+
double ans = get_ans(white, black, 0);
61+
cout<<std::setprecision(15)<< ans<<endl;
62+
}
63+
64+
65+
int main(){
66+
cin>>white>>black;
67+
work();
68+
return 0;
69+
}
70+

cf/109/A_div1.cpp

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <iostream>
2+
#include <cstring>
3+
4+
#include <vector>
5+
6+
using namespace std;
7+
8+
9+
string S;
10+
string forb[14];
11+
12+
const int INF = 99999999;
13+
const int MAXN = 100005;
14+
int N, dp[MAXN][2];
15+
16+
bool is_in(int a, int b, string &myS){
17+
for(int i=0; i<N; i++){
18+
if((forb[i][0]==myS[a] && forb[i][1]==myS[b])||(forb[i][0]==myS[b] && forb[i][1]==myS[a])){
19+
return true;
20+
}
21+
}
22+
return false;
23+
}
24+
25+
typedef pair<int, int> pii;
26+
void work(){
27+
S+="#";
28+
int n_char = S.length();
29+
vector< pii > V;
30+
int pre = 0, ans = 0;
31+
for(int i=1; i<n_char; i++){
32+
if(S[i]==S[pre]){
33+
continue;
34+
}else{
35+
int a = pre;
36+
int b = i-1;
37+
V.push_back( pii(a,b));
38+
pre = i;
39+
}
40+
}
41+
for(int i=0; i<MAXN; i++){
42+
dp[i][0] = dp[i][1] = INF;
43+
}
44+
45+
46+
dp[0][0] = V[0].second-V[0].first+1;
47+
dp[0][1] = 0;
48+
49+
int sz = V.size();
50+
cout<<"sz = "<<sz<<endl;
51+
for(int i=0; i<sz; i++){
52+
cout<<V[i].first<<" "<<V[i].second<<endl;
53+
}
54+
for(int i=1; i<sz; i++){
55+
int l_a = V[i].second-V[i].first+1;
56+
if(is_in( V[i-1].first, V[i].first, S)){
57+
dp[i][1] = min(dp[i-1][0], dp[i][1]);
58+
dp[i][0] = min(dp[i-1][0],dp[i-1][1])+l_a;
59+
}else{
60+
dp[i][1] = min(min(dp[i-1][0], dp[i-1][1]), dp[i][1]);
61+
dp[i][0] = min(dp[i-1][0],dp[i-1][1])+l_a;
62+
}
63+
cout<<"dp["<<i<<"][0] = "<<dp[i][0]<<" dp["<<i<<"][1] = "<<dp[i][1]<<endl;
64+
}
65+
66+
ans = min(dp[sz-1][0], dp[sz-1][1]);
67+
cout<<ans<<endl;
68+
}
69+
70+
71+
int main(){
72+
73+
cin>>S;
74+
cin>>N;
75+
for(int i=0; i<N; i++){
76+
cin>>forb[i];
77+
}
78+
work();
79+
80+
return 0;
81+
}
82+

cf/109/a.out

30.7 KB
Binary file not shown.

cf/110/a.out

14.6 KB
Binary file not shown.

cf/110/div1_B.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <stdio.h>
4+
#include <cstring>
5+
#include <string.h>
6+
7+
8+
using namespace std;
9+
10+
string str1, str2;
11+
const int MAXN = 2003;
12+
int dp[MAXN][MAXN];
13+
14+
void work(){
15+
memset(dp,0,sizeof(dp));
16+
int sz_1 = str1.size();
17+
int sz_2 = str2.size();
18+
19+
int tmp_max = 0;
20+
for(int i=1; i<sz_1; i++){
21+
for(int j=1; j<sz_2; j++){
22+
if(str1[i]==str2[j]){
23+
dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
24+
//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
25+
tmp_max = max(tmp_max, dp[i][j]);
26+
}else{
27+
dp[i][j] = 0;
28+
}
29+
30+
}
31+
}
32+
cout<<tmp_max<<endl;
33+
34+
cout<<sz_2 - 1 - tmp_max<<endl;
35+
}
36+
37+
int main(){
38+
cin>>str1;
39+
cin>>str2;
40+
str1 = "#"+str1;
41+
str2 = "*"+str2;
42+
work();
43+
44+
45+
46+
return 0;
47+
}
48+

cf/110/div1_B2.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <stdio.h>
4+
#include <cstring>
5+
#include <string.h>
6+
7+
8+
using namespace std;
9+
10+
string str1, str2;
11+
const int MAXN = 2003;
12+
int dp[MAXN][MAXN];
13+
14+
int work(string &mystr1, string &mystr2){
15+
16+
int ptr1 = 0, ptr2 = 0;
17+
int sz1 = mystr1.size(), sz2 = mystr2.size();
18+
19+
int cnt = 0;
20+
while(ptr2<sz2){
21+
while(ptr1<sz1){
22+
if(mystr1[ptr1]==mystr2[ptr2]){
23+
ptr1++, ptr2++;
24+
cnt++;
25+
}else{
26+
ptr1++;
27+
}
28+
}
29+
if(ptr1>=sz1){
30+
break;
31+
}
32+
}
33+
int len = 0;
34+
35+
if(sz1>sz2){
36+
return sz1 - cnt;
37+
}else{
38+
return sz2 - cnt;
39+
}
40+
}
41+
42+
int main(){
43+
cin>>str1;
44+
cin>>str2;
45+
46+
47+
int sz = str1.size();
48+
int sz2 = str2.size();
49+
int ans = 1000000000;
50+
for(int i=0; i<sz; i++){
51+
for(int j=i; j<sz; j++){
52+
int len = j-i+1;
53+
string tmp = str1.substr(i, len);
54+
55+
if(tmp[0]!=str2[0] || tmp[len-1]!=str2[sz2-1])continue;
56+
57+
int cur = work(tmp, str1);
58+
ans = min(cur, ans);
59+
cout<<"tmp = "<<tmp<<endl;
60+
cout<<cur<<endl;
61+
}
62+
}
63+
64+
cout<<"ans = "<<ans<<endl;
65+
66+
67+
return 0;
68+
}
69+

cf/120_F.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string.h>
4+
#include <queue>
5+
#include <fstream>
6+
7+
using namespace std;
8+
9+
int T, N;
10+
const int MAXN = 105;
11+
vector<int> G[MAXN];
12+
bool visited[MAXN];
13+
14+
typedef pair<int, int> pii;
15+
16+
int work(){
17+
int cur_max_dis = 0;
18+
for(int start=0; start<N; start++){
19+
memset(visited, 0, sizeof(visited));
20+
queue< pii > Q;
21+
pii init(start, 0);
22+
Q.push(init);
23+
while(!Q.empty()){
24+
pii cur = Q.front();
25+
Q.pop();
26+
cur_max_dis = max(cur_max_dis, cur.second);
27+
visited[cur.first] = 1;
28+
int sz = G[cur.first].size();
29+
for(int i=0; i<sz; i++){
30+
int next = G[cur.first][i];
31+
if(visited[next]==false){
32+
pii next_node(next, cur.second+1);
33+
Q.push(next_node);
34+
}
35+
}
36+
}
37+
}
38+
return cur_max_dis;
39+
}
40+
41+
42+
int main(){
43+
ifstream fin("input.txt");
44+
ofstream fout("output.txt");
45+
fin>>T;
46+
int ans = 0;
47+
for(int spider = 0; spider <T; spider++){
48+
fin>>N;
49+
for(int i=0; i<MAXN; i++){
50+
G[i].clear();
51+
}
52+
53+
for(int i=0; i<N-1; i++){
54+
int a, b;
55+
fin>>a>>b;
56+
a--,b--;
57+
G[a].push_back(b);
58+
G[b].push_back(a);
59+
}
60+
//cout<<"ready "<<endl;
61+
int cur = work();
62+
ans += cur;
63+
}
64+
fout<<ans<<endl;
65+
66+
return 0;
67+
}
68+

0 commit comments

Comments
 (0)