摘要: #include <iostream>#include <string>#include <vector>using namespace std;//注意使用结构体来表示牛奶struct struct_milk{string brand;double price;double volumn;int day;double day_price;};int main(... 阅读全文
posted @ 2010-04-25 20:40 北海小龙 阅读(312) 评论(0) 推荐(0) 编辑
摘要: //求阶乘的位数//方法:使用10的对数解决#include <iostream>#include <math.h>using namespace std;int main(){int count;cin>>count;while(count--){int number;cin>>number;double sum = 0;for(int i = 1... 阅读全文
posted @ 2010-04-25 20:39 北海小龙 阅读(255) 评论(0) 推荐(0) 编辑
摘要: //主要是解题的思路//f(0) = 7//f(1) = 11//因为f(n)要模3,所以我先将f(0)和f(1)模的3,所以现在是//f(0) = 7 % 3 = 1//f(1) =11 % 3 = 2//f(3) = 3 % 3 = 0//f(4) = 2 % 3 = 2//f(5) = 2 % 3 = 2//f(6) = 4 % 3 = 1//f(7) = 3 % 3 = 0//f(8) =... 阅读全文
posted @ 2010-04-25 20:39 北海小龙 阅读(415) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;int main(){int number;cin>>number;//cout<<endl;注意此处一定不要加endl,否则会出现格式错误的警告。int n,m;for(int i=0;i<number;i++){int j = 0;cin>>n>>m;... 阅读全文
posted @ 2010-04-25 20:38 北海小龙 阅读(217) 评论(0) 推荐(0) 编辑
摘要: //思路:使用周期实现,周期的开始不一定从头开始#include <iostream>using namespace std;int main(){int a,b;long n;while(cin>>a>>b>>n && (a+b+n)!=0){int result[200] = {0,1,1};if(n<3){cout<... 阅读全文
posted @ 2010-04-25 20:37 北海小龙 阅读(288) 评论(0) 推荐(0) 编辑
摘要: //注意:尽量使用C++的string类型,而不要使用c字符串数组#include <iostream>#include <string>using namespace std;int digit_sum(int digit);int main(){string digit;cin>>digit;//这里读入的是string类型,不是int类型,便于求各个位数和... 阅读全文
posted @ 2010-04-25 20:37 北海小龙 阅读(300) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <vector>#include <string>using namespace std;//使用结构体实现typedef struct{string color;int time;}balloon;vector<balloon> balloons;void popular_color();vo... 阅读全文
posted @ 2010-04-25 20:36 北海小龙 阅读(126) 评论(0) 推荐(0) 编辑
摘要: //求最小公倍数//思路:先求两个数的最小公倍数,前两个数的最小公倍数与第三个数再求最小公倍数,求出最小公倍数后接着与第四个数相求。//求两个数的最小公倍数:利用辗转相除法#include <iostream>using namespace std;int gcd(int a,int b);int main(){ int row,col;cin>>row;for(int i... 阅读全文
posted @ 2010-04-25 20:35 北海小龙 阅读(395) 评论(0) 推荐(0) 编辑
摘要: //整数划分问题 思路:见《算法分析与设计》12页//注:使用递归会出现超时的情况,所以本程序将递归改成迭代的形式#include <iostream>using namespace std;int main(){int a[121][121]; //a[i][j]代表整数i最大数不超过jfor(int n=1;n<121;n++){for(int m=1;m<n+1;m+... 阅读全文
posted @ 2010-04-25 20:33 北海小龙 阅读(456) 评论(0) 推荐(0) 编辑
摘要: //Prim算法求最小生成树#include <iostream>using namespace std;#define arraysize 501int maxData = 0x7fffffff;//设定最大值int dis[arraysize][arraysize];bool final[arraysize];int d[arraysize];int N;void prim(){i... 阅读全文
posted @ 2010-04-25 20:31 北海小龙 阅读(144) 评论(0) 推荐(0) 编辑