摘要:
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 阅读全文
摘要:
1018. Public Bike Management (30)时间限制400 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThere is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.The 阅读全文
摘要:
题意要求最大子序列和,一道很经典的题目,可以用贪心算法解之~~// 1007. Maximum Subsequence Sum.cpp: 主项目文件。 #include "stdafx.h"
#include int main()
{ int n; while(~scanf("%d",&n)){ int leftTemp,left,right,curSum=0,maxSum=-1; int first,end; bool tag=false; for(int i=0;i=0) tag=true; if(curSummaxSum){ maxS... 阅读全文
摘要:
http://ac.jobdu.com/problem.php?cid=1040&pid=65题目描述: 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?输入: 测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( #include #include #include #include #include #include #include #include #inclu... 阅读全文
摘要:
http://ac.jobdu.com/problem.php?cid=1040&pid=64题目描述: 对于一个十进制数A,将A转换为二进制数,然后按位逆序排列,再转换为十进制数B,我们乘B为A的二进制逆序数。 例如对于十进制数173,它的二进制形式为10101101,逆序排列得到10110101,其十进制数为181,181即为173的二进制逆序数。输入: 一个1000位(即10^999)以内的十进制数。输出: 输入的十进制数的二进制逆序数。样例输入:173样例输出:181// 题目65:10进制 VS 2进制.cpp: 主项目文件。 #include "stdafx.h& 阅读全文