自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(91)
  • 收藏
  • 关注

原创 知识库问答和数据库问答

与知识库问答类似,但数据库问答不在是去切分文本匹配相似度,而是通过大模型以及text2sql的方式使用sql语句查询数据库中的数据,进行回答。

2024-07-17 21:59:15 910 1

转载 C++ 优先队列priority_queue,如何定义大小根堆

1.代码如下(示例):priority_queue < int >默认构建的是一个大根堆,所以每次从头取数据得到的是一个从大到小的队列排序.priority_queue< int> 实际上等价于 priority_queue<int, vector, less< int>>。#include <iostream>#include <queue>using namespace std;void common_sort

2021-09-08 15:56:51 7237 2

原创 leetcode(每日一题)--523. 连续的子数组和

题目https://leetcode-cn.com/problems/continuous-subarray-sum/代码和解析(Java)class Solution { public boolean checkSubarraySum(int[] nums, int k) { //前缀和+HashSet+同余定理 //将sum[j]-sum[i-1]=n*k化为sum[j]/n - sum[i-1]/n = k //因为k为整数,所以sum[j

2021-06-02 19:09:03 205

转载 leetcode --208. 实现 Trie (前缀树)

题目https://leetcode-cn.com/problems/implement-trie-prefix-tree/代码解析部分摘自:https://leetcode-cn.com/problems/implement-trie-prefix-tree/solution/trie-tree-de-shi-xian-gua-he-chu-xue-zhe-by-huwt/typedef struct { struct Trie* children[26];//字母映射表 boo

2021-04-14 21:20:48 177

原创 leetcode -- 783. 二叉搜索树节点最小距离

题目https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/给你一个二叉搜索树的根节点 root ,返回 树中任意两不同节点值之间的最小差值 。代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *righ

2021-04-13 21:07:35 124

原创 leetcode -- 16. 最接近的三数之和

题目https://leetcode-cn.com/problems/3sum-closest/给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。示例:输入:nums = [-1,2,1,-4], target = 1输出:2解释:与 target 最接近的和是 2 (-1 + 2 + 1 = 2) 。提示:3 <= nums.length <=

2021-04-06 21:14:22 74

原创 leetcode -- 15. 三数之和

题目https://leetcode-cn.com/problems/3sum/给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组。注意:答案中不可以包含重复的三元组。示例 1:输入:nums = [-1,0,1,2,-1,-4]输出:[[-1,-1,2],[-1,0,1]]示例 2:输入:nums = []输出:[]示例 3:输入:nums = [0]输出:[]代码

2021-04-06 20:43:28 84

原创 POJ 1384 Piggy-Bank

完全背包的应用#include<stdio.h>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>using namespace std;#define INF 0x3f3f3f3f/*10 110//e空罐重量,f满罐的重量2//给定货币中使用的各种硬币的数量1 1//p:硬币价值;W:重量30 50*/int p[1005],w[

2021-04-06 17:26:56 70

原创 HDU 1213 How Many Tables AND HDU 1232 畅通工程(简单并查集)

题目直接放链接了:12131232一、分析简单的并查集算法的使用二、代码1.代码如下(示例):#include<iostream>#include<stdio.h>#include<cstring>#include<algorithm>using namespace std;int pre[1005];void init(int n){ for(int i=0;i<=n;i++) { pre

2021-03-22 20:26:01 84

原创 HDU 1237 简单计算器

题目Problem Description读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值。Input测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。Output对每个测试用例输出1行,即该表达式的值,精确到小数点后2位。Sample Input1 + 24 + 2 * 5 - 7 / 110Sample Output3.0013.36一

2021-03-22 18:47:55 123 1

原创 HDU 1159 Common Subsequence (动态规划--最大公共子序列)

题目Problem DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, …, xm> another sequence Z = <z1, z2, …, zk> is a subsequence of X if there exists a strict

2021-03-19 20:41:58 86

原创 HDU 1728 逃离迷宫

题目链接Problem Description  给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,gloria是个没什么方向感的人,因此,她在行走过程中,不能转太多弯了,否则她会晕倒的。我们假定给定的两个位置都是空地,初始时,gloria所面向的方向未定,

2021-03-16 15:52:53 114 1

原创 HDU 1069 Monkey and Banana

题目Problem DescriptionA group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be

2021-03-14 20:27:09 136

原创 HDU Number Sequence

题目Problem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).InputThe input consists of multiple test cases. Each test case conta

2021-03-14 10:10:50 101

原创 HDU N!Again

