hdoj 2032 杨辉三角
2016-04-05 11:02
447 查看
<h1 style="color: rgb(26, 92, 200); text-align: center; font-family: 'Times New Roman';">杨辉三角</h1><span style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;"><strong><span style="font-family: Arial; font-size: 12px; color: green;">Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 54099 Accepted Submission(s): 22480 </span></strong></span><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Problem Description</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 </div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Input</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Output</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Sample Input</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;"><pre style="word-wrap: break-word; white-space: pre-wrap; margin-top: 0px; margin-bottom: 0px;"><div style="font-family: 'Courier New', Courier, monospace;">2 3</div>
Sample Output
1 1 1 1 1 1 1 2 1
代码:
#include<cstdio> int main() { int a[40][40]; int n; while(~scanf("%d",&n)) { if(n==1) { printf("1\n\n"); continue; } if(n==2) { printf("1\n"); printf("1 1\n\n"); continue; } if(n>=3) { a[1][1]=1; a[2][1]=1; a[2][2]=1; for(int i=3;i<=n;i++) { a[i][1]=1; a[i][i]=1; for(int j=2;j<i;j++) { a[i][j]=a[i-1][j-1]+a[i-1][j]; } } for(int i=1;i<=n;i++) { for(int j=1;j<i;j++) { printf("%d ",a[i][j]); } printf("%d\n",a[i][i]); } printf("\n"); } } return 0; }
相关文章推荐
- SpringMVC深入学习----单例or多例
- 大数据 --> MapReduce原理与设计思想
- string 与char* char[]之间的转换
- 使用CSS3设计地图上的雷达定位提示效果
- JSON 工具包/常见Mapping
- 转场动画
- android studio 运行单个activity
- mysql中使用limit 分页
- JS限制用户只能输入数字,用正则表达式
- MediaPlayer播放一般音频与SoundPool播放短促的音效
- Linux常用命令整理
- Android 6.0 使用 Apache HttpClient
- 网络编程的技术要点
- android:padding和android:margin的用法及区别
- 用Fragment制作的Tab页面产生的UI重叠问题
- 算法實例-C#-信箱排序-PigeonHoleSort
- Oracle decode函数
- hello
- log 的 debug()、 error()、 info()方法的区别
- android开源的酷炫的交互动画和视觉效果:Interactive-animation