Codeforces 812B-Sagheer, the Hausmeister
来源:互联网 发布:淘宝专业术语大全 编辑:程序博客网 时间:2024/06/06 09:39
**题目的意思是给出一栋楼的灯的状态,每一栋一格花费1分钟,只能在两端的楼梯上楼
且只有一层的灯全关闭才能上楼,问最小时间。最下面是一楼,最上面是顶楼,人初始
在(n,1)的位置**
比赛的时候一直想着贪心,但是还是在很多细节错了。。
居然没有想着写dp。。。
char s[20][110];int mp[20][110];int n,m;int sum[20][110];int layer;void init(){ for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ if(mp[i][j]){layer=i;return;} } }}int main(){ while(~sf("%d%d",&n,&m)){ int ret=0; rep(i,1,n){ sf("%s",s[i]); } int ans=0; int pos=0; int mid=m/2+1; int tmp; for(int cas=0;cas<=1;++cas){ ret=0;pos=0; if(cas==0){ for(int i=n;i>=1;--i){ for(int j=0;j<=m+1;++j){ mp[i][j]=s[i][j]-'0';if(mp[i][j])mp[i][j]=++ret; } } } else{ tmp=ans;ans=0; for(int i=n;i>=1;--i){ for(int j=m+1;j>=0;--j){ mp[i][j]=s[i][j]-'0';if(mp[i][j])mp[i][j]=++ret; } } } init(); if(layer==0){puts("0");return 0;} //pf("%d",layer); for(int i=n;i>=1;--i){ if(pos==0){ int id=0; for(int k=m;k>=1;--k)if(mp[i][k]){id=k;break;} int last=pos; for(last=1;last<=m;++last){if(mp[i-1][last])break;} if(id==0)continue; if(mp[i][id]==ret){ans+=id;break;} if(id>=mid){ if(last>=m-id+1) {ans+=m+1;pos=m+1;} else {ans+=2*id;pos=0;} } else{ if(last>m-id+1){ans+=m+1;pos=m+1;} else {ans+=2*id;pos=0;} } } else{ int id=0; for(int k=1;k<=m;++k)if(mp[i][k]){id=k;break;} int last=0; for(last=m;last>=1;--last){if(mp[i-1][last])break;} if(id==0)continue; if(mp[i][id]==ret){ans+=pos-id;break;} if(id>=mid){ if(last>m-id+1){ans+=2*(pos-id);pos=m+1;} else {ans+=m+1;pos=0;} } else{ if(last>m-id+1){ans+=2*(pos-id);} else {ans+=m+1;pos=0;} } } } } ans=min(ans,tmp); ans+=n-layer; pf("%d\n",ans); }}
阅读全文
0 0
- Codeforces 812B-Sagheer, the Hausmeister
- Codeforces 812B Sagheer, the Hausmeister[dp]
- codeforces 812 B Sagheer, the Hausmeister(枚举)
- Codeforces 812 B Sagheer, the Hausmeister
- codeforces 812B Sagheer, the Hausmeister dp
- codeforces 812b Sagheer, the Hausmeister
- codeforces Sagheer, the Hausmeister 812B
- Codeforces 812B-Sagheer, the Hausmeister
- Sagheer, the Hausmeister CodeForces
- Sagheer, the Hausmeister CodeForces
- B. Sagheer, the Hausmeister
- Codeforecs 812B Sagheer, the Hausmeister DP
- CF 812B Sagheer, the Hausmeister
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
- CodeFroces 812B Sagheer, the Hausmeister(BFS)
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister dfs深度优先搜索
- hdu6171 双向bfs
- 1040:计算1~N之间所有的奇数之和
- 环形进度条的简单实现
- 观察者模式——猫和老鼠(什么原来这里是标题吗)
- JAVAEE之Spring学习(五)---SpringMVC注解实现功能的详解
- Codeforces 812B-Sagheer, the Hausmeister
- 子网掩码255.255.0.0与255.255.255.0的区别
- Java开发工具包下载安装和配置
- MPC8309 USB OTG功能调试
- jquery遍历json的方法
- ios 适配
- 深度学习(二)-----传统神经网络
- 51nod 1675 序列变换 莫比乌斯反演(第二种形式)
- Linux 命令行使用技巧整理