生活随笔
收集整理的這篇文章主要介紹了
华东师大二月月赛游记
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
華東師大二月月賽游記
- 傳送門
- A.昔我往矣
- B.楊柳依依
- C.今我來思
- D.雨雪霏霏
傳送門
A.昔我往矣
一看到這題就想到了LCA,然后就開始碼,結果碼的時候發(fā)現(xiàn)用三段跳沒法維護翻新的記錄與翻新的代價,然后就一格一格的跳,很順利的TLE
My incorrect code:
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rg register
using namespace std
;
const ll INF
=10000000000;
ll
Read(){ll dx
=0,fh
=1;char c
=getchar();while(c
>'9'||c
<'0'){if(c
=='-') fh
=-1;c
=getchar();}while(c
<='9'&&c
>='0'){dx
=dx
*10+c
-'0';c
=getchar();}return dx
*fh
;
}
ll h
[50002],cnt
;
struct node
{ll to
,next
,val
;
}edg
[50002];
void Add(ll u
,ll v
,ll val
){++cnt
;edg
[cnt
].next
=h
[u
];edg
[cnt
].to
=v
;edg
[cnt
].val
=val
;h
[u
]=cnt
;
}
ll Newed
[50002],n
,q
,p
[6],Place
,fa
[50002],vis
[50002],que
[50010],he
=0,t
=1,dep
[50010];
ll
chk(ll A
,ll B
){for(ll i
=h
[A
];i
;i
=edg
[i
].next
) if(edg
[i
].to
==B
) return i
;
}
ll
Work(rg ll A
,rg ll B
){ll sum
=0,AA
=A
,BB
=B
;while(dep
[A
]!=dep
[B
]){if(dep
[A
]>dep
[B
]){ll num
=chk(A
,fa
[A
]);if(!Newed
[num
]){Newed
[num
]=1;sum
+=edg
[num
].val
;}A
=fa
[A
];}if(dep
[B
]>dep
[A
]){ll num
=chk(B
,fa
[B
]);if(!Newed
[num
]){Newed
[num
]=1;sum
+=edg
[num
].val
;}B
=fa
[B
];}}while(A
!=B
){if(fa
[A
]){ll numA
=chk(A
,fa
[A
]);if(!Newed
[numA
]){Newed
[numA
]=1;sum
+=edg
[numA
].val
;}A
=fa
[A
];}if(fa
[B
]){ll numB
=chk(B
,fa
[B
]);if(!Newed
[numB
]){Newed
[numB
]=1;sum
+=edg
[numB
].val
;}B
=fa
[B
]; }}return sum
;
}
void Init(){memset(p
,0,sizeof(p
));memset(Newed
,0,sizeof(Newed
));
}
int main(){n
=Read();for(rg
int i
=1;i
<n
;++i
){ll aa
,bb
,Val
;aa
=Read();bb
=Read();Val
=Read();Add(aa
+1,bb
+1,Val
);Add(bb
+1,aa
+1,Val
);}q
=Read();que
[1]=1;dep
[1]=1;while(he
<t
){++he
;ll u
=que
[he
]; vis
[u
]=1;for(rg
int i
=h
[u
];i
;i
=edg
[i
].next
){ll v
=edg
[i
].to
;if(vis
[v
]) continue;dep
[v
]=dep
[u
]+1;fa
[v
]=u
;que
[++t
]=v
;}}for(rg
int r
=1;r
<=q
;++r
){Init();p
[1]=Read();p
[2]=Read();p
[3]=Read();p
[4]=Read();p
[5]=Read();++p
[1];++p
[2];++p
[3];++p
[4];++p
[5];printf("%lld",Work(p
[1],p
[2])+Work(p
[2],p
[3])+Work(p
[3],p
[4])+Work(p
[4],p
[5]));}return 0;
}
反思與總結:
暴力出奇跡
B.楊柳依依
比賽的時候想到是BFS,但是時間不夠,一看有九分的數(shù)據(jù)范圍k都為一,就想到了騙分方法:起點為那個人的必經(jīng)之路,就輸出起點就行了。期望得分:9分
Wrong Code:
#include<bits/stdc++.h>
#define ll long long
using namespace std
;
const ll INF
=10000000000;
ll
Read(){ll dx
=0,fh
=1;char c
=getchar();while(c
>'9'||c
<'0'){if(c
=='-') fh
=-1;c
=getchar();}while(c
<='9'&&c
>='0'){dx
=dx
*10+c
-'0';c
=getchar();}return dx
*fh
;
}
ll h
[50002],cnt
;
struct node
{ll to
,next
;
}edg
[50002];
void Add(ll u
,ll v
){++cnt
;edg
[cnt
].next
=h
[u
];edg
[cnt
].to
=v
;h
[u
]=cnt
;
}
ll m
,n
,k
,s
[100000],e
[100000];
int main(){n
=Read(),m
=Read();for(int i
=1;i
<=m
;++i
){int aa
=Read(),bb
=Read();Add(aa
,bb
);Add(bb
,aa
);}k
=Read();for(int i
=1;i
<=k
;++i
)s
[i
]=Read(),e
[i
]=Read();if(k
==1) printf("%d",s
[1]);else printf("不會qwq");return 0;
}
比賽完之后看題解,就這個題的題解能看懂,把這個題訂了一下
算法分析:
以每個人為起點BFS一遍,記錄每個點的步數(shù),當?shù)竭_這個點的時候步數(shù)為最短步數(shù)時,記錄前驅的數(shù)量與個數(shù),然后再兩遍遞歸遍歷來找這個人到每個點的次數(shù)和總路徑,二者相除,算出這個點一個人時的概率,不斷地加上下一個人的概率,最后統(tǒng)計概率最大的節(jié)點的編號
但是鄙人的遞歸遍歷遇到環(huán)時退不出去了
My incorrect Code:
#include<bits/stdc++.h>
using namespace std
;
int Read(){
int dx
=0,fh
=1;
char c
=getchar();
while(c
>'9'||c
<'0'){if(c
=='-') fh
=-1;c
=getchar();
}
while(c
<='9'&&c
>='0'){dx
=dx
*10+c
-'0';c
=getchar();
}
return dx
*fh
;
}
int h
[50002],cnt
;
struct node
{
int to
,next
;
}edg
[50002];
void Add(int u
,int v
){
++cnt
;
edg
[cnt
].next
=h
[u
];
edg
[cnt
].to
=v
;
h
[u
]=cnt
;
}
double ans
,Chance
[5001];
int step
[5001],flag
[5001],num
,az
[5001],VVis
[5001],Vis
[5001],m
,n
,r
,k
,s
[2001],e
[2001],que
[100000],he
,ta
,pre
[5001][100],cpre
[5001],ways
[2001],vis
[5001];
void Record(int u
){
++az
[u
];
int sum
=0;
for(int i
=1;i
<=cpre
[u
];++i
){int v
=pre
[u
][i
];Record(v
);
}
}
void Chk(int u
){
Vis
[u
]=1;
Chance
[u
]+=double(double(az
[u
])/double(ways
[e
[r
]]));
for(int i
=h
[u
];i
;i
=edg
[i
].next
){int v
=edg
[i
].to
;if(!vis
[v
]||Vis
[v
]) continue;Chk(v
);
}
}
int main(){
n
=Read(),m
=Read();
for(int i
=1;i
<=m
;++i
){int aa
=Read(),bb
=Read();Add(aa
,bb
);Add(bb
,aa
);
}
k
=Read();
for(int i
=1;i
<=k
;++i
)s
[i
]=Read(),e
[i
]=Read();
for(r
=1;r
<=k
;++r
){memset(az
,0,sizeof(az
));memset(que
,0,sizeof(que
));memset(Vis
,0,sizeof(Vis
));memset(vis
,0,sizeof(vis
));memset(pre
,0,sizeof(pre
));memset(cpre
,0,sizeof(cpre
));memset(ways
,0,sizeof(ways
));memset(flag
,0,sizeof(flag
));memset(step
,0,sizeof(step
));he
=0,ta
=1;que
[ta
]=s
[r
];while(he
<ta
){++he
;int u
=que
[he
];
vis
[u
]=1;for(int i
=h
[u
];i
;i
=edg
[i
].next
){int v
=edg
[i
].to
;
if(!vis
[v
]){if(flag
[v
]&&flag
[v
]<step
[u
]+1) continue;step
[v
]=step
[u
]+1;pre
[v
][++cpre
[v
]]=u
;flag
[v
]=step
[v
];que
[++ta
]=v
;if(u
==s
[r
]) ++ways
[v
];ways
[v
]+=ways
[u
];}}}if(flag
[e
[r
]]){vis
[e
[r
]]=1;Record(e
[r
]);}Chk(s
[r
]);
}
for(int i
=0;i
<n
;++i
){if(ans
<Chance
[i
]){ans
=Chance
[i
];num
=i
;}
}
printf("%d",num
);
return 0;
}
總結與反思:
C.今我來思
玄學題目,樣例過了,其他全錯
錯誤示范:
#include<bits/stdc++.h>
#define ll long long
using namespace std
;
const ll INF
=10000000000;
ll
Read(){ll dx
=0,fh
=1;char c
=getchar();while(c
>'9'||c
<'0'){if(c
=='-') fh
=-1;c
=getchar();}while(c
<='9'&&c
>='0'){dx
=dx
*10+c
-'0';c
=getchar();}return dx
*fh
;
}
ll n
,q
,Cheat
,l
[100004],r
[100004],a
[100004],used
[100004],A
[100004],f
[100004],flag
[100004];
int main(){n
=Read(),q
=Read();for(ll i
=0;i
<=n
;++i
) a
[i
]=-1;for(ll i
=0;i
<n
;++i
) l
[i
]=-1,r
[i
]=-1;for(ll R
=1;R
<=q
;++R
){ll le
,num
,ri
;le
=Read(),ri
=Read(),num
=Read();++le
;++ri
;if(l
[num
]==-1&&r
[num
]==-1){l
[num
]=le
;r
[num
]=ri
; }else{if((l
[num
]>ri
||le
>r
[num
])) Cheat
=1;else{r
[num
]=max(r
[num
],ri
);l
[num
]=min(l
[num
],le
);}} for(ll i
=0;i
<n
-1;++i
)for(ll j
=i
+1;j
<=n
-1;++j
)if(r
[i
]<=r
[j
]&&l
[i
]>=l
[j
]&&l
[i
]!=-1&&l
[j
]!=-1){Cheat
=1;}for(ll i
=le
;i
<=ri
;++i
) a
[i
]=max(a
[i
],num
);}for(ll i
=0;i
<n
;++i
){for(ll j
=1;j
<=n
;++j
){if(a
[j
]<=i
&&!flag
[j
]){A
[j
]=i
;used
[i
]=1;flag
[j
]=1;break;} }if(used
[i
]==0){Cheat
=1;break;}}if(Cheat
) for(ll i
=1;i
<=n
;++i
) printf("-1 ");else for(ll i
=1;i
<=n
;++i
) printf("%d ",A
[i
]);return 0;
}
D.雨雪霏霏
暴力出奇跡!(bingmeiyou)
#include<bits/stdc++.h>
using namespace std
;
int Read(){int dx
=0,fh
=1;char c
=getchar();while(c
>'9'||c
<'0'){if(c
=='-') fh
=-1;c
=getchar();}while(c
<='9'&&c
>='0'){dx
=dx
*10+c
-'0';c
=getchar();}return dx
*fh
;
}
int cmax
,h
,t
,que
[5000010][3],R
,C
,Q
,Co
[50001][101],L
[50001][101],Hush
[50001],dx
[5]={0,1,-1,0,0},dy
[5]={0,0,0,1,-1};
bool vis
[50001][101];
int main(){
R
=Read();C
=Read();Q
=Read();for(int i
=1;i
<=R
;++i
)for(int j
=1;j
<=C
;++j
)L
[j
][i
]=Read();for(int i
=1;i
<=R
;++i
)for(int j
=1;j
<=C
;++j
)Co
[j
][i
]=Read(),cmax
=max(cmax
,Co
[j
][i
]);for(int r
=1;r
<=Q
;++r
){int state
=Read();if(state
==1){int aa
,bb
,cc
;aa
=Read();bb
=Read();cc
=Read();Co
[aa
][bb
]=cc
;cmax
=max(cc
,cmax
);}else if(state
==2){memset(Hush
,0,sizeof(Hush
));memset(vis
,0,sizeof(vis
));memset(que
,0,sizeof(que
));int x
=Read(),y
=Read(),H
=Read();if(H
<L
[x
][y
]){printf("0\n");continue;}else{t
=1;h
=0;que
[1][1]=x
;que
[1][2]=y
;vis
[x
][y
]=1;while(h
<t
){++h
;int X
=que
[h
][1],Y
=que
[h
][2];Hush
[Co
[X
][Y
]]=1;if(X
>C
||X
<1||Y
>R
||Y
<1) continue;
for(int i
=1;i
<=4;++i
){int x1
=X
+dx
[i
],y1
=Y
+dy
[i
];if(H
<L
[x1
][y1
]||vis
[x1
][y1
]||x1
>C
||x1
<1||y1
>R
||y1
<1) continue;vis
[x1
][y1
]=1;++t
;que
[++t
][1]=x1
;que
[t
][2]=y1
;}}}int ans
=0;for(int i
=1;i
<=cmax
;++i
) ans
+=Hush
[i
];printf("%d\n",ans
);}}return 0;
}
總結與反思:
暴力出奇跡
然而捆綁測試中并不能這樣
總結
以上是生活随笔為你收集整理的华东师大二月月赛游记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。