![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
test
文章平均质量分 53
maqingli87
这个作者很懒,什么都没留下…
展开
-
POJ 2528 离散化+线段树
题目大意:市长竞选,在一个墙上贴海报,每个海报都有起点和终点,问最后有几张海报是可见的。参考1参考2参考3参考4#include #include #include using namespace std;struct node{ int x; int num;}s[20004];//用于离散化,存储一个端点struct tree{ int l,原创 2012-10-04 12:33:22 · 604 阅读 · 0 评论 -
重载输入输出运算符
class test{private: int x;public: friend istream& operator >>(istream & stream,test &other) { cout << "test input" << endl; other.x = 100; return stream; } friend ostream& operator <<(原创 2012-11-13 14:00:34 · 334 阅读 · 0 评论 -
找到符合签名的最小排列
You are given an array of n elements [1,2,....n]. For example {3,2,1,6,7,4,5}.Now we create a signature of this array by comparing every consecutive pir of elements. If they increase, write I else w原创 2012-11-13 13:50:37 · 477 阅读 · 0 评论 -
表达式求值 中缀树变后缀树
中缀表达式转化为后缀表达式中缀表达式和后缀表达式分别在向量IFX和PFX中,用栈S实现中缀式转为后缀式,对IFX中表达式从左到右扫描,设TOKEN是扫描读到的符号,转换算法可描述如下。 栈初始化从左向右扫描向量IFX,直到结尾: 1.从IPX中取出下一个TOKEN 2.CASE TOKEN OF '(': 将TOKEN压入栈S原创 2012-10-23 20:29:36 · 572 阅读 · 0 评论 -
哈夫曼树压缩 字符串编码
假设只有0-9这十个字符组成的字符串#define Size 10int freq[Size];string code[Size];string word;struct Node{ int id; int freq; Node *left; Node *right; Node(int freq_in):id(-1), freq(freq_in) { left = rig原创 2012-10-22 22:41:46 · 1159 阅读 · 0 评论 -
一个词典,一个字符矩阵,找出那些在字符举证中出现的单词
#define MAX 26struct Node{ bool isTail; char ch; Node* next[MAX]; Node():isTail(false), ch(' ') { for(int i = 0; i < MAX; ++i) next[i] = NULL; } Node(char ch_in):isTail(false), ch(ch_i原创 2012-10-22 21:25:31 · 729 阅读 · 0 评论 -
N个点的 费马点
平面中给定N个点的坐标(x, y), 找到离点(m, n)最近的一个点。 该点称为这N个点的 费马点。该问题是POJ上面的一个题目参考链接1参考链接2代码一#include #include #include using namespace std;#define MAX_NUM 128/* *http://www.programlife.net/poj-242原创 2012-10-22 16:25:11 · 1470 阅读 · 0 评论 -
LRU cache
struct Node{ int id; char val[100]; Node *prev; Node *next;};class DoubleLinkedList{public: DoubleLinkedList() { head = tail = NULL; size = 0; } int Size() { return size; } void原创 2012-10-21 16:16:54 · 327 阅读 · 0 评论 -
大整数 乘法
我的算法class Solution {public: string multiply(string num1, string num2) { int sa = num1.size(), sb = num2.size(); if(0 == sa || 0 == sb) return ""; vector res(sa + s原创 2012-10-17 22:35:27 · 339 阅读 · 0 评论 -
poj 1161 并査集
参考链接1参考链接2并査集。很多学生,每个学生可能属于一个或者多个社团。一个学生染病,其所在社团都有病。问一号学生得病了,一共有多少人得病。#include #include #include #include #include #include #include #include #include #include #include #inclu原创 2012-10-12 11:29:32 · 334 阅读 · 0 评论 -
heap sort 堆排序
堆排序 heap sort参考链接——1void Print(int arr[], int size){ if(NULL != arr) for(int i = 0; i < size; ++i) cout << arr[i] << ' '; cout << endl;}void MaxHeapify(int arr[], int idx, int size){原创 2012-10-10 16:43:39 · 283 阅读 · 0 评论 -
字符串中第一个只出现一次的字符
给定一个字符串,找出该字符串中第一个只出现一次的字符。char FirstNonRepeated(string& str){ //find the first char in str that appears only once //找到str中第一个只出现一次的字符 //假设只有ascii字符 short chars[256]; memset(chars, 0, 256);原创 2012-10-09 22:24:35 · 345 阅读 · 0 评论 -
两链表相交,寻找第一个交点
struct Node{ int val; Node *next; Node(int val_in):val(val_in), next(NULL) { }};Node* getTail(Node* head, int& size){ size = 0; if(NULL == head) return NULL; while(NULL != head->next)原创 2012-10-09 17:23:27 · 382 阅读 · 0 评论 -
单链表反转
struct Node{ int val; Node *next; Node(int val_in):val(val_in), next(NULL) { } Node(int val_in, Node *next_in):val(val_in), next(next_in) { }};Node* reverse(Node *head){ Node* ret = NUL原创 2012-10-09 17:32:48 · 299 阅读 · 0 评论 -
判断链表是否有环
struct Node{ int val; Node *next; Node(int val_in):val(val_in), next(NULL) { }};bool hasCircle(Node* head){ if(NULL == head) return false; Node *fast = head, *slow = head; while(NULL原创 2012-10-09 17:03:55 · 459 阅读 · 0 评论 -
实现double sqrt(double num)
C语言实现sqrt的几种方法#include #include #include #include /** * * @brief 牛顿迭代法求解 * @param [in]要开方的数 * @return 开方后的结果 * */double sqrt_1(double dNum){ double dVal, dLastVal; assert(dNum > 1e-转载 2012-10-09 11:34:09 · 1682 阅读 · 0 评论 -
Trie树 键树应用
给一个字典,然后给定一个字符串,求字典中所有以该字符串为前缀的单词。会有多次查询,要求通过预处理建立一个查询结构。可假设字典仅含有小写字母。struct Node{ bool isTail; Node *child[26]; Node() { isTail = false; for(int i = 0; i < 26; ++i) child[i] = NULL;原创 2012-11-13 15:15:16 · 466 阅读 · 0 评论