代码改变世界

hdc fibonacci number 1568

2012-04-14 20:47 by youxin, 404 阅读, 0 推荐, 收藏,
摘要:hdc1568Problem Description2007年到来了。经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来。接下来,CodeStar决定要考考他,于是每问他一个数字,他就要把答案说出来,不过有的数字太长了。所以规定超过4位的只要说出前4位就可以了,可是CodeStar自己又记不住。于是他决定编写一个程序来测验zouyu说的是否正确。Input输入若干数字n(0 <= n <= 100000000),每个数字一行。读到 阅读全文

多种方式求fibonacci数列

2012-04-14 17:14 by youxin, 461 阅读, 0 推荐, 收藏,
摘要:方法如下:/*f[1]=1;f[2]=1; f[n]=f[n-2]+f[n-1] ;*/#includeusing namespace std;int fibonacci(int n){ int *f=new int[n+1];//第0个元素不放 f[1]=1; f[2]=1; for(int i=3;i>n; cout(3/2)^n-1;递归求解过程如下:第3种:迭代来求/*f[1]=1;f[2]=1; f[n]=f[n-2]+f[n-1] ;*/#includeusing namespace std;int fibonacci(int n){ int *... 阅读全文

杭电acm分类

2012-04-14 16:34 by youxin, 1326 阅读, 0 推荐, 收藏,
摘要:第一个分类版本:基础题:1000、1001、1004、1005、1008、1012、1013、1014、1017、1019、1021、1028、1029、1032、1037、1040、1048、1056、1058、1061、1070、1076、1089、1090、1091、1092、1093、1094、1095、1096、1097、1098、1106、1108、1157、1163、1164、1170、1194、1196、1197、1201、1202、1205、1219、1234、1235、1236、1248、1266、1279、1282、1283、1302、1303、1323、1326、133 阅读全文

高精度整数去位取最小问题

2012-04-13 11:43 by youxin, 974 阅读, 0 推荐, 收藏,
摘要:Description键盘输入一个高精度的正整数N,去掉其中任意M个数字后剩下的数字按原左右次序将组成一个新的正整数。编程对给定的N和M寻找一种方案使得剩下的数字组成的新数最小。输出组成的新的正整数。(不超过240位)输入数据均不需判错。如果去掉了某几个位后得到的新整数开头为0,保留0。Input本题有多组测试数据,每组测试数据占一行。一个高精度正整数N(N不超过240位)一个正整数M。(M为不大于N的长度的正整数)N,M由一个空格分开。Output新的正整数,每组数据的输出占一行。不要多余的空白.Sample Input456547 1 456547 2 456547 3 7773359 2 阅读全文

For在VC6.0和VS2010编译器下的作用域问题

2012-04-06 13:04 by youxin, 419 阅读, 0 推荐, 收藏,
摘要:根据c++标准,在for的初始语句中声明的变量,其作用范围是从它定义的位置开始,一直到for所带语句的作用域结束。 由于VC6.0对C++标准的支持性不是太好,导致了在for定义的变量在for外部仍可返回。看下面的代码: #include <iostream>using namespace std;int main(){ for(int i=0;i<5;i++) { } cout<<i<<endl; return 0;}在VC6.0上面运行正常,输出5;在vs2010显示错误:error C2065: “i”: 未声明的标识符; 阅读全文

用vector建立2D数组

2012-04-06 08:33 by youxin, 1031 阅读, 0 推荐, 收藏,
摘要:vector< vector<int> > //一定要有空格,否则认为移位运算符。 vector<vector<int> > array(3) ,申请保存3个向量的vector,array[i]返回的是第i个向量,同理array[i][j]返回的是第i个向量的第j个元素。 问题到这里,你可能会得意的说:"我明白了,很简单吗!"。别急,还有一些细节问题:如下 vector< vector<int> > array2(3); array2[1][2] = 9; 我保证你的程序会segement failed 阅读全文

setprecision()与setiosflags()

2012-04-05 23:03 by youxin, 564 阅读, 0 推荐, 收藏,
摘要:使用setprecision(n)可控制输出流显示浮点数的数字个数。C++默认的流输出数值有效位是6。如果setprecision(n)与setiosflags(ios::fixed)合用,可以控制小数点右边的数字个数。setiosflags(ios::fixed)是用定点方式表示实数。如果与setiosnags(ios::scientific)合用,可以控制指数表示法的小数位数。setiosflags(ios::scientific)是用指数方式表示实数。#include <iostream> #include <iomanip> //要用到格式控制符 #includ 阅读全文

c++ ios_base类

2012-04-05 22:40 by youxin, 1296 阅读, 0 推荐, 收藏,
摘要:ios_base is Base class with type-independent members for the standard stream classes(ios);其中有一个成员函数ios_base::flags 用来控制流的格式。fmtflags flags ( ) const; fmtflags flags ( fmtflags fmtfl );Get/set format flagsThe first syntax returns the current set of format flags set for the stream.The second syntax s. 阅读全文

c++设置左对齐

2012-04-03 22:32 by youxin, 4402 阅读, 0 推荐, 收藏,
摘要:方法一:cout.flags (ios::left);//设置对齐的标志位为左2. cout<<left 对齐选项:(left,rightorinternal).manip setw ( int n );默认右对齐setw(n) 设置固定宽度Set field widthSets the number of characters to be used as thefield widthfor the next insertion operation.smanip setfill ( char c );// setfill example#include <iostream&g 阅读全文

Error C2361: initialization of (identifier) is skipped by (default) label

2012-04-03 16:16 by youxin, 1128 阅读, 0 推荐, 收藏,
摘要:看下面一段代码:// C2361.cppvoid func( void ) { int x; switch (x) { case 0 : int i = 1; { int j = 1; } default : // C2361 error int k = 1; }}编译时会报错,Error C2361: initialization of (identifier) is skipped by (default) label,msdn解释是这样的,The initialization ofidentifiercan be skipped in... 阅读全文
上一页 1 ··· 243 244 245 246 247 248 249 250 251 ··· 269 下一页