摘要: 对于给出的母函数模板 , 让人理解起来比较费劲的!以下给出几种解释 , 和自己理解!//made by syx//time 2010年9月11日 10:17:27//母函数例题/*//整数拆分模板#include <iostream>using namespace std;const int lmax=10000;//c1是用来存放展开式的系数的,而c2则是用来计算时保存的,//他是用下标来控制每一项的位置,比如 c2[3] 就是 x^3 的系数。//用c1保存,然后在计算时用c2来保存变化的值。int c1[lmax+1],c2[lmax+1];int main(){int n, 阅读全文
posted @ 2012-08-07 08:23 zh yu 阅读(295) 评论(0) 推荐(0) 编辑
摘要: //控制输出精度;可以用iostream中的precision或是用iomanip中的setrecision;#include<iostream>#include<iomanip>using namespace std;int main(){ float a=4.5891589; //cout<<fixed; //cout<<setprecision(3)<<a<<endl; cout.precision(2);//默认模式下,它指的是显示的总位数; cout<<a<<endl; cout.setf 阅读全文
posted @ 2012-07-27 09:42 zh yu 阅读(1572) 评论(0) 推荐(0) 编辑
摘要: sortTime Limit: 6000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16968Accepted Submission(s): 4977Problem Description给你n个整数,请按从大到小的顺序输出其中前m大的数。Input每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。Output对每组测试数据按从大到小的顺序输出前m大的数。Samp 阅读全文
posted @ 2012-07-26 16:30 zh yu 阅读(273) 评论(0) 推荐(0) 编辑
摘要: Problem DescriptionThe highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The 阅读全文
posted @ 2012-07-26 14:50 zh yu 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 1 //快速幂取模, 2 #include <iostream> 3 4 using namespace std; 5 //1. 6 //a^n%b 7 int modExp(int a, int n, int b) 8 { 9 int t,y;10 t=1;y=a;11 while (n)12 {13 if (n&1) t=t*y%b;//若n为偶数;14 y=y*y%b;15 n>>=1;16 }17 return t;18 }19 //2.利用a^n%c = (((a%c)*a)%c...... 阅读全文
posted @ 2012-07-26 10:42 zh yu 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 在系统中,往往有一些服务只需要它们在整个系统中只存在一个实例,而且可以在系统的任意角落访问到它,我们引入单件模式来解决这个问题,这是众多设计模式中的一种class testSingleton{static testSingleton instance;//类的单例private testSingleton{};//构造函数前的修饰符为私有;这样就不能在类的外部用new来生成//一个新的对象public static testSingleton getInstance()//返回 单例{if(instance == null)instance = new testSingleton();retu 阅读全文
posted @ 2012-05-12 10:24 zh yu 阅读(370) 评论(0) 推荐(0) 编辑
摘要: //C.h 几乎各程序都需要用到的文件包含宏命令和使用名空间#ifndef _C_H_#define _C_H_#include <iostream>#include <fstream>#include <iomanip>#include <cmath>#include <string>#include <vector>#include <list>#include <stack>#include <queue>#include <bitset>#include <al 阅读全文
posted @ 2012-04-09 22:25 zh yu 阅读(529) 评论(0) 推荐(0) 编辑
摘要: 1 #include<iostream> 2 using namespace std; 3 template<class T> 4 struct Node 5 { 6 T data; 7 Node<T> *next; 8 }; 9 template<class T> 10 class LinkList 11 { 12 public: 13 LinkList(); 14 LinkList(T a[],int n); 15 ~LinkList(); 16 int length(); 17 ... 阅读全文
posted @ 2012-03-06 17:50 zh yu 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 在1~36之间取随机6个数(不重复),并按从小到大的顺序输出/*主要思想是用系统时间生成随机数的种子,然后取随机数,冒泡排序并输出11/24/2011 by zhuyu*/#include <iostream>#include <ctime>#include <cstdlib>using namespace std;int num[6];void paixu();double random(double,double);int main(){ int limit=36;//限制上限为36 int *temp=new int[limit]; int numbe 阅读全文
posted @ 2011-11-24 14:07 zh yu 阅读(276) 评论(0) 推荐(0) 编辑