WY模拟赛8
WY模拟赛8
T1. 洛谷P12375 「LAOI-12」MST?
爆推式子。
code:
#include <bits/stdc++.h>
#define int __int128
// #define int long long
#define fuck inline
#define lb long double
using namespace std;
// typedef long long ll;
const int N=1e6+23,M=64,mod=998244353;
const int inf=INT_MAX,INF=1e9+7;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118;
// const int M=mod1*mod2;
fuck int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
return x*f;
}
fuck void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) write(x/10);
putchar(x%10+'0');
}
int n,m;
fuck void solve()
{
n=read(),m=read();
int x=1.5+sqrt(2.25+2*(m-n));
int sum1=((x*x+5)*x/6)%mod;
int sum2=((2*m-n+2+x)*(n-x-1)/2)%mod;
write((sum1+sum2)%mod);cout<<"\n";
}
signed main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
// int fuckccf=read();
int QwQ=read();
while(QwQ--)solve();
// solve();
return 0;
}
// 6666 66666 666666
// 6 6 6 6 6
// 6 6 6666 6
// 6 6 6 6 6
// 6666 6 6 6666666
T2. 洛谷 P12684 【MX-J15-T4】叉叉学习魔法
非常神奇的 $ 01bfs $ ,第一次写有点被牛逼到。
#include <bits/stdc++.h>
#define i8 __int128
// #define int long long
#define fuck inline
#define lb long double
using namespace std;
// typedef long long ll;
const int N=5e3+5,M=64,mod=998244353;
const int inf=INT_MAX,INF=1e9+7;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118;
// const int M=mod1*mod2;
fuck int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
return x*f;
}
fuck void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) write(x/10);
putchar(x%10+'0');
}
struct node
{
int x,y,t1,t2;
bool operator <(const node &a)const
{
if(t1!=a.t1)return t1>a.t1;
else return t2>a.t2;
}
};
int dx1[10]={-1,1,0,0};
int dy1[10]={0,0,1,-1};
int dx2[10]={1,1,-1,-1};
int dy2[10]={1,-1,1,-1};
deque<node>q;
vector<node>g1,g2;
int xx,yy,wx,wy,n,m;
int a[N][N],vis[N][N];
fuck void solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
string s;cin>>s;s=' '+s;
for(int j=1;j<=m;j++)
{
if(s[j]=='X')xx=i,yy=j,a[i][j]=2;
if(s[j]=='W')wx=i,wy=j,a[i][j]=3;
if(s[j]=='.')a[i][j]=0;
if(s[j]=='#')a[i][j]=1;
}
}
q.push_front({xx,yy,0,0});
while(!q.empty())
{
node u=q.front();
while(!q.empty()&&u.t1==q.front().t1&&u.t2==q.front().t2)
{
u=q.front();q.pop_front();
if(u.x==wx&&u.y==wy){cout<<u.t1<<" "<<u.t2<<"\n";return;}
if(vis[u.x][u.y])continue;
vis[u.x][u.y]=1;
for(int i=0;i<4;i++)
{
int x=u.x+dx1[i],y=u.y+dy1[i];
if(!x||!y||x==n+1||y==m+1||a[x][y]==1)continue;
g1.push_back({x,y,u.t1+1,u.t2});
}
for(int i=0;i<4;i++)
{
int x=u.x+dx2[i],y=u.y+dy2[i];
if(!x||!y||x==n+1||y==m+1||a[x][y]==1)continue;
g2.push_back({x,y,u.t1,u.t2+1});
}
}
for(auto v:g2)q.push_front(v);
for(auto v:g1)q.push_back(v);
g1.clear(),g2.clear();
}
cout<<-1<<" "<<-1<<endl;
}
signed main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
// int fuckccf=read();
// int QwQ=read();
// while(QwQ--)solve();
solve();
return 0;
}
// 6666 66666 666666
// 6 6 6 6 6
// 6 6 6666 6
// 6 6 6 6 6
// 6666 6 6 6666666
T3. 洛谷 P11327 [NOISG 2022 Finals] Voting Cities
这玩意难写到吐血。
注意到优惠卷的作用效果与本身价值没有关系,且只有五种,于是考虑对每一种选择状态建立一个层级,跑分层图最短路。
注意:
- 最大值取值范围不能太小也不能太大。
- 特判 $ S $ 为可投票城市的时候。
#include <bits/stdc++.h>
#define i8 __int128
#define int long long
#define fuck inline
#define lb long double
using namespace std;
// typedef long long ll;
const int N=1e3+5,M=64,mod=998244353;
const int inf=INT_MAX,INF=1e9+7;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118;
// const int M=mod1*mod2;
fuck int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
return x*f;
}
fuck void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) write(x/10);
putchar(x%10+'0');
}
fuck int ksm(int a,int b)
{
if(a==0&&b==0)return 0;
int res=1;
while(b)
{
if(b&1)res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res%mod;
}
int n;
int a[N],f[N][N][3];
fuck void solve()
{
memset(f,0,sizeof(f));
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
// for(int i=0;i<=n;i++)
// {
// for(int j=0;j<=n;j++)cout<<f[i][j][1]<<" ";
// cout<<endl;
// }
// for(int i=0;i<=n;i++)
// {
// for(int j=0;j<=n;j++)cout<<f[i][j][0]<<" ";
// cout<<endl;
// }
for(int len=2;len<=n;len++)
for(int l=1;l<=(n-len+1);l++)
{
int r=len+l-1;
// cout<<a[l]<<" "<<a[l+1]<<endl;
// cout<<ksm(a[l],a[l+1])<<endl;
f[l][r][0]=max(f[l][r][0],f[l+1][r][0]+ksm(a[l],a[l+1]));
f[l][r][0]=max(f[l][r][0],f[l+1][r][1]+ksm(a[l],a[r]));
f[l][r][1]=max(f[l][r][1],f[l][r-1][0]+ksm(a[r],a[l]));
f[l][r][1]=max(f[l][r][1],f[l][r-1][1]+ksm(a[r],a[r-1]));
}
cout<<max(f[1][n][0],f[1][n][1])<<endl;
}
signed main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
// int fuckccf=read();
int QwQ=read();
while(QwQ--)solve();
// solve();
return 0;
}
// 6666 66666 666666
// 6 6 6 6 6
// 6 6 6666 6
// 6 6 6 6 6
// 6666 6 6 6666666
T4. 洛谷 P12043 [USTCPC 2025] 图上交互题4 / Constructive Shortest Path
构造题总是出乎我的意料。
大胆假设给的就是边权。发现最短路一定小于等于加入的边权,用 $ Floyd $ 检查一下最短路,如果比加入边权小就无解。
#include <bits/stdc++.h>
#define i8 __int128
// #define int long long
#define fuck inline
#define lb long double
using namespace std;
// typedef long long ll;
const int N=5e2+5,M=1e5+5,mod=998244353;
const int inf=INT_MAX,INF=1e9+7;
// const int mod1=469762049,mod2=998244353,mod3=1004535809;
// const int G=3,Gi=332748118;
// const int M=mod1*mod2;
fuck int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}
while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
return x*f;
}
fuck void write(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) write(x/10);
putchar(x%10+'0');
}
struct node
{
int x,y,w;
}p[M];
int dis[N][N];
int n,m;
fuck void solve()
{
cin>>n>>m;
memset(dis,0x3f,sizeof(dis));
for(int i=1;i<=n;i++)dis[i][i]=0;
for(int i=1;i<=m;i++)
{
cin>>p[i].x>>p[i].y>>p[i].w;
dis[p[i].x][p[i].y]=dis[p[i].y][p[i].x]=min(dis[p[i].x][p[i].y],p[i].w);
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
for(int i=1;i<=m;i++)
{
if(dis[p[i].x][p[i].y]<p[i].w)
{
cout<<"No";return;
}
}
cout<<"Yes"<<"\n";
for(int i=1;i<=m;i++)cout<<p[i].w<<" ";
}
signed main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
// int fuckccf=read();
// int QwQ=read();
// while(QwQ--)solve();
solve();
return 0;
}
// 6666 66666 666666
// 6 6 6 6 6
// 6 6 6666 6
// 6 6 6 6 6
// 6666 6 6 6666666
总结
- 做题经验少;
- 对于复杂题有想法也不能在短时间内实现,需提升码力。
完结收工!!!!!

看完点赞,养成习惯
\(\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\Downarrow\)

浙公网安备 33010602011771号