cjweffort

博客园 首页 联系 订阅 管理

2013年3月12日

摘要: the final judge data is so big that so many times test result is time limit.To refer the idea from the Internet,solve this problem need to utilize the hash thinking.As a student name consists of 3 capital English letters plus a one-digit number,from 0 to 26*26*26*10*(courses+2)(the total number of c 阅读全文
posted @ 2013-03-12 20:11 cjweffort 阅读(174) 评论(0) 推荐(0) 编辑

摘要: give the hash key to every student,then sort the students in increasing order of the students name.to every course,traverse the list of student who select the course,his own hash key will exists.traverse every students,if he has the hash key(select the course) then must print his name.as we had sort 阅读全文
posted @ 2013-03-12 17:15 cjweffort 阅读(191) 评论(0) 推荐(0) 编辑

摘要: two pointsdon't used hash table#include #include using namespace std; const int INF=0x7fffffff; const int N=100003; int coin[N]; int n,needSum; void findCoins(){ int i=0,j=n-1; int lowMinCoin=INF,left=-1,right=-1; while(ineedSum) j--; else i++; } if(left==-1&&right==-1) printf("No.. 阅读全文
posted @ 2013-03-12 11:26 cjweffort 阅读(170) 评论(0) 推荐(0) 编辑

摘要: 编程之美上的题目。// 1049. Counting Ones.cpp: 主项目文件。 #include "stdafx.h" #include #include long long countOnes(int num){ long long ret=0; int expPower=1; while(num/expPower!=0){ int iLowNumber=num%expPower; int curNum=num/expPower%10; int iHighNumber=num/expPower/10; if(curNum<1){ ret+=iHig... 阅读全文
posted @ 2013-03-12 10:45 cjweffort 阅读(229) 评论(0) 推荐(0) 编辑

摘要: 简单的hash题// 1050. String Subtraction.cpp: 主项目文件。 #include "stdafx.h" #include #include const int N=10003; char str[N]; char hash[600]; int main() { while(gets(str)){ memset(hash,0,sizeof(hash)); if(strlen(str)==0) break; char ch; while((ch=getchar())!='\n'){ if(!hash[ch]) hash... 阅读全文
posted @ 2013-03-12 10:11 cjweffort 阅读(121) 评论(0) 推荐(0) 编辑

摘要: 没仔细审题,走了很多弯路。题目要求:内存中有很多散列的节点,可能构成不止一个链表。其次要注意空链表的情况。// 1052. Linked List Sorting.cpp: 主项目文件。 #include "stdafx.h" #include #include using namespace std; const int N=100003; typedef struct Node{ int add,data,next; }Node; Node node[N],list[N]; int n; bool cmp1(Node m1,Node m2){ return m1.add 阅读全文
posted @ 2013-03-12 10:09 cjweffort 阅读(142) 评论(0) 推荐(0) 编辑

摘要: 经典的树的遍历问题,在插入每个非叶节点的邻接点时,维护一个优先队列,优先插入数据比较大的节点,从而在实施搜索时一旦碰到叶子节点,且该路径上数据总和为所需值时,直接输出该路径上的各数据。// 1053. Path of Equal Weight.cpp: 主项目文件。 #include "stdafx.h" #include #include #include #include using namespace std; const int N=103; int hashTable[N]; bool used[N]; int needSum; typedef struct No 阅读全文
posted @ 2013-03-12 08:46 cjweffort 阅读(140) 评论(0) 推荐(0) 编辑

摘要: 大数问题,字符串处理。// 1024. Palindromic Number.cpp: 主项目文件。 #include "stdafx.h" #include #include bool isPalindromic(char *str){ int length=strlen(str); for(int i=0,j=length-1;i=0;i--) rev[cnt++]=str[i]; rev[cnt]='\0'; } void plus(char *str,char *rev){ char sum[151]; memset(sum,0,sizeof(sum 阅读全文
posted @ 2013-03-12 00:07 cjweffort 阅读(151) 评论(0) 推荐(0) 编辑