桑海

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年4月2日

摘要: WC:View Code 1 #include<iostream> 2 #include<string> 3 #include<vector> 4 #include<algorithm> 5 using namespace std; 6 7 string judge(string &s) 8 { 9 int i = 0;10 for(; i < s.size() && s[i] == '0'; ++i);11 string t(s.begin()+i, s.end());12 if(i == s.si 阅读全文
posted @ 2013-04-02 21:53 桑海 阅读(209) 评论(0) 推荐(0) 编辑

摘要: View Code 1 #include<iostream> 2 using namespace std; 3 4 int f(int n) 5 { 6 int sum = 0; 7 while(n) 8 { 9 sum += n%10;10 if(sum > 9)11 sum = sum %10 + sum/10;12 n /= 10;13 }14 return sum;15 }16 int main()17 {18 int n;19 while(cin >> ... 阅读全文
posted @ 2013-04-02 20:31 桑海 阅读(182) 评论(0) 推荐(0) 编辑

摘要: 刚还是还以为是简单的a==b,汗,重新审题如下:View Code 1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 int judge(char ch) 6 { 7 if(ch == '-') 8 return -1; 9 return 0;10 }11 int for_Locate(string a)12 {13 int i = 0;14 if(a[0] == '-' || a[0] == '+')15 i = 1;16 for(;.. 阅读全文
posted @ 2013-04-02 17:16 桑海 阅读(312) 评论(0) 推荐(0) 编辑

摘要: 2057 1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 void reverse(string& a) 6 { 7 int len = a.size(); 8 for(int i = 0; i < len/2; ++i) 9 { 10 char t = a[i]; 11 a[i] = a[len-i-1]; 12 a[len-i-1] = t; 13 } 14 } 15 16 void exchange(s... 阅读全文
posted @ 2013-04-02 15:50 桑海 阅读(136) 评论(0) 推荐(0) 编辑

2013年3月29日

摘要: 2072:View Code 1 #include<iostream> 2 #include<vector> 3 #include<string> 4 #include<algorithm> 5 using namespace std; 6 7 int end(string str) 8 { 9 for(int i = 0; i < str.size(); ++i)10 if(str[i] == '#')11 return 1;12 return 0;13 }14 /*15 int count(string str)16 { 阅读全文
posted @ 2013-03-29 12:12 桑海 阅读(205) 评论(0) 推荐(0) 编辑

2013年3月27日

摘要: 杭电2056:Rectangles博客:KingsView Code 1 #include<iostream> 2 #include<iomanip> 3 using namespace std; 4 5 class p 6 { 7 public: 8 double x; 9 double y;10 friend istream& operator >>(istream& in, p& x);11 };12 13 istream& operator >>(istream& in, p& a)14 { 阅读全文
posted @ 2013-03-27 20:52 桑海 阅读(267) 评论(0) 推荐(0) 编辑

2013年3月26日

摘要: 杭电2048相关知识充电转自:错排公式分类:数论关于程序2012-06-08 19:07335人阅读评论(0)收藏举报n2错排问题错排问题就是一种递推式,不过它比较著名且常用,所以要熟记!方法一:n各有序的元素应有n!种不同的排列。如若一个排列式的所有的元素都不在原来的位置上,则称这个排列为错排。任给一个n,求出1,2,……,n的错排个数Dn共有多少个。递归关系式为:D(n)=(n-1)(D(n-1)+D(n-2))D(1)=0,D(2)=1可以得到:错排公式为f(n) = n![1-1/1!+1/2!-1/3!+……+(-1)^n*1/n!]其中,n!=1*2*3*.....*n,特别地,有 阅读全文
posted @ 2013-03-26 20:13 桑海 阅读(176) 评论(0) 推荐(0) 编辑

2013年2月24日

摘要: 2000:ASCII码排序View Code 1 #include<iostream> 2 #include<iomanip> 3 using namespace std; 4 5 const double PI = 3.1415927; 6 int main() 7 { 8 double r; 9 while(cin >> r)10 {11 cout.precision(3);12 cout.setf(ios::fixed);13 cout << 4*PI*r*r*r/3 << endl;14 }15 return 0;16... 阅读全文
posted @ 2013-02-24 20:31 桑海 阅读(280) 评论(0) 推荐(0) 编辑

摘要: Problem DescriptionFatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for a 阅读全文
posted @ 2013-02-24 15:05 桑海 阅读(326) 评论(0) 推荐(0) 编辑

摘要: 转自:VincentCZW1.qsort函数:原型:void qsort(void *base, int nelem, int width, int (*fcmp)(const void *,const void *));功能:使用快速排序例程进行排序参 数:1 待排序数组首地址2 数组中待排序元素数量3 各元素的占用空间大小4 指向函数的指针,用于确定排序的顺序说明:qsort函数是ANSI C标准中提供的,其声明在stdlib.h文件中,是根据二分法写的,其时间复杂度为n*log(n)。qsort要求提供的函数是需要自己定义的一个比较函数,比较函数使得qsort通用性更好。有了比较函数qs 阅读全文
posted @ 2013-02-24 14:53 桑海 阅读(241) 评论(0) 推荐(0) 编辑