题目Problem DescriptionWhereIsHeroFrom: Zty, what are you doing ?Zty: I want to calculate N!..WhereIsHeroFrom: So easy! How big N is ?Zty: 1 <=N <=10000

2021-03-13 19:05:28 90

原创 HDU 1249 三角形

题目Problem Description用N个三角形最多可以把平面分成几个区域?Input输入数据的第一行是一个正整数T(1<=T<=10000),表示测试数据的数量.然后是T组测试数据,每组测试数据只包含一个正整数N(1<=N<=10000).Output对于每组测试数据,请输出题目中要求的结果.Sample Input212Sample Output28一、分析平面本身是1部分.一个三角形将平面分成三角形内、外2部分,即增加了1部分, 两个三角形不

2021-03-13 12:13:21 1467 4

原创 草稿(修改中。。)

Super Jumping! Jumping! Jumping!#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int n;int a[1010],dp[1010];int max(int a,int b){ return a-b>0?a:b;}int

2021-03-12 19:38:48 195

原创 关于动态规划问题

https://zhuanlan.zhihu.com/p/150516970

2021-03-10 21:16:00 70

原创 HDU 1003 Max Sum

题目Problem DescriptionGiven a sequence a[1],a[2],a[3]…a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an inte

2021-03-10 20:03:53 69

原创 HDU 1239 Calling Extraterrestrial Intelligence Again

题目http://acm.hdu.edu.cn/showproblem.php?pid=1239Problem DescriptionA message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November 16, 1974. The message consisted o

2021-03-08 21:54:23 467

原创 各种排序方法汇总

还是以前老师上课总结的//经典排序算法: 冒泡、选择、插入、希尔、快排、归并#include<stdio.h>#include<stdlib.h>void swap0(int *a, int *b){ int temp = *a; *a = *b; *b = temp;}//交换数组a[]中的第i和第j个元素void swap(int *a, int i, int j){ int temp = a[i]; a[i] = a[j];

2021-03-08 20:24:00 202

原创 素数筛选函数

原理:任何数的整数倍必定不是素数,大于二的偶数必定不是素数。假设有一个筛子存放1~N,例如:2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ....N先将2的倍数筛去:2 3 5 7 9 11 13 15 17 19 21....N再将3的倍数筛去:2 3 5 7 11 13 17 19....N再来将5的倍数筛去,再来将7的质数筛去,再来将11的倍数筛去........,如此进行到最后留下的数就都是质数,这就是

2021-03-08 20:06:26 263

转载 C++优先队列简介

C++优先队列简介一、优先队列与队列具有类似的特性,即只能从队尾插入元素,从队首删除元素。此外,优先队列中的最大元素总是位于队首,所以在进行出队时,总是将当前队列中的最大元素出队二、优先队列的使用1、首先要添加头文件#include2、优先队列的声明priority_queue<type,container,function>其中第一个参数不可以省略,后两个参数可以省略。type:数据类型container:实现优先队列的底层容器,要求必须是以数组形式实现的容器

2021-03-07 15:40:01 381

原创 HDU 1181 变形课

题目Problem Description呃…变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体.Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,如果他自己不能完成的话,他就只好向Hermione请教,并且被迫听一大堆好好学习的

2021-03-07 15:30:49 101 1

原创 HDU 1180 诡异的楼梯

题目hduoj1180Problem DescriptionHogwarts正式开学以后,Harry发现在Hogwarts里,某些楼梯并不是静止不动的,相反,他们每隔一分钟就变动一次方向.比如下面的例子里,一开始楼梯在竖直方向,一分钟以后它移动到了水平方向,再过一分钟它又回到了竖直方向.Harry发现对他来说很难找到能使得他最快到达目的地的路线,这时Ron(Harry最好的朋友)告诉Harry正好有一个魔法道具可以帮助他寻找这样的路线,而那个魔法道具上的咒语,正是由你纂写的.Input测试数据有

2021-03-06 11:27:28 110

转载 【转载】深搜和广搜的区别

遍历分为:1.深度(Depth)优先搜索DFS: 一个递归过程,有回退过程。尽可能“深”地搜索图。在深度优先搜索中,对于最新发现的顶点,如果它还有以此为起点而未探测到的边,就沿此边继续搜索下去。当结点V的所有边都已被探寻过,搜索将回溯到发现结点V有那条边的始结点,则选择其中一个作为源结点并重复以上过程,整个进程反复进行直到所有结点都被发现为止。2.广度(Breath)优先搜索BFS: 一个分层的搜索过程,没有回退过程,是非递归的。只是每次都尽可能地扩展当前节点的邻居节点,之后再向其子结点进行扩展。应用

