2011年11月10日

poj3983 (24点)

摘要: 给出4个数,只能添加+-*/或者()使得结果为24。思路:枚举,一共5*3^4.#include <iostream>using namespace std;double a,b,c,d;double f(double a,double b,int op){ if(1 == op) return a+b; if(2 == op) return a-b; if(3 == op) return a*b; return a/b;}//type表示加括号的方式,一共5种bool caculate(int p1,int p2,int p3,int type){ double ans=0.0; 阅读全文

posted @ 2011-11-10 21:56 buptLizer 阅读(795) 评论(0) 推荐(0) 编辑

poj1995快速幂取余

摘要: 快速幂运算:View Code int pow(int a,int n){ int rs=1; while(n) { if(n&1) rs=rs*a; a=a*a; n=n>>1; } return rs;}快速幂取余://求a^b%n,O(logb)__int64 get_mi_mod(__int64 a,__int64 b,int n){ if(0 == a) return 0; if(0 == b) return 1; __int64 rs=1; while(b) { if(b&1) rs=(rs*a)%n; a=(a*a)%... 阅读全文

posted @ 2011-11-10 15:01 buptLizer 阅读(1105) 评论(1) 推荐(0) 编辑

导航