mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-12-16 12:13:03 +00:00
feat: 添加P9014.cpp解决动态网格路径问题
实现动态网格路径计算功能,支持实时更新网格方向并重新计算路径总和。包含初始化网格数据、路径计数和动态更新逻辑。
This commit is contained in:
parent
6752cfbb74
commit
3db3b11d46
79
src/10/12/P9014.cpp
Normal file
79
src/10/12/P9014.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <istream>
|
||||||
|
using ll = int64_t;
|
||||||
|
|
||||||
|
const ll maxn = 1500+5;
|
||||||
|
ll n,r[maxn],d[maxn],q,ans,cnt[maxn][maxn];
|
||||||
|
char c[maxn][maxn];
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
std::iostream::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::cin>>n;
|
||||||
|
for(ll i=1;i<=n;i++){
|
||||||
|
for(ll j=1;j<=n;j++){
|
||||||
|
std::cin>>c[i][j];
|
||||||
|
}
|
||||||
|
std::cin>>r[i];
|
||||||
|
}
|
||||||
|
for(ll i=1;i<=n;i++){
|
||||||
|
std::cin>>d[i];
|
||||||
|
}
|
||||||
|
for(ll i=1;i<=n;i++){
|
||||||
|
for(ll j=1;j<=n;j++){
|
||||||
|
ll x=i,y=j;
|
||||||
|
while(x<=n && y<=n){
|
||||||
|
cnt[x][y]++;
|
||||||
|
ll nx = x+c[x][y]=='D', ny = y+c[x][y]=='R';
|
||||||
|
x=nx,y=ny;
|
||||||
|
}
|
||||||
|
printf("%lld, %lld add %lld\n",i,j,x>n?d[y]:r[x]);
|
||||||
|
ans+= x>n?d[y]:r[x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(ll i=1;i<=n;i++){
|
||||||
|
for(ll j=1;j<=n;j++){
|
||||||
|
printf("%lld ",cnt[i][j]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
std::cin>>q;
|
||||||
|
std::cout<<ans<<"\n";
|
||||||
|
while(q--){
|
||||||
|
ll i,j;
|
||||||
|
std::cin>>i>>j;
|
||||||
|
ll x=i,y=j;
|
||||||
|
x+=c[i][j]=='D';
|
||||||
|
y+=c[i][j]=='R';
|
||||||
|
while(x<=n && y<=n){
|
||||||
|
cnt[x][y]-=cnt[i][j];
|
||||||
|
ll nx = x+c[x][y]=='D', ny = y+c[x][y]=='R';
|
||||||
|
x=nx,y=ny;
|
||||||
|
}
|
||||||
|
ans-=cnt[i][j]*(x>n?d[y]:r[x]);
|
||||||
|
printf("tmp ans=%lld\n",ans);
|
||||||
|
c[i][j]=c[i][j]=='R'?'D':'R';
|
||||||
|
x=i,y=j;
|
||||||
|
x+=c[i][j]=='D';
|
||||||
|
y+=c[i][j]=='R';
|
||||||
|
while(x<=n && y<=n){
|
||||||
|
cnt[x][y]+=cnt[i][j];
|
||||||
|
ll nx = x+c[x][y]=='D', ny = y+c[x][y]=='R';
|
||||||
|
x=nx,y=ny;
|
||||||
|
}
|
||||||
|
printf("x=%lld, y=%lld\n",x,y);
|
||||||
|
ans+=cnt[i][j]*(x>n?d[y]:r[x]);
|
||||||
|
std::cout<<ans<<"\n";
|
||||||
|
for(ll i=1;i<=n;i++){
|
||||||
|
for(ll j=1;j<=n;j++){
|
||||||
|
printf("%c ",c[i][j]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user