现在位置: 首页 > sunshine945发表的所有文章
  • 02月
  • 17日
综合 ⁄ 共 529字 评论关闭
装饰器的实际就是函数,他们接受函数对象,在适当处调用函数或者至少一些引用,返回值是一个包装了的函数对象 装饰器又分为有参和无参装饰器,无参的装饰器就是本身是一装饰器,直接把被装饰函数作为参数,进行相关操作,有参数的装饰器就是通过传入的参数,返回一个装饰器对象,然后实现对被装饰函数的操作 #!/usr/bin/env python from time import ctime, sleep def tsfunc(func): def wrappedFunc(): print '[%s] %s() called' % (ctime(), func.__name__) return func()#此处实现对被装饰函数的调用 ......
阅读全文
  • 02月
  • 15日
综合 ⁄ 共 1079字 评论关闭
计算黄金分割数, 精确到小数点后100位 利用裴波那契数列前一项与后一项的比值,且所选取的数越大,精度越高 之后就是大数除法。只是做个简单的,每次上商的时候不断用被除数减去除数,直到减成负的,然后在加上除数,用的是恢复余数的方法 代码: #include<cstdio> #include<cstring> #define ll long long #define MAX 1000 int a[MAX], b[MAX], c[MAX]; int cnt1; int calc() { int res = 0, cnt; while(1) { for(int i = 0; i < MAX-1; ++ i......
阅读全文
  • 02月
  • 07日
综合 ⁄ 共 836字 评论关闭
用列表模拟堆栈(stack.py) #!/usr/bin/env python stack=[] def pushit(): stack.append(raw_input('Enter new string:').strip()) def popit(): if len(stack) == 0: print 'Can not pop from an empty stack' else: print 'Removed [', `stack.pop()`, ' ]' def viewstack(): print stack CMDs={'u':pushit, 'o':popit, 'v':viewstack} def showmenu(): pr= ''' p(u)sh p(O)p (V)iew (Q)uit Enter choice:''' while True: while True: ......
阅读全文
  • 02月
  • 06日
综合 ⁄ 共 627字 评论关闭
链接:http://poj.org/problem?id=3900 题意:T个case,N种钻石,最大载重为M,第K种钻石具有价值ck, 重量wk, 数量为K个,要求选出最大价值 题目给出的数据范围 1 ≤ T ≤ 74, 1 ≤ N ≤ 15, 1 ≤ M ≤ 1000000000 (109), 1 ≤ Wk, Ck ≤ 1000000000 (109). 动态规划开不下那么大数组,N的个数不大,采用深搜,重要的是剪枝 首先按照性价比排一下序 然后如果当前搜到的结果res加上剩下所有钻石的价值都没有result大就剪枝 还有一个就是,因为是按照性价比排序所以如果当前结果res+剩余容量全部都用来放置这种性价比的钻石得到的价值都没有r......
阅读全文
  • 02月
  • 05日
综合 ⁄ 共 522字 评论关闭
水题,WA了一次,没有考虑到最终结果中 分子%分母 为0的情况 #include<cstdio> #define abs(a) a>0?a:-a   int gcd(int a, int b) { int max, min; if(a > b) { max = a; min = b; } else { max = b; min = a; } int r = max%min; while(r != 0) { max = r; if(r < min) { max = min; min = r; } r = max%min; } return min; ......
阅读全文
  • 02月
  • 04日
综合 ⁄ 共 539字 评论关闭
链接:http://poj.org/problem?id=3978 水题一道。打表就可以了 #include<cstdio> #include<cstring> #define MAXN 100005   int num[MAXN]; bool is_prime[MAXN];//is_prime[i] = 1 表示i是质数 void solve() { memset(is_prime, true, sizeof(is_prime)); is_prime[0] = is_prime[1] = false; num[0] = num[1] = 0; for(int i = 2; i < MAXN; ++ i) { if(is_prime[i]) {......
阅读全文
  • 02月
  • 03日
综合 ⁄ 共 1556字 评论关闭
样例过了,这题就A了,像这样 #include<cstdio> int main() { printf("5*(5-(1/5))\n"); } 我的正解是枚举,加括号的方式有5种 (a b) (c d) ((a b) c) d (a (b c)) d a (b (c d)) a ((b c) d) 然后三个位置上的符号分别都进行枚举 #include<cstdio> #include<cmath> #define MIN 1e-10 double a, b, c, d; double cal(double n1, double n2, int op) { switch(op) { case 0: return n1+n2; case 1: return n1-n2; case 2: return n1*n2; case 3:......
阅读全文
  • 01月
  • 29日
综合 ⁄ 共 1756字 评论关闭
链接:http://poj.org/problem?id=1009 题意:把题目给出的点的像素值按照给定的要求进行转换,其中转换规则是给出图片宽度width,这些点都是从左到右从上到下一次排 列的,每个点新的像素值是原来的像素值与其前后左右的像素值的差的绝对值最大的那个。 思路:题目给出的点的个数的范围是10^9,width值也没有确定,一个一个的计算空间和时间上都会超的,但是看discuss貌似是说这个 题目的测试数据在width值大于10000时就变成一行,类似这样 100000 2 50000 5 50000 0 0 然后就把这种情况作为特殊情况处理,不过我没试 周围元素都一......
阅读全文
  • 01月
  • 26日
综合 ⁄ 共 721字 评论关闭
水题 #include<cstdio> #include<string> #include<algorithm> #include<map> using namespace std; char Haab_Month[20][10] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "ua......
阅读全文
  • 01月
  • 25日
综合 ⁄ 共 324字 评论关闭
链接http://poj.org/problem?id=1005 偶不是有意刷水题的,poj上自己没做的依次往后做的 #include<cstdio> #define PI 3.1415926 int main() { freopen("poj1005.txt", "r", stdin); int n; scanf("%d", &n); double x, y; for(int k = 0; k < n; ++ k) { scanf("%lf%lf", &x, &y); printf("Property %d: This property will begin eroding in year %d.\n", k + 1, &#......
阅读全文
  • 01月
  • 25日
综合 ⁄ 共 868字 评论关闭
链接http://poj.org/problem?id=1002 一道水题,之前把电话号码转化成string,用map来做,TLE了,直接用数字做A了 #include<cstdio> #include<algorithm> #include<iostream> using namespace std; #define MAX 100010 int num[MAX]; char str[100]; int map[100]; int main() { freopen("poj1002.txt", "r", stdin); for(int i = 0; i < 10; ++ i) { map[i + '0'] = i; } map['A'] ......
阅读全文
  • 01月
  • 23日
综合 ⁄ 共 1255字 评论关闭
连接:http://poj.org/problem?id=1001 大数乘法,一次就过了,目测跟去年相比做水题的能力真是提高不少 方法比较笨,就是首先转化成整数处理,再处理小数点,细心一点就好了 #include<cstdio> #include<cstring> #include<iostream> using namespace std; int a[200], b[200], c[200]; int n_len, len1; int cal(int a1[200], int len1) { memset(c, 0, sizeof(c)); for(int i = 0; i < n_len; ++ i) { for(int......
阅读全文