codeforces-#475A. Bayan Bus(模拟)
来源:互联网 发布:淘宝 寄海外 编辑:程序博客网 时间:2024/04/29 06:13
题目大意:给一个矩形的大巴乘坐规则,给定人数,输出大巴的座位的情况。
解题思路:就是字符串模拟,可以对特殊的简单处理下,这里给出两种写法,第二种写法更直接,简单粗暴。详见code。
题目大意:http://codeforces.com/problemset/problem/475/A
code:
<pre name="code" class="cpp">#include <iostream>#include <cstdio>#include <cstring>using namespace std;int n,k,m;char str[4][27]={ "|#.#.#.#.#.#.#.#.#.#.#.|D|", "|#.#.#.#.#.#.#.#.#.#.#.|.|", "|#.......................|", "|#.#.#.#.#.#.#.#.#.#.#.|.|",};int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&k)){ if(k>34) break; printf("+------------------------+\n"); if(k<=4) for(int i=0;i<k;++i) str[i][1]='O'; else if(k>4){ for(int i=0;i<4;++i) str[i][1]='O'; k-=4; n=k/3; m=k%3; for(int i=0;i<4;++i) for(int j=0;j<n;++j) if(i!=2)str[i][3+2*j]='O'; for(int i=0;i<m;++i) if(i!=2)str[i][2*n+3]='O'; } for(int i=0;i<4;++i){ for(int j=0;j<26;++j) printf("%c",str[i][j]); if(i==0 || i==3)printf(")\n"); else printf("\n"); } printf("+------------------------+\n"); } return 0;}
暴力code:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int k;char str[6][30]={ "+------------------------+", "|#.#.#.#.#.#.#.#.#.#.#.|D|)", "|#.#.#.#.#.#.#.#.#.#.#.|.|", "|#.......................|", "|#.#.#.#.#.#.#.#.#.#.#.|.|)", "+------------------------+",};int main(){ scanf("%d",&k); for(int i=0;i<30;++i) for(int j=0;j<6;++j){ if(k==0) break; if(str[j][i]=='#'){ k--; str[j][i]='O'; } } for(int i=0;i<6;++i) printf("%s\n",str[i]); return 0;}
0 0
- codeforces-#475A. Bayan Bus(模拟)
- 【CODEFORCES】 A. Bayan Bus
- 475A Bayan Bus
- Codeforces Bayan Bus
- A. Bayan Bus
- 【模拟】Codeforces 711A Bus to Udayland
- CF Bayan 2015 Contest Warm Up A.(模拟+预处理)
- codeforces 435A Queue on Bus Stop(模拟水题)
- Codeforces Round #369 (Div. 2) A. Bus to Udayland【模拟】
- cf475A Bayan Bus
- CodeForces #Bayan# -- C Kamal-ol-molk's Painting 模拟
- CodeForces - 660B Seating On Bus (模拟)水
- CodeForces 711A Bus to Udayland(水题)
- Codeforces-711A Bus to Udayland(找座位)
- CodeForces 711A A. Bus to Udayland
- Codeforces 660B Seating On Bus 【模拟】
- CodeForces 660 B. Seating On Bus【模拟】
- Codeforces 864C Bus(模拟水题)
- MySQL5.6 如何优化慢查询的SQL语句 -- 慢日志介绍
- Java线程:线程安全与不安全
- 天坛汉白玉石雕遭踩踏 游客:踩着照相才过瘾
- BNUOJ29065鸣人的查克拉
- 程序员面试题精选100题(完整版)博客地址
- codeforces-#475A. Bayan Bus(模拟)
- HDU-#5058 So easy(set)
- Linux - 输入输出流程序 代码(C)
- 类模板与模板类 &&函数模板与模板函数
- .优秀程序员必备的15大技能
- svn: Can't convert string from 'UTF-8' to native encoding
- 【iOS开发-30】UITabBarController的几种代理方法以及结合NSUserDefaults还原上次退出时被选中视图控制器和视图控制器的顺序
- 新的开始
- cocoapods安装与使用