- 博客(24)
- 资源 (2)
- 收藏
- 关注
原创 HDU_2095find your present (2)
http://acm.hdu.edu.cn/showproblem.php?pid=2095本题如果知道位运算那么将十分简单,其中需要用到^(异或符)。真异或假的结果是真,假异或真的结果也是真,真异或真的结果是假,假异或假的结果是假。就是说两个值不相同,则异或结果为真。反之,为假。 不同为1,相同为0,如1001异或1010等于0011.(来自百度百科http://baike.baidu.
2012-08-04 14:44:42
338
原创 HDU_2072单词数
http://acm.hdu.edu.cn/showproblem.php?pid=2072此题只需将句子中的字符串分开然后进行比较即刻。#include #include char str[10005];char a[100][25];int main(){ int count,i,j,f; while(gets(str)&&strcmp(str,
2012-08-03 22:36:22
874
1
原创 插入排序
(1) 首先对数组的前两个数据进行从小到大的排序(2) 接着将第3个数据与排好序的两个数据比较,将第3个数据插入到合适的位置(3) 然后,将第3个数据插入到已排好序的前三个数据中(4) 重复以上操作直至排序结束//插入排序 #include void InsertionSort(int* a,int n){ int i,j,t,h; for(i=
2012-08-02 20:15:45
343
原创 HDU_1020Encoding
http://acm.hdu.edu.cn/showproblem.php?pid=1020#include #include #define MAX 10005int main(){ char c,str[MAX]; int n,i,k,len; scanf("%d",&n); while(n--) {
2012-08-02 11:22:34
242
原创 类实现只Stack
#include class Node{public: Node* pre; int num; Node* next; Node() { pre=NULL; next=NULL; } Node(int num):num(num) { pre=NULL; next
2012-07-24 18:08:53
279
原创 类实现只Queue
#include class Node{public: Node* pre; int num; Node* next; Node() { pre=NULL; next=NULL; } Node(int num):num(num) { pre=NULL; next
2012-07-24 18:08:26
265
原创 类实现之二叉树
#include #include using namespace std;class Node{public: Node* father; int num; Node* left; Node* right; Node() { father=NULL; left=NULL; right=NULL;
2012-07-24 18:06:10
432
原创 类实现之LinkedList
#include class Node{public: Node* pre; int num; Node* next; Node() { pre=NULL; next=NULL; } Node(int num):num(num) { pre=NULL; next
2012-07-24 18:05:33
361
原创 类实现之ArrayList
#include class ArrayList{public: int* p; int length; int size; ArrayList() { p=new int[5]; length=5; size=0; } ~ArrayList() { } v
2012-07-24 18:04:34
285
原创 队列
#include #include #include #define QUEUELEN 15typedef struct{ char name[10]; int age;}DATA;typedef struct{ DATA data[QUEUELEN]; int head; int tail;}SQType;SQType *SQT
2012-06-22 21:50:27
250
原创 栈
#include #include #include #define MAXLEN 50typedef struct{ char name[10]; int age;}DATA;typedef struct stack{ DATA data[MAXLEN+1]; int top;}StackType;StackType *STInit()
2012-06-21 14:14:12
240
原创 HDU_1008 Elevator
http://acm.hdu.edu.cn/showproblem.php?pid=1008 #include using namespace std;int main(){ int temp,ci,ceng,N,last; while(cin>>ci) { if(ci==0) break; N=ci; temp=0; l
2012-06-20 23:20:45
274
原创 HDU_1004 Let the Balloon Rise
http://acm.hdu.edu.cn/showproblem.php?pid=1004此题考察对map的使用 #include #include #include using namespace std;int main(){ int n; map balloon; string color; while(cin>>n&&n)
2012-06-20 23:12:22
288
原创 链表
#include #include #include typedef struct{ char key[10];//关键字 char name[20]; int age;}Data;//数据节点类型typedef struct Node//定义链表结构{ Data nodeData; struct Node *nextNode;}CLType
2012-06-19 15:25:17
269
原创 HDU_1301 Jungle Roads
http://acm.hdu.edu.cn/showproblem.php?pid=1301#include #include using namespace std;struct edge{ int u,v,w;}node[900];int parents[900];void UFset(){ for(int i=0;i<900;i++) parent
2012-06-17 21:05:02
308
原创 HDU_1233 还是畅通工程
http://acm.hdu.edu.cn/showproblem.php?pid=1233#include #include using namespace std;struct edge{ int u,v,w;}node[5005];int father[5005];void Init(int n){ for(int i=0;i<=n;i++) fath
2012-06-17 21:01:03
255
原创 冒泡排序
(1) 对数组中的各数据,一次比较相邻的两个元素大小。(2) 如果前面的数据大于后面的数据,就交换两个数据。经过第一轮的多次排序之后,便可把最小的数据排好。(3) 然后,再用同样的方法把剩下的数据诸葛进行比较,最后便可按照从小到大的顺序排好数组中个数据的顺序。//冒泡排序#include void BubbleSort(int *a,int len){ int i,j,tem
2012-06-17 06:30:32
212
原创 选择排序
(1) 首先从原始数组中选择最小的一个数据,将其和位于第1个位置的数据交换(2)接着从剩下的n-1个数据中选择最小的一个元素,将其和第2个位置的数据和第2个位置的数据交换(3)然后这样不断重复,知道最后两个数据交换。最后,便完成了对原始数组从小到大的排序。#include void SelectionSort(int *a,int len){ int i,j,k,temp
2012-06-17 06:29:06
280
原创 HDU_1248寒冰王座
http://acm.hdu.edu.cn/showproblem.php?pid=1248此题用到母函数,由题意可知需求出一个在现有金钱范围内的最大消费,所以可以开一个数组f[n],其中n是现有金钱数量,只要求出n在现有范围内最大时候的消费金额即可。循环求出f[n]的最大值,用到从题意中推到出的公式f[n-k]+k>f[n],其中为单件物品的价格,代码如下:#include #in
2012-06-17 06:28:06
386
原创 HDU_1257最少拦截系统
http://acm.hdu.edu.cn/showproblem.php?pid=1257此题只需进行多次循环将所有以递减的数列找全即可解答。技巧:可设置一个判断的值来判断该高度是否一辈拦截,进而可以防止已经被拦截的高度再次被纳入判断范围。//贪心 #include #include using namespace std;struct node{ int h
2012-06-17 06:24:56
317
原创 最小公倍数与最大公约数
两个数的最小公倍数与最大公约数#include #include using namespace std;int gcd(int a,int b){ if(a<b) { int temp=a; a=b; b=temp; } return b==0 ? a:gcd(b,a%b);}int lcm(int a,int b){
2012-06-17 06:23:55
245
原创 HDU_1282回文数猜想
http://acm.hdu.edu.cn/showproblem.php?pid=1282解答此题关键在于回文数的判断,而判断一个数是否是回文数可采用将一个数各个位上的数字分开倒叙重新组合,然后与原数比较。#include #include using namespace std;int judge(int n){ int b[20]; int res=0,k=0
2012-06-17 06:22:47
1220
原创 顺序表
#include #include #define MAXLEN 100 //定义顺序表的最大长度typedef struct{ char key[10]; //节点的关键字 char name[20]; int age;}DATA; //定义节点类型typedef struct //定义顺序表结构{ D
2012-06-17 06:18:11
279
原创 HDU_1069Monkey and Banana
http://acm.hdu.edu.cn/showproblem.php?pid=1069题意:有几种边长不等的长方体,每种个数不限,下面就是堆积这些长方体,上一层的面积必须小于下一层的面积,而且,上一层的各个边都不能大于下一层的。每个长方体都有高度,求最高能堆积的高度。由题意可知每个长方体有长宽高,也因此可以以任意一面作为底面而与地面垂直的的边作为高故每个长方体可大致划分为三个不同的形
2012-06-17 06:16:43
427
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人