Skip to content

Commit 48289bb

Browse files
committed
add a lot
1 parent 934e054 commit 48289bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+538543
-11
lines changed

a.out

9.62 KB
Binary file not shown.

blog/divide_without_divide.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int A, B;
5+
void get_ans(int &res, int all, int div){
6+
if(all<div){
7+
return ;
8+
}
9+
10+
int sum = div;
11+
int cnt = 1;
12+
int cur = -1;
13+
int rec = -1;
14+
while(sum<=all){
15+
cur = sum;
16+
rec = cnt;
17+
sum += sum;
18+
cnt += cnt;
19+
}
20+
int left = all-cur;
21+
res += rec;
22+
get_ans(res, left, div);
23+
}
24+
25+
26+
void work(){
27+
int ans;
28+
get_ans(ans, A,B);
29+
cout<<"ans = "<<ans<<endl;
30+
}
31+
32+
33+
int main(){
34+
cin>>A>>B;
35+
36+
work();
37+
38+
39+
return 0;
40+
}
41+

cf/175/A.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main(){
6+
7+
return 0;
8+
}
9+

hdoj/1698.cpp

+30-11
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,58 @@
22

33
using namespace std;
44

5-
const int MAXN = 100001;
6-
int tree[MAXN*8],N,T, lazy[MAXN*8];
5+
const int MAXN = 120001;
6+
int tree[MAXN*8],N,T;
7+
int lazy[MAXN*8];
8+
int cur_case;
9+
//int sum[MAXN*8];
10+
711

812
void pushUp(int idx){
913
tree[idx] = tree[idx*2] + tree[idx*2+1];
1014
}
1115

16+
void pushDown(int idx, int m){
17+
if(lazy[idx]){
18+
lazy[idx<<1] = lazy[idx<<1|1]= lazy[idx];
19+
tree[idx<<1] = (m-(m>>1))*lazy[idx];
20+
tree[idx<<1|1] = (m>>1)*lazy[idx];
21+
lazy[idx] = 0;
22+
}
23+
}
1224
void build(int l, int r, int idx){
1325
if(l==r){
1426
tree[idx] = 1;
27+
lazy[idx] = 0;
1528
return;
1629
}
1730
int m = (l+r)>>1;
1831
build(l, m, idx*2);
1932
build(m+1, r, idx*2+1);
2033
pushUp(idx);
2134
}
35+
/*
36+
void build(int l, int r, int idx){
37+
lazy[idx] = 0;tree[idx] = 1;
38+
if(l==r)return;
39+
int m = (l+r)>>1;build(l,m,idx*2);build(m+1,r,idx*2+1);
40+
pushUp(idx);
41+
}
42+
*/
2243

2344
void insert(int L, int R, int l, int r, int idx, int value){
24-
cout<<"now idx = "<<idx<<endl;
2545
if(L<=l && r<=R){
26-
cout<<"inserting "<<L<<" to "<<R<<" idx = "<<idx<<" value = "<<value<<endl;
27-
tree[idx] = (R-L+1)*value;
46+
tree[idx] = (r-l+1)*value;
47+
lazy[idx] = value;
2848
return ;
2949
}
50+
pushDown(idx, r-l+1);
3051
int m = (l+r)>>1;
3152
if(L<=m){
32-
insert(L, m, l, m, idx*2, value);
53+
insert(L, R, l, m, idx*2, value);
3354
}
3455
if(R>m){
35-
insert(m+1, R, m+1, r, idx*2+1, value);
56+
insert(L, R, m+1, r, idx*2+1, value);
3657
}
3758
pushUp(idx);
3859
}
@@ -43,20 +64,18 @@ void work(){
4364
memset(tree,0,sizeof(tree));
4465
memset(lazy,0,sizeof(lazy));
4566
build(1,N,1);
46-
cout<<"ops = "<<ops<<endl;
4767
for(int i=0; i<ops; i++){
4868
int a,b,c;
4969
scanf("%d %d %d",&a,&b,&c);
5070
insert(a,b,1,N,1,c);
5171
}
52-
cout<<tree[1]<<endl;
72+
cout<<"Case "<<cur_case<<": The total value of the hook is "<<tree[1]<<"."<<endl;
5373
}
5474

