随笔分类 -  c++

摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 const int nMax = 3000; 10 int A[nMax+1]; 11 int B[nMax+1];//用来每次5分法后保存要比较的值在A中的下... 阅读全文
posted @ 2018-06-10 20:38 myth_HG 阅读(1064) 评论(0) 推荐(0)
摘要:/*线性时间算法*/1 #include<iostream> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <algorithm> 5 using namespace std; 6 #define NMax 10010 7 int A[N 阅读全文
posted @ 2018-05-20 17:32 myth_HG 阅读(180) 评论(0) 推荐(0)
摘要:#include #include#include#includeusing namespace std;const int maxN=200;char s1[maxN],s2[maxN];int a[maxN],b[maxN];int **ans=new int*[maxN];int ret[2*... 阅读全文
posted @ 2015-10-01 11:29 myth_HG 阅读(448) 评论(0) 推荐(0)
摘要:/*N!Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 67077 Accepted Submission(s): 19228P... 阅读全文
posted @ 2015-09-30 11:56 myth_HG 阅读(238) 评论(0) 推荐(0)
摘要:/*Integer InquiryTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15874 Accepted Submission(... 阅读全文
posted @ 2015-09-29 19:40 myth_HG 阅读(297) 评论(0) 推荐(0)
摘要:/*二分查找(范围统计)*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 1000int A[maxn];int lower_bound1(int *A,int x,int y,int v)//二分查找求下界{ int m; while(x=v)//看区别 y=m; else x=m+1; } return x;}int upper_bound1(int *A,in... 阅读全文
posted @ 2013-07-23 17:34 myth_HG 阅读(351) 评论(0) 推荐(0)
摘要:/*困难串(无两个相邻的重复字串)*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 1000int cnt,n,L;int S[maxn];int dfs(int cur)//返回0表示已经得到解,无须继续搜索{ int i,ok,j,k,equals; if(cnt++==n)//输出方案 { for(i=0; i<cur; i++) printf("%c",'A'+S[i]); ... 阅读全文
posted @ 2013-07-22 16:25 myth_HG 阅读(436) 评论(0) 推荐(0)
摘要:/*n皇后问题*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 1000int n,tot,col[maxn],vis[3][maxn];void search(int cur){ int i,j; if(cur==n) { tot++; printf("----解%d:----\n",tot); for(i=0; i<n; i++) { printf... 阅读全文
posted @ 2013-07-22 10:45 myth_HG 阅读(277) 评论(0) 推荐(0)
摘要:/*子集生成的各种实现*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 26000int A[maxn];int B[maxn];int n,sum;void print_subset(int n,int *A, int cur)//用增量法实现子集生成{ int i; for(i=0; i < cur ; i++) { printf("%d ",A[i]);//打印当前集合 if(i==0) ... 阅读全文
posted @ 2013-07-21 18:47 myth_HG 阅读(358) 评论(0) 推荐(0)
摘要:/*经典移动小球*/#include #include#include#include#include#include#include#includeusing namespace std;#define maxn 26000int left1[maxn],right1[maxn];void link(int x,int y){ right1[x]=y; left1[y]=x;}int main(){ int i,n,casen,x,y,k; char type[2]; while(~scanf("%d%d",&n,&casen)) { for... 阅读全文
posted @ 2013-07-20 20:31 myth_HG 阅读(247) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <iostream>#include<algorithm>#include<windows.h>#include<math.h>using namespace std;#define Max 20#define LT(a,b) ((a)<(b))void setcolor(int color){ HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hout,color);}typedef s 阅读全文
posted @ 2013-01-17 16:50 myth_HG 阅读(547) 评论(0) 推荐(0)
摘要:#include<stdio.h>#include<afx.h> #include<time.h>#include<string>#include <windows.h>int main(){ CTime t = CTime::GetCurrentTime(); //获取系统日期,存储在t里面 int d=t.GetDay();int y=t.GetYear();int m=t.GetMonth();int h=t.GetHour();int mm=t.GetMinute();int s=t.GetSecond();int w=t.G 阅读全文
posted @ 2012-12-14 13:59 myth_HG 阅读(263) 评论(0) 推荐(0)
摘要:#pragma warning (disable:4786) #include<cstdio>#include<iostream>#include<string>#include<string.h>#include<set>using namespace std;int main(){ set<string> st; string s=""; char c; while((c=getchar())!='#') { s+=c; while(c!='\n') { while( 阅读全文
posted @ 2012-11-17 18:40 myth_HG 阅读(324) 评论(0) 推荐(0)
摘要:/*最长回文子串*/#include<iostream>#include<string.h>#include<ctype.h>using namespace std;#define Max 5000 +10char buf[Max],s[Max];int p[Max];int main(){ int n,m=0,max=0; int i,j; //int k; int x,y; fgets(buf,sizeof(s),stdin); n=strlen(buf); for(i=0;i<n;i++) if(isalpha(buf[i])) ... 阅读全文
posted @ 2012-11-04 14:07 myth_HG 阅读(152) 评论(0) 推荐(0)
摘要:/*交换两个数不用中间变量*/#include<iostream>using namespace std;int main(){ int a,b; scanf("%d%d",&a,&b); a=a+b; b=a-b; a=a-b; printf("%d %d\n",a,b); return 0;} 阅读全文
posted @ 2012-11-01 23:34 myth_HG 阅读(127) 评论(0) 推荐(0)
摘要:/*清除缓存cin.sync();*/#include <iostream>using namespace std;int main () { char first, second; cout << "Please, enter a word: "; first=cin.get(); cin.sync(); cout << "Please, enter another word: "; second=cin.get(); cout << "The first word began by " 阅读全文
posted @ 2012-10-31 19:39 myth_HG 阅读(424) 评论(0) 推荐(0)
摘要:/*最fibonacci的定义*/#include<iostream>using namespace std;int main(){ __int64 f[10000],n; f[0]=0;f[1]=1;f[2]=1; while(scanf("%I64d",&n)!=EOF) { for(__int64 i=2;i<=n;i++) f[i]=f[i-1]+f[i-2]; printf("%I64d\n",f[n]); } return 0;}/*用矩阵相乘实现fibonacci(本题是求f(n)最后... 阅读全文
posted @ 2012-10-27 19:46 myth_HG 阅读(316) 评论(0) 推荐(0)
摘要:#include<iostream>using namespace std;class Base{public: virtual void Show()const{cout<<"调用Base::Show()"<<endl;}};class Derived:public Base{public: void Show()const{cout<<"调用Derived::Show()"<<endl;}};void Refers1(const Base &obj){ obj.Show();}voi 阅读全文
posted @ 2012-10-15 15:53 myth_HG 阅读(151) 评论(0) 推荐(0)
摘要:/*也就是说因为goto只管goto到指定的内容 只要是在这个函数体类 任何位置都可以他不是循环 不会返回到goto位置 但是当goto的内容在共同之前 可以类似于循环如 label:...语句goto label; 由于label在goto之前 所以按照正常的顺序他会再遇到goto label 从而循环下去但是如果在后面呢语句1goto label;语句2label:语句3那么语句2不运行 直接从语句3运行下去 不会再循环了由于goto语句看起来很散 因此在循环的时候最好不要用但goto也有他独到的用处 用于那种需要直接跳转到某个语句的情况赞同11|*/#include<iostrea 阅读全文
posted @ 2012-10-14 21:54 myth_HG 阅读(222) 评论(0) 推荐(0)
摘要:/*类型转换函数一般用于将类型转换为基本数据类型,但也可以转换为构造类型,如下*/#include <stdlib.h>#include<iostream>#include <stdio.h>#include<cmath>using namespace std;class Point{private:double x;public:Point(double a= 0):x(a){};void Show(){cout<<"x:"<<x<<endl;}};class A{protected:do 阅读全文
posted @ 2012-10-11 22:33 myth_HG 阅读(238) 评论(0) 推荐(0)