![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
oj
_noname
Ideas worth spreading.
展开
-
木棍问题
//木棍问题#include#includebool concatenate(int,int,int,int);int compare(const void *arg1,const void *arg2){ return *(int *)arg2-*(int *)arg1;}int sticks[100];bool used[100];int main(){ int n;原创 2015-07-24 22:42:00 · 1818 阅读 · 0 评论 -
基于递归的二叉树遍历
//基于递归的二叉树遍历#include#includestruct TreeNode{ int val; TreeNode *left,*right;};TreeNode *insertTree(TreeNode *root,int val){ TreeNode *newNode; if(root==NULL){ newNode=new原创 2015-07-27 20:50:59 · 494 阅读 · 2 评论 -
链表的应用:计算每个作业的运行时间
//链表的应用:计算每个作业的运行时间#include#includestruct Task{ char name[50]; char sDate[15]; char sTime[15]; char eDate[15]; char eTime[15]; int cost; Task *next;};struct Resource{ char ID[50]; Task *原创 2015-07-27 01:23:34 · 695 阅读 · 2 评论 -
二叉树的建立
//二叉树的建立#include#includestruct TreeNode{ int val; TreeNode *left,*right;};TreeNode *insertTree(TreeNode *root,int val){ TreeNode *newNode; if(root==NULL){ newNode=new TreeNode; newNode->原创 2015-07-27 20:22:38 · 513 阅读 · 2 评论 -
约瑟夫问题
//约瑟夫问题#include#include#define MAX_NUM 300int aLoop[MAX_NUM+10];main(){ int n,m,i; while(1) { scanf("%d%d",&n,&m); if(n==0) break; for(i=0;i<n;i++) aLoop[i]=i+1; int nPtr=0; fo原创 2015-07-06 21:25:41 · 518 阅读 · 0 评论 -
平衡二叉树
//平衡二叉树#include#includestruct TreeNode{ int val; int depth; TreeNode *left,*right;};void computeDepth(TreeNode *root){ int depth; if(root->left!=NULL) depth=root->left->depth; else dep原创 2015-07-27 22:10:07 · 645 阅读 · 2 评论 -
时区间时间的转换
//时区间时间的转换#include#includeint difference(char *zone1,char *zone2){ char zone[32][10]={"UTC","GMT","BST","IST","WET","WEST","CET","CEST","EET","EEST","MSK","MSD","AST","ADT","NST","NDT","EST","ED原创 2015-07-05 17:48:59 · 2271 阅读 · 0 评论 -
循环链表:约瑟夫问题
//循环链表#includestruct Monkey{ int ID; Monkey * next;};int main(){ Monkey *link,*monkey,*lastMonkey; int totalMonkeys,stride,count; printf("input total:\n"); scanf("%d",&totalMonkeys); print原创 2015-07-26 23:56:50 · 601 阅读 · 2 评论 -
最长公共子序列
//最长公共子序列#include#include#define MAX_LEN 1000char sz1[MAX_LEN];char sz2[MAX_LEN];int aMaxLen[MAX_LEN][MAX_LEN];int main(){ scanf("%s%s",sz1,sz2); while(sz1[0]!='@'){ int nLength1=strlen(原创 2015-07-26 22:20:50 · 573 阅读 · 2 评论 -
统计字符数
//poj:2742#include#includeint main(){ int cases; int sum[26],i,max; char str[1001]; scanf("%d",&cases); while(cases>0) { scanf("%s",str); int len=strlen(str); for(i=0;i<26;i++) sum原创 2015-06-15 11:09:48 · 586 阅读 · 0 评论 -
简单枚举的例子:生理周期
//简单枚举的例子:生理周期#includeint main(){ int p,e,i,d,j,n=1; scanf("%d%d%d%d",&p,&e,&i,&d); while(p!=-1&&e!=-1&&i!=-1&&d!=-1) { for(j=d+1;j<21252;j++) if((j-p)%23==0) break; for(;j<21252;j=j+23原创 2015-07-14 19:58:47 · 879 阅读 · 0 评论 -
数学模型中包括多个变量的例子:称硬币
//数学模型中包括多个变量的例子:称硬币#include#includechar left[3][7],right[3][7],result[3][7];bool isHeavy(char);bool isLight(char);int main(){ int n; char c; scanf("%d",&n); while(n>0) { for(int i=0;i原创 2015-07-15 23:57:18 · 970 阅读 · 0 评论 -
八皇后问题
//八皇后问题#include#includeint queenPlaces[92][8];int count=0;int board[8][8];void putQueen(int ithQueen);int main(){ int n,i,j; for(i=0;i<8;i++) { for(j=0;j<8;j++) board[i][j]=-1; for(原创 2015-07-23 21:31:11 · 528 阅读 · 0 评论 -
红与黑
//红与黑#includeint W,H;char z[21][21];int f(int x,int y){ if(x=W||y=H) return 0; if(z[x][y]=='#') return 0; else{ z[x][y]='#'; return 1+f(x-1,y)+f(x+1,y)+f(x,y-1)+f(x,y+1); }}int main(原创 2015-07-23 20:10:51 · 617 阅读 · 0 评论 -
递归-放苹果
//递归-放苹果#includeint count(int x,int y){ if(y==1||x==0) return 1; if(x<y) return count(x,x); return count(x,y-1)+count(x-y,y);}int main(){ int t,m,n,i; scanf("%d",&t); for(i=0;i<t;i++) {原创 2015-07-22 23:46:19 · 578 阅读 · 0 评论 -
逆波兰表达式
//逆波兰表达式#include#includedouble exp(){ char a[10]; scanf("%s",a); switch(a[0]) { case '+':return exp()+exp(); case '-':return exp()-exp(); case '/':return exp()/exp(); case '*':return原创 2015-07-22 23:05:07 · 509 阅读 · 0 评论 -
优化判断条件的例子:讨厌的青蛙
//优化判断条件的例子:讨厌的青蛙#include#includeint r,c,n;struct PLANT{ int x,y;};PLANT plants[5001];PLANT plant;int myCompare(const void *ele1,const void *ele2);int searchPath(PLANT secPlant,int dX,int d原创 2015-07-22 20:52:38 · 743 阅读 · 0 评论 -
菲波那契数列
//菲波那契数列#includeint f(int a){ if(a==1||a==2) return 1; else return f(a-1)+f(a-2);}int main(){ int n; scanf("%d",&n); for(int i=0;i<=n;i++) { int a; scanf("%d",&a); printf("%d\n"原创 2015-07-22 21:26:32 · 640 阅读 · 0 评论 -
二叉树
//二叉树#includeint common(int x,int y){ if(x==y) return x; if(x>y) common(x/2,y); else common(x,y/2);}int main(){ int m,n; scanf("%d%d",&m,&n); printf("%d\n",common(m,n)); return 0;}原创 2015-07-22 21:30:53 · 466 阅读 · 0 评论 -
遍历搜索空间的例子:熄灯问题
//遍历搜索空间的例子:熄灯问题#includeint puzzle[6][8],press[6][8];bool guess(){ int c,r; for(r=1;r for(c=1;c press[r+1][c]=(puzzle[r][c]+press[r][c]+press[r-1][c]+press[r][c原创 2015-07-20 22:18:14 · 628 阅读 · 0 评论 -
搜索空间中解不唯一的例子:完美立方
//搜索空间中解不唯一的例子:完美立方#include#includeint main(){ int n,a,b,c,d; long int cube[101]; scanf("%d",&n); for(int i=1;i<=n;i++) cube[i]=i*i*i; for(a=6;a<=n;a++) for(b=2;b<a-1;b++) { if(cube原创 2015-07-20 20:36:44 · 726 阅读 · 0 评论 -
帮助Jimmy
//帮助Jimmy#include#include#include#define MAX_N 1000#define INFINITE 1000000int t,n,x,y,max;struct Platform{ int Lx,Rx,h;};Platform aPlatform[MAX_N+10];int aLeftMinTime[MAX_N+10];int aRigh原创 2015-07-26 20:48:37 · 1189 阅读 · 2 评论 -
大整数加法
//大整数加法#include#include#define MAX_LEN 200int an1[MAX_LEN+10];int an2[MAX_LEN+10];char szLine1[MAX_LEN+10];char szLine2[MAX_LEN+10];int main(){ while(1) { scanf("%s",szLine1); scanf(原创 2015-07-11 21:45:07 · 574 阅读 · 0 评论 -
最长上升子序列
//最长上升子序列#include#include#define MAX_N 1000int b[MAX_N+10];int aMaxLen[MAX_N+10];int main(){ int N; int i=0,j=0; scanf("%d",&N); for(i=1;i<=N;i++) scanf("%d",&b[i]); aMaxLen[1]=1; for(i原创 2015-07-26 00:50:49 · 534 阅读 · 1 评论 -
计算题:装箱问题
//poj:1017#includeint main(){ int a,b,c,d,e,f,x,y,N; int u[4]={0,5,3,1}; while(1) { scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f); if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)break; N=f+d+e+(c+3)/4;原创 2015-06-10 10:05:51 · 1065 阅读 · 0 评论 -
简单计算题:校门外的树
input:500 3150 300100 200470 471output:298 #include int main(int argc,char **argv) { int L,i,j,n; bool trees[10001]; for(i=0;i<10001;i++) { trees[i]=true; } scanf("%d%d"原创 2015-05-23 21:15:49 · 877 阅读 · 0 评论 -
日历问题
//日历问题 #includeint type(int i);char week[7][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};int year[2]={365,366};int month[2][12]={31,28,31,30,31,30,31,31,30,21,30,原创 2015-06-25 19:34:34 · 1121 阅读 · 0 评论 -
细菌繁殖
//细菌繁殖#includeint main(){ int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int n; scanf("%d",&n); int month_1,day_1,Num,month_2,day_2; for(int i=0;i<n;i++) { scanf("%d%d%d%d%d",&month原创 2015-06-24 11:22:47 · 1571 阅读 · 0 评论 -
简单计算题:棋盘上的距离
输入样例2a1 c3f5 f8输出样例2 1 2 13 1 1 Inf#include#includeint main(){ int nCases,i; scanf("%d",&nCases); for(i=0;i<nCases;i++) { char begin[5],end[5]; scanf("%s %s",begin,end); in原创 2015-05-22 21:20:35 · 2863 阅读 · 0 评论 -
判断闰年
//poj:2733#include/*int main(){ int a; scanf("%d",&a); if(a%400==0||(a%4==0&&a%100!=0)) printf("Y"); else printf("N"); return 0;}*/int main(){ int a; scanf("%d",&a); if(a%4!=0)原创 2015-06-19 13:21:48 · 569 阅读 · 0 评论 -
CaesarCode
//poj:2975#include#includevoid decipher(char message[]);int main(){ char message[201]; gets(message); while(strcmp(message,"START")==0) { decipher(message); printf("%s\n",message); get原创 2015-06-18 14:52:29 · 597 阅读 · 0 评论 -
substring
//poj:2744#include#include int t,n; char str[101][101]; int searchMaxSubString(char *source) { int subStrLen=strlen(source); int sourceStrLen=strlen(source); int i,j; bool foundMaxSub原创 2015-06-17 11:47:02 · 513 阅读 · 0 评论 -
字符串处理487-3279
//poj:2974#include#include#includechar map[]="2223334445556667*77888999*";char str[80],telNumbers[100000][9];int compare(const void *elem1,const void *elem2){ return (strcmp((char *)elem1,(c原创 2015-06-16 12:14:44 · 1014 阅读 · 0 评论 -
简单计算题:填词
input:3 3 2EBGGEEEGEBEGGEEoutput:EEG#includeint main(int argc,char** argv){ int n,m,p; int characters[26]; int i,j; for(i=0;i<26;i++) { characters[i]=0; } scanf("%d%d%d",原创 2015-05-25 10:46:16 · 672 阅读 · 0 评论 -
花生问题
//花生问题#define MAX_NUM 55#include#includeint aField[MAX_NUM][MAX_NUM];int T,M,N,K;int main(){ scanf("%d",&T); for(int i=0;i<T;i++) { scanf("%d%d%d",&M,&N,&K); for(int m=1;m<=M;m++) fo原创 2015-07-08 23:29:11 · 742 阅读 · 0 评论 -
玛雅历
//玛雅历#include#includeconst int NAMELEN=10;char month1[19][NAMELEN]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet原创 2015-07-04 23:11:32 · 1311 阅读 · 0 评论 -
排列
//排列#include#include#define MAX_NUM 1024int an[MAX_NUM+10];int MyCompare(const void *e1,const void *e2){ return *((int *)e1)-*((int *)e2);}int main(){ int M; int n,k,i,j; scanf("%d",&M);原创 2015-07-10 22:59:13 · 517 阅读 · 0 评论 -
麦森数
//麦森数#include#include#include#define LEN 125void Multiply(int *a,int *b){ int i,j; int nCarry; int nTmp; int c[LEN]; memset(c,0,sizeof(int)*LEN); for(i=0;i<LEN;i++) { nCarry=0; for(j原创 2015-07-12 21:46:32 · 649 阅读 · 0 评论 -
大整数除法
//大整数除法#include#include#define MAX_LEN 200char szLine1[MAX_LEN+10];char szLine2[MAX_LEN+10];int an1[MAX_LEN+10];int an2[MAX_LEN+10];int aResult[MAX_LEN+10];int Substract(int *p1,int *p2,i原创 2015-07-12 19:48:43 · 1673 阅读 · 0 评论 -
大整数乘法
//大整数乘法#include#include#define MAX_LEN 200unsigned an1[MAX_LEN+10];unsigned an2[MAX_LEN+10];unsigned aResult[MAX_LEN*2+10];char szLine1[MAX_LEN+10];char szLine2[MAX_LEN+10];int main(){ g原创 2015-07-12 14:43:45 · 496 阅读 · 0 评论