55-
56-
5775
int main(){
5876
scanf("%d",&T);
5977
for(int t=1; t<=T; t++){
78+
cur_case = t;
6079
scanf("%d",&N);
6180
work();
6281
}

hdoj/a.out

4.1 KB
Binary file not shown.

poj/2752.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
5+
using namespace std;
6+
7+
const int MAXN = 500000;
8+
string T;
9+
int failure[MAXN];
10+
bool mark[MAXN];
11+
void work(){
12+
memset(mark,0,sizeof(mark));
13+
failure[0] = failure[1] = 0;
14+
int M = T.length();
15+
for(int i=2; i<=M; i++){
16+
int j = failure[i-1];
17+
for(;;){
18+
if(T[i-1]==T[j]){
19+
failure[i] = j+1;
20+
break;
21+
}
22+
if(j==0){
23+
failure[i] = 0;
24+
break;
25+
}
26+
j = failure[j];
27+
}
28+
}
29+
/*
30+
cout<<"print failure"<<endl;
31+
for(int i=0; i<=M; i++){
32+
cout<<failure[i]<<" ";
33+
}
34+
cout<<endl;
35+
*/
36+
37+
int t = M;
38+
while(1){
39+
if(t == 0)break;
40+
mark[t] = 1;
41+
t = failure[t];
42+
}
43+
44+
for(int i=1; i<M; i++){
45+
if(mark[i]){
46+
cout<<i<<" ";
47+
}
48+
}
49+
cout<<M<<endl;
50+
}
51+
52+
53+
int main(){
54+
while(cin>>T){
55+
work();
56+
}
57+
return 0;
58+
}
59+

poj/3261.cpp

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#include <cstring>
2+
#include <cstdio>
3+
#include <iostream>
4+
#include <algorithm>
5+
6+
using namespace std;
7+
8+
const int MAXN = 20001;
9+
10+
int num[MAXN], stp, N, K;
11+
int P[20][MAXN], height[MAXN], mapping[MAXN];
12+
13+
struct entry {
14+
int nr[2];
15+
int p;
16+
}L[MAXN];
17+
18+
bool mycmp(struct entry a, struct entry b){
19+
return a.nr[0]==b.nr[0]?(a.nr[1]<b.nr[1]?1:0):(a.nr[0]<b.nr[0]?1:0);
20+
}
21+
22+
int lcp(int x, int y){
23+
int k,ret =0;
24+
if(x==y)return N-x;
25+
for(k=stp-1; k>=0 && x<N && y<N; k--){
26+
if(P[k][x]==P[k][y]){
27+
x+= 1<<k, y+=1<<k, ret += 1<<k;
28+
}
29+
}
30+
return ret;
31+
}
32+
33+
void myprint(int start, int end){
34+
for(int i=start; i<=end; i++){
35+
cout<<num[i];
36+
}
37+
}
38+
39+
40+
void build_sa(){
41+
for(int i=0; i<N; i++){
42+
P[0][i] = num[i];
43+
}
44+
int cnt = 1;
45+
for(stp=1; cnt>>1 < N ; cnt<<=1, stp+=1){
46+
for(int i=0; i<N; i++){
47+
L[i].nr[0] = P[stp-1][i];
48+
L[i].nr[1] = i+cnt<N?P[stp-1][i+cnt]:-1;
49+
L[i].p = i;
50+
}
51+
sort(L,L+N,mycmp);
52+
for(int i=0; i<N; i++){
53+
P[stp][L[i].p] = i>0 && L[i].nr[0]==L[i-1].nr[0] && L[i].nr[1]==L[i-1].nr[1]? P[stp][L[i-1].p]:i;
54+
}
55+
}
56+
/*
57+
for(int i=0; i<N; i++){
58+
cout<<P[stp-1][i]<<" ";
59+
}cout<<endl;
60+
*/
61+
62+
for(int i=0; i<N; i++){
63+
mapping[ P[stp-1][i] ] = i;
64+
}
65+
/*
66+
cout<<"begin printing"<<endl;
67+
for(int i=0; i<N; i++){
68+
myprint(mapping[i], N-1);
69+
cout<<endl;
70+
}
71+
*/
72+
73+
height[0] = 0;
74+
for(int i=1; i<N; i++){
75+
height[i] = lcp(mapping[i-1], mapping[i]);
76+
}
77+
/*
78+
for(int i=0; i<N; i++){
79+
cout<<"height["<<i<<"] = "<<height[i]<<endl;
80+
}
81+
*/
82+
}
83+
84+
85+
bool judge(int len){
86+
bool in = false;
87+
int count = 0, ans = 0;
88+
bool ok = true;
89+
90+
for(int i=0; i<N; i++){
91+
if(height[i]>=len && in){
92+
//cout<<"at pos "<<i<<" continue add 1"<<endl;
93+
count++;
94+
}else if(height[i]>=len && !in){
95+
//cout<<"at pos "<<i<<" initial 1"<<endl;
96+
in = true;
97+
count = 1;
98+
}else if(height[i]<len){
99+
//cout<<"at pos "<<i<<" go out set 0"<<endl;
100+
in = false;
101+
ans = max(ans, count);
102+
count = 0;
103+
}
104+
}
105+
ans = max(ans, count);
106+
ans+=1;
107+
//cout<<"checking length = "<<len<<" count = "<<ans<<endl;
108+
if(ans>=K){
109+
return true;
110+
}return false;
111+
}
112+
113+
114+
void work(){
115+
int low = 0, high = N-1;
116+
int ans = 0;
117+
while(low<=high){
118+
//cout<<"low = "<<low<<" high = "<<high<<endl;
119+
int mid = (low+high)/2;
120+
if(judge(mid)){
121+
low = mid+1;
122+
ans = mid;
123+
}else{
124+
high = mid-1;
125+
}
126+
}
127+
cout<<ans<<endl;
128+
}
129+
130+
131+
int main(){
132+
133+
134+
while(scanf("%d %d", &N, &K)!=EOF){
135+
136+
for(int i=0; i<N; i++){
137+
scanf("%d", &num[i]);
138+
139+
}
140+
build_sa();
141+
work();
142+
}
143+
144+
return 0;
145+
}
146+

0 commit comments

Comments
 (0)