杨辉三角 && 鸽兔同校
杨辉三角:
用个一维数组直接模拟就行,只是 C++ 的高精度调了好久,后来发现能用 python ,于是试着写了写:
dp = [] def out(L, end):
for i in range(end + 1):
print L[i],
print def clear(L, num):
del L[:]
for i in range(num):
L.append(0) def solve():
x = int(raw_input())
if x == 0:
return
else:
clear(dp, x)
dp[0] = 1
for i in range(0, x):
dp[i] = 1
out(dp, end = i)
for j in range(i, 0, -1):
dp[j] += dp[j-1]
solve() solve()
很少用 python 刷题,写得不是很好。
鸽兔同校:
# -*- coding: utf-8 -*- def solve():
try:
s = raw_input()
n, m = s.split()
n = int(n)
m = int(m)
if 4 * n < m or (4 * n - m) % 2 == 1 or (4 * n - m) / 2 > n:
print 'Error'
else:
a = (4 * n - m) / 2
b = n - a
print a, b
solve()
except EOFError:
pass
solve()
感觉自己好像在做小学的数学题似的 -_-||
杨辉三角 && 鸽兔同校的更多相关文章
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- POJ2167Irrelevant Elements[唯一分解定理 组合数 杨辉三角]
Irrelevant Elements Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2407 Accepted: 59 ...
- python生成器实现杨辉三角
def triangels(): """ 杨辉三角 """ lst = [1] n_count = 2 # 下一行列表长度 while Tr ...
- python 生成器生成杨辉三角
用Python写趣味程序感觉屌屌的,停不下来 #生成器生成展示杨辉三角 #原理是在一个2维数组里展示杨辉三角,空的地方用0,输出时,转化为' ' def yang(line): n,leng=0,2* ...
- HDNOIP201405杨辉三角
2016.1.27 试题描述 杨辉三角是形如如下的数字三角形: 1 1 1 1 2 1 …… 现在想求出杨辉三角第N行的N个数中,有多少个数能被给定的质数p整除. 输入 一行两个空格隔 ...
- Java的二维数组的应用及杨辉三角的编写
(1) 编写一个程序,生成一个10*10的二维随机整数数组,并将该数组的每行最大值保存于一个一维数组中,将每列平均值保存于另外一个一维数组中并分别输出. (2) 编程输出杨辉三角的前10行. 找出一个 ...
- POJ3187Backward Digit Sums[杨辉三角]
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6350 Accepted: 36 ...
- 杨辉三角用java实现
代码如下: public class ErArray { public static void main(String[] args) { //杨辉三角 int[][] num = new int[1 ...
随机推荐
- 【转】西门子数控系统中MMC、PCU、NCU、CCU简略介绍
转载地址:http://cyj221.blog.163.com/blog/static/34194117201093005526170/ 2010-10-30 01:06:09| 分类: 机械制造 ...
- poj1785 Binary Search Heap Construction
此题可以先排序再用rmq递归解决. 当然可以用treap. http://poj.org/problem?id=1785 #include <cstdio> #include <cs ...
- Y2K Accounting Bug 分类: POJ 2015-06-16 16:55 14人阅读 评论(0) 收藏
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11222 Accepted: 56 ...
- U3D UGUI学习3 - RectTransform
总的来说整合了NGUI很多零散功能,比如NGUI2.X处理拉伸要额外套脚本,NGUI3.X开始引入新的锚点.再加上依赖BoxCollider使得整个HUD显示非常乱 而UGUI很清晰明了,你也能看清楚 ...
- [Python] 使用有道翻译API
Python 使用youdao (有道翻译)API 想写一个给自己记录背单词状况的软件,需要获取英文单词的中文释义(基本功能).考虑使用有道翻译的API实现获取英文单词的中文释义的方法. 获取API_ ...
- Educational Codeforces Round 16 A
Description he only king stands on the standard chess board. You are given his position in format &q ...
- podupdate时没有进度
pod无法下载,解决方法. pod install --verbose --no-repo-update 原有命令被墙了. pod install --verbose --no-repo-update ...
- Eclipse常用快捷键windows
Ctrl+1:快速修正Ctrl+W: 关闭当前文件ctrl+O:打开outlineCtrl+D: 删除当前行 Ctrl+L: 定位在某行Ctrl+Q:转到上次修改位置Ctrl+/:注释代码Ctrl+H ...
- 【Java】常见的Set类型,HashSet、TreeSet、LinkedHashSet
HashSet,锋芒毕露,我们最常用到.其他两个,我们较少用到,今天,我们看看他们的区别. import java.util.HashSet; import java.util.Set; public ...
- linux中的shell脚本编程
[1]shell脚本 1--- shell命令 2--- 控制语句(新的语法) (Shell命令的有序集合) [2]创建shell脚本文件 1--- 1.sh 2--- chmod 777 1.sh ...