题解P6370 [COCI2006-2007#6] KAMEN
1.题解 P7763 [COCI2016-2017#5] Ronald2.题解 P6497 [COCI2016-2017#2] Prosječni3.题解 P7537 [COCI2016-2017#4] Rima4.题解 P8017 [COCI2013-2014#4] UTRKA5.题解 P7751 [COCI2013-2014#2] PUTNIK6.题解 P7752 [COCI2013-2014#2] PALETA7.题解 P7586 [COCI2012-2013#1] SNAGA8.题解 P6485 [COCI2010-2011#4] PROSJEK9.题解 P6447 [COCI2010-2011#1] ŽABE10.题解P6677 [COCI2019-2020#2] Checker11.题解P8073 [COCI2009-2010#7] BAKICE12.题解P8084 [COCI2011-2012#4] BROJ
13.题解P6370 [COCI2006-2007#6] KAMEN
14.题解 P7165 [COCI2020-2021#1] Papričice15.题解 P9911 [COCI 2023/2024 #2] Kuglice16.题解 P6356 [COCI2007-2008#3] CUDAK17.题解 P7309 [COCI2018-2019#2] Kocka18.题解 P6548 [COCI2010-2011#2] IGRA19.题解 P6491 [COCI2010-2011#6] ABECEDA传送门 P6370 [COCI2006-2007#6] KAMEN
题意
比较简单就不详细解释了。
就是模拟石子下落,输出最终效果。
暴力 60
暴力模拟的代码应该是好敲的。
对于每一次,逐层下落,直至落至最后一层。
附赠代码。
#include <bits/stdc++.h> //#define int long long using namespace std; const int N = 3e4+5; const int M = 32; int r,c,n; char ma[N][M]; map<char,int >dy; bool check(int a,int x) { if(dy[ma[a][x]]||dy[ma[a+1][x]]) return 0; else return 1; } signed main() { dy['O']=1; dy['X']=2; cin>>r>>c; for(int i=1; i<=r; ++i) { for(int j=1; j<=c; ++j) { cin>>ma[i][j]; } } cin>>n; for(int i=1; i<=n; ++i) { int x; cin>>x; int now=1; for(now=1; now<=r; ++now) { if(now==r) break; if(ma[now+1][x]=='X') break; if(ma[now+1][x]=='.') continue; if(ma[now+1][x]=='O') { if(x>1&&check(now,x-1)) { x--; continue; } if(x<c&&check(now,x+1)) { x++; continue; } break; } } ma[now][x]='O'; } for(int i=1; i<=r; ++i) { for(int j=1; j<=c; ++j) { cout<<ma[i][j]; } cout<<endl; } return 0; }
AC
可以看出,对于相同的下落点,每一次下落会有大量路程重复去刷。
以此为出发点。
用一个数组
用
当然,每一次下落路径并不是完全相同,也可能会受到其他下落的影响。
因此,我们对于每次受影响的列从原落点的前一层开始更新一下。
AC代码
#include <bits/stdc++.h> //#define int long long using namespace std; const int N = 3e4+5; const int M = 100; int n, m; char ma[N][M]; int cnt[N]; int to[N][M]; bool check(int now,int x) { if(ma[now][x]=='.'&&ma[now+1][x]=='.') return 1; return 0; } void down(int x,int now,int st) { while(1) { cnt[st]=now; to[now][st]=x; if(ma[now+1][x]=='X') break; else if(ma[now+1][x]=='.'){} else if(ma[now+1][x]=='O') { if((x>1)&&check(now,x-1)) x--; else if((x<m)&&check(now,x+1)) x++; else break; } now++; } } signed main() { cin>>n>>m; for(int i=1;i<=n;++i) { string s; cin>>s; for(int j=1;j<=m;++j) { ma[i][j]=s[j-1]; } } for(int i=1;i<=m;++i) ma[n+1][i]='X'; for(int i=1;i<=m;++i) { down(i,1,i); } int T; cin>>T; while (T--) { int x; cin>>x; ma[cnt[x]][to[cnt[x]][x]] ='O'; for(int i=1;i<=m;++i) { if(ma[cnt[i]][to[cnt[i]][i]]=='O') down(to[cnt[i]-1][i],cnt[i]-1,i); } } for(int i=1;i<=n;++i) { for(int j=1;j<=m;++j ) { cout<<ma[i][j]; } cout<<endl; } return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!