摘要:
hash// 1023. Have Fun with Numbers.cpp: 主项目文件。 #include "stdafx.h"
#include #include int hash[10]; void doubleOperate(char *str,char *pStr){ } int main()
{ memset(hash,0,sizeof(hash)); char str[23],pStr[23]; gets(str); int length=strlen(str); for(int i=0;str[i];i++) hash[str[i]-'0' 阅读全文
摘要:
字符串处理能力有待提高// 1022. Digital Library.cpp: 主项目文件。 #include "stdafx.h"
#include #include #include using namespace std; const int N=10003;
typedef struct Book{ char info[6][83]; //int id,time; //char title[83],author[83],publisher[83]; char keyWord[8][13]; int keys;
}Book;
Book books[N];
int n 阅读全文
摘要:
考察连通分量个数,用搜索或并查集,并查集效率较高;求最深的树根节点,用dfs// 1021. Deepest Root.cpp: 主项目文件。 #include "stdafx.h"
#include #include #include using namespace std; const int N=10003;
bool used[N];
vector edge[N];
vector needRoot;
int maxLevel,tLevel,n; void dfs(int cur,int level){ used[cur]=true; if(level>=tLe 阅读全文
摘要:
典型的数据结构体,根据后序和中序确定树,然后层序遍历该二叉树。// 1020. Tree Traversals.cpp: 主项目文件。 #include "stdafx.h"
#include #include #include using namespace std; typedef struct BitNode{ int value; BitNode *lchild,*rchild;
}BitNode; void createTree(BitNode *&root,int *in,int l1,int h1,int *post,int l2,int h2){ i 阅读全文
摘要:
注意判定素数时考虑0,1,2,3几种情况// 1015. Reversible Primes.cpp: 主项目文件。 #include "stdafx.h"
#include #include bool isPrime(int num){ if(num==0||num==1) return false; if(num==2||num==3) return true; for(int i=2;i=0){ scanf("%d",&D); if(N==0||N==1){ puts("No"); continue; } bool ta 阅读全文
摘要:
考察并查集,注意:边数可能很大,利用动态数组自动管理。// 1013. Battle Over Cities.cpp: 主项目文件。 #include "stdafx.h"
#include #include using namespace std; const int N=1003;
int fa[N];
typedef struct EDGE{ int from,to;
}EDGE;
vector road;
int n,m,enemy; void init(){ for(int i=0;i<N;i++) fa[i]=-1;
} int findSet(int x 阅读全文