2021-03-02 16:29:49 142

原创 【C++】sort函数使用方法

一.sort函数1.sort函数包含在头文件为#include的c++标准库中,调用标准库里的排序方法可以实现对数据的排序,但是sort函数是如何实现的,我们不用考虑!2.sort函数的模板有三个参数:void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);(1)第一个参数first:是要排序的数组的起始地址。(2)第二个参数last:是结束的地址(最后一个数据的后一个数据的地址)(3)第三

2021-03-02 15:31:58 2393

转载 【转载】C++ algorithm头文件函数的基本用法

algorithm/*algorithm头文件下的常用函数*//*使用algorithm头文件,需要在头文件下加一行using namespace std;” */ //常用函数max(), min(), abs()//swap()//reverse()//next_permutation()//fill()// sort()//lower_bound和upper_bound() /*max(), min(), abs()的使用*/#include<st...

2021-03-02 15:19:36 195

原创 HDU 1072 Nightmare

题目hduoj1072NightmareProblem DescriptionIgnatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb explodes. The initial exploding tim

2021-02-26 21:52:22 177

原创 HDU 1026 Ignatius and the Princess I

题目hduoj1026Problem DescriptionThe Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166’s castle. The castle is a large labyrinth. To make the problem simply, we assume the l

2021-02-26 12:25:28 239

转载 【转载】c++常用排序规则,以及优先队列记录

#include<algorithm>#include<iostream>#include<vector>#include<queue>using namespace std;bool cmp1(int a,int b){ return a > b;}struct number1{ int a; number1(){} number1(int a):a(a){} bool operator

2021-02-25 17:02:19 152

原创 HDU 1016 Prime Ring Problem

题目Prime Ring Problemhduoj1016Problem DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, …, n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.Note: the number of first c

2021-02-25 12:29:49 94

原创 HDU 1015 Safecracker

题目hduoj1015SafecrackerProblem Description=== Op tech briefing, 2002/11/02 06:42 CST ===“The item is locked in a Klein safe behind a painting in the second-floor library. Klein safes are extremely rare; most of them, along with Klein and his factory, w

2021-02-24 22:38:14 208

原创 HDU 1010

题目:Tempter of the BoneProblem DescriptionThe doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap,

2021-02-23 22:19:26 108 1

原创 关于Java中TreeSet的元素有序

一、Comparable的使用(重写CompareTo(To)方法)Student类package Collection.Set;import java.util.Objects;public class Student implements Comparable<Student>{ private int age; private String name; public Student() { } public Student(int

2021-02-22 19:02:21 263 2

原创 leetcode--167. 两数之和 II - 输入有序数组

题目链接https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/一、题目给定一个已按照 升序排列 的整数数组 numbers ,请你从数组中找出两个数满足相加之和等于目标数 target 。函数应该以长度为 2 的整数数组的形式返回这两个数的下标值。numbers 的下标 从 1 开始计数 ,所以答案数组应当满足 1 <= answer[0] < answer[1] <= numbers.length 。

2021-02-17 21:25:54 93

原创 leetcode--160. 相交链表

题目链接https://leetcode-cn.com/problems/intersection-of-two-linked-lists/一、题目编写一个程序,找到两个单链表相交的起始节点。如下面的两个链表:示例 1:输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3输出:Reference of the node with value = 8输入解释:相交节点的值为

2021-02-10 15:32:14 115

原创 leetcode--141. 环形链表

题目链接https://leetcode-cn.com/problems/linked-list-cycle/submissions/一、题目给定一个链表,判断链表中是否有环。如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是 -1,则在该链表中没有环。注意:pos 不作为参数进行传递,仅仅是为了标识链表的实际情况。如果链表中存在环,则返回 true

2021-02-06 18:45:46 148

原创 leetcode--136. 只出现一次的数字

题目链接https://leetcode-cn.com/problems/single-number/一、题目给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。说明:你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?示例 1:输入: [2,2,1]输出: 1示例 2:输入: [4,1,2,1,2]输出: 4二、分析与代码这个题如果再开一个数组来做是很快的,但题目要求不使用多余的空间1.暴力(耗时过长)一路写下来的

2021-02-06 16:30:01 76

原创 leetcode--122. 买卖股票的最佳时机 II

题目链接https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/一、题目给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。示例 1:输入: [7,1,5,3,6,4]输出: 7解释: 在第 2 天(股票价格 = 1)的时候买入,在第 3 天(

2021-02-06 15:59:16 131

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除