CSP-J/S游记
yangshengyue · · 生活·游记
We rise together as our destiny unfolds
We face the darkness and our trials are yet untold
Through the shadows of despair
Oh in silence hopes we share
To chase our dreams that we've declared
We glimpse through our eyes
Yet fools blind our sights
Can't make what they say
We'll find our way we'll find our way
省流 J: 90 + 100 + 35 + 56 = 281 S: 100 + 44 + 24 + 0=168 有一等的风险吗,极小(
Day 0
周五下午帅气跑路,直接战略性放弃一节语文作文课和一节数学讲模拟卷子(虽然我 150)。高铁不颠荡,但汽车快给我阴死了,顺带吐槽一下 SD 日照考点是真在荒郊野岭。
Day 1
上午场
最烧心的一集。
再次省流:应得分 356 实际 281 , T1 挂分,T3 一眼秒但没有时间了。
T1 由于将 ABCDF 看成 ABCDE 痛失十分。 T2 简单双指针也非常好想,于是半个小时我“通过”了 T1 T2。
秉持着“能拿的分先拿的原则”,看了一下 T3 和 T4 主观臆断出了今年最错误的决定。
“T4 比 T3 简单”
于是乎我去写了 T4 ,但终归是一个玄学解,因为我没有考虑到一个端点可以被删除,但是我一直在调我的玄学解,以至于 2h 都没有结果。
然后我去看了 T3,仅用 0s 看出二进制拆位的正解,而此时考试仅仅只剩 10min 的充裕时间!!!
这个傻子拍了拍自己。
下午场
再次省流:应得分 230+ 实际 168 , T2 投入时间不够没有想出正解,T4 暴力挂挂挂。
我的优势是不是 20min 通过了 T1。
:::success[T1 code]{open}
#include<bits/stdc++.h>
#define ll long long
#define re register
using namespace std;
const int N=5e5+5;
ll a[N],n,m,ma,id,l,ri,ans;
map<ll,ll>mp;
int main(){
freopen("crystal.in","r",stdin);
freopen("crystal.out","w",stdout);
cin>>n>>m;
for(re int i=1;i<=n;i++){
cin>>a[i];
mp[a[i]]++;
}
sort(a+1,a+1+n);
l=1;ll res=0,now=m;
for(re int i=1;i<=n;i+=mp[a[i]]){
now-=res*(a[i]-a[i-1]);
res+=mp[a[i]];
while(now<0){
now+=a[i]-a[l];
res--;
l++;
}
ans=max(ans,res);
}
cout<<ans<<endl;
return 0;
}
:::
然后意识到 T2 的思维难点在于花式建图,先想出了较为好像的 n + m 个点, nd 条边的图去跑 dji 而 CSP 的欺骗在于大样例让我误以为这个做法能拿 60 pts。
然后 T2 我就再也没有动过了,认为这个分数“足够”。
:::success[T2 code finall]{open}
#include<bits/stdc++.h>
#define ll long long
#define re register
#define pa pair
using namespace std;
const int N=5e5+5;
const ll INF=INT_MAX;
ll a[N],nex[N*2],to[N*2],val[N*2],head[N],tot,n,m,d,q,c,dis[N+5000];
void add(int u,int v,int w){
to[++tot]=v;
val[tot]=w;
nex[tot]=head[u];
head[u]=tot;
}
ll dijstra(int s,int t){
priority_queue<pa<ll,ll> >q;
for(re int i=1;i<=m+n;i++)dis[i]=INF;
dis[s]=0;
q.push({0,s});
while(q.size()){
auto now=q.top();q.pop();
ll u=now.second;
for(re int i=head[u];i;i=nex[i]){
ll v=to[i],w=val[i];
if(dis[u]+w<dis[v]){
dis[v]=dis[u]+w;
q.push({-dis[v],v});
}
}
}
return dis[t];
}
map<ll,ll>mp;
int main(){
freopen("subway.in","r",stdin);
freopen("subway.out","w",stdout);
cin>>c>>n>>m>>d>>q;
for(re int i=1;i<=m;i++){
cin>>a[i];
}
for(re int i=1;i<=n;i++){
ll k;
cin>>k;
while(k--){
ll u,w;
cin>>u>>w;
add(u,i+m,w);
add(i+m,u,w);
}
}
while(q--){
ll u,v;
cin>>u>>v;
ll di=dijstra(u,v);
cout<<a[u]+a[v]+di<<endl;
}
return 0;
}
/*
0 2 5 20 2
4 1 9 2 5
3 1 5 2 7 4 6
3 2 3 3 4 5 7
1 3
1 2
0 3 7 20 2
8 3 6 1 7 2 9
3 1 4 2 5 5 100
3 2 6 3 1 7 2
4 3 2 5 100 4 6 6 7
1 6
2 3
*/
| ad: 快来坐济南地铁游大美泉城。 |
|---|
T3 把这个暴力优化到
T4 我……你……我……哎呦……嗐。
暴力思路非常好想,但是 lca 写挂了,知识点掌握不牢 ++。
不过 lca 写挂了我寻思着我还有 bfs 求距离呢。
谁知道我读错题了,是一个 min 的 max 的 min ,我的二分答案写得炸炸的。
穷尽所有的时间未能调出 T4 暴力。
:::success[T3 T4 暴力]
#include<bits/stdc++.h>
#define ll long long
#define re register
#define pa pair
using namespace std;
const int N=5e5+5;
const ll INF=INT_MAX;
ll a[N],c,n,d,ans,dis[N],num[N],jj;
void dfs(ll u,ll dep){
if(dep<dis[u]){
dis[u]=dep;num[u]=1;
}else{
if(dep==dis[u])num[u]++;
else return ;
}
int j=u+1;
while(a[j]<=a[u]+d&&j<=n){
dfs(j,dep+1);
j++;
}
}
int main(){
freopen("migrate.in","r",stdin);
freopen("migrate.out","w",stdout);
int T;
cin>>c>>T;
while(T--){
ans=0;
cin>>n>>d;
for(re int i=1;i<=n;i++)cin>>a[i];
for(re int i=1;i<=n-3;i++){
for(re int j=i;j<=n;j++)dis[j]=INF,num[j]=0;
dfs(i,0);
for(re int j=i;j<=n;j++)if(num[j]==2)ans++;
}
cout<<ans<<endl;
}
return 0;
}
/*
0 2
4 2
1 2 3 4
5 2
1 2 3 4 5
0 2
5 3
-2 -1 0 1 2
6 2
-4 -3 -2 -1 3 6
*/
#include<bits/stdc++.h>
#define ll long long
#define re register
#define pa pair
using namespace std;
const int N=5e5+5;
const ll INF=INT_MAX;
ll a[N],c,n,d,ans,dis,num,jj,fa[N][30],dep[N],vis[N],ne[N],k,di;
vector<int>G[N];
void dfs(int u,int f){
fa[u][0]=f;dep[u]=dep[f]+1;
for(re int j=1;j<=29;j++){
fa[u][j]=fa[fa[u][j-1]][j-1];
}
for(auto v:G[u]){
if(v==f)continue;
dfs(v,u);
}
}
ll lca(int u,int v){
if(dep[u]<dep[v])swap(u,v);
while(dep[u]!=dep[v])u=fa[u][0];
if(u==v)return u;
for(re int j=29;j>=0;j--){
if(fa[u][j]!=fa[v][j]){
u=fa[u][j],v=fa[v][j];
}
}
return fa[u][0];
}
void dfs3(int u,int f,ll dep,int e){
if(u==e){
di=min(di,dep);
return ;
}
for(auto v:G[u]){
if(v==f)continue;
dfs3(v,u,dep+1,e);
}
}
ll dist(int u,int v){
di=INF;
dfs3(u,0,0,v);
return di;
}
void dfs2(int u,int f){
for(auto v:G[u]){
if(v==f&&(!ne[v]))continue;
vis[v]=1;
dfs2(v,u);
}
}
ll solve(){
vector<int>need;
for(re int i=0;i<(1<<n);i++){
need.clear();
for(re int j=1;j<=n;j++){
if(i&(1<<(j-1)))need.push_back(j);
}
if(need.size()!=k)continue;
ll tot=0;
for(auto j:need){
vis[j]=0;
}
for(auto j:need){
if(!vis[j]){
vis[j]=1;
dfs2(j,0);tot++;
}
//cout<<j<<' ';
}//cout<<endl;
if(tot>2){
continue;//cout<<1<<endl;
}
ll cnt=0;
for(re int j=1;j<=n;j++){
ll res=INF;
for(auto k:need){
res=min(res,dist(j,k));
//cout<<dist(j,k)<<endl;
}
cnt=max(res,cnt);
}
ans=min(ans,cnt);
//cout<<cnt<<endl;
}
}
int main(){
freopen("hub.in","r",stdin);
freopen("hub.out","w",stdout);
int T;
cin>>c>>T;
while(T--){
ans=INF;
cin>>n>>k;
for(re int i=1;i<=n;i++){
G[i].clear();
}
for(re int i=1;i<n;i++){
int x,y;
cin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(1,0);
solve();
cout<<ans<<endl;
}
return 0;
}
/*
0 2
5 2
1 2
2 3
3 4
4 5
10 3
1 2
1 3
2 4
2 5
3 6
3 7
3 8
7 9
9 10
6
1 2
2 3
1 4
4 5
4 6
*/
:::
初步总结
教训:
1. 最核心最关键对于一个部分分若调试半小时未能调试出来基本说明了思路有问题,这就可以放一放去思考其他题而不是跟它死磕。
2. 板子要背牢
3. 读好题!!!
后话(Day 5)
期中考试。
前几天在死命复习。
语数英物估分 120 + 146 + 145 + 97 = 508 感觉考得还行。
作为初中选手,路还长,重要的是总结经验,勇于向下一站迈进。
What's stretching so far along
The rails or our mutual bond?
We track through the quiet land
To carry us across the sand, you say
One day, our weight, will fall away
Look out! Ride on, we will lead the way
Just let those set options come
None will we choose as fate's outcome
What we'll do and we've done
To seek the souls we left afar
Press on Engrave that in your mind
We won't leave one behind Our way's undefined
I stand in promise, with my heart unchained
No eyes will call in vain to say my name
I storm the silence, with our hearts awake
I seize the light from every path we break