![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 88
最佳损友1020
xdu 计科毕业
xjtu 计科在读
种一棵树的最好时机是十年前,其次是现在
展开
-
实习机试代码记录
题目:美团2024届暑期实习第一轮后端笔试详解通过了前三道,花了一堆时间在第四道上,一分没得,第五题都没时间看。题目的设置有点无语,一到四题安排在一起,第五题安排在一起,当时不知道提交后可以继续修改,进了一到四题的项就不敢提交,以为第五题单独放一起肯定很难,最后没时间了看了一下第五题,比较简单。搞不明白为啥要把第五题单独列一个项,要不然怎样都能写出四道来小美有一个由数字字符组成的字符串。现在她想对这个字符串进行一些修改。 具体地,她可以将文个字符串中任意位置字符修改为任意的数字字符。她想知道,至少进行多少原创 2023-08-15 22:59:58 · 272 阅读 · 0 评论 -
企业机试代码记录
动态规划问题,假设已解决n-1与n-2规模时最短时间,可能的方法是:n-1 (最轻的人单独过河把最重的人接过来 fn-1+v0+vn) n-2(最轻的人过去 最重的和第二重的人过去 第二轻的人过来 第一第二轻的人过去 fn-2+v1+vn+v2+v2)数组各数减去第一个数,归并相同特征的数组,使用map记录各数组的出现次数,对每一个map kv,查看map中是否存在相反数组,需对全0数组(相反数组为自身)进行特殊处理,为了避免重复计算,将相反数组出现次数置为-1。超时,过不了,只能使用二分查找解法了。原创 2023-03-16 18:15:27 · 632 阅读 · 0 评论 -
leetcode记录2
快排:以前都只看过双指针格式的代码,看了看leetcode单指针的代码,比较易懂。归并:不怎么喜欢用夹带++i或i++的表达式,总觉得不好看,非递归的实现忘了。给定整数数组 nums 和整数 k,请返回数组中第 k 个最大的元素。代码化简,while循环改成for循环。利用快排的划分函数即可。原创 2023-03-02 23:29:44 · 198 阅读 · 0 评论 -
算法分析上机作业
算法实现代码算法测试代码实验二算法实现与测试代码实验三算法实现代码算法测试代码实验四算法实现与测试代码实验报告实验一问题描述给定由n个数组成的集合S,从中找出最接近S的中位数的n/4个元素。请设计一个最坏情况下时间复杂度为O(n)的算法。解决这个问题之前需要先找到线性时间内解决选择问题(在n个数中选择第k个顺序统计量)的算法,而算法导论中已经给出了期望时间为线性的选择算法和最坏情况下为线性的选择算法。在假设已经获得线性选择算法后只需计算集合的中位数,而后计算集合中各元素与中位数原创 2022-07-16 11:14:43 · 1219 阅读 · 4 评论 -
leetcode记录
代码复制粘贴太多了,编辑起来很卡,再开一个博客:leetcode记录2给你一个链表数组,每个链表都已经按升序排列。请你将所有链表合并到一个升序链表中,返回合并后的链表。思路:简单的合并链表,刚开始的思路是每次循环找到最小的节点,后面看题解发现可以使用优先队列这种方式辅助找到最小值使用优先队列找到最小值圆圈中最后剩下的数字0,1,···,n-1这n个数字排成一个圆圈,从数字0开始,每次从这个圆圈里删除第m个数字(删除后从下一个数字开始计数)。求出这个圆圈里剩下的最后一个数字。例如,0、1、2、3、4这原创 2022-06-16 22:18:05 · 523 阅读 · 0 评论 -
王道考研机试指南重写
王道考研机试指南重写前言数据结构一章栈的应用括号匹配问题简单计算器前言几年前因为应付有些学校的机试,大致刷了一遍《王道考研机试指南》里代码王道考研机试指南代码合集。几年过去了想重新刷一遍,加强算法能力,同时也熟悉c++的新特性。以下代码更多的不是算法效率,而是尽可能使用一些新特性并保持代码规范(尝试规范)。......原创 2022-03-31 21:23:05 · 3187 阅读 · 0 评论 -
王道考研机试指南代码合集
王道考研机试指南代码合集github链接王道考研机试指南的代码合集,附有一些笔记和感悟文件夹中包括机试指南的pdf,笔记部分,和代码对应题目的列表如发现任何问题欢迎在下面留言原创 2020-06-29 12:07:10 · 2422 阅读 · 0 评论 -
二叉树遍历
题目链接#include<iostream>#include<string>using namespace std;typedef struct node { struct node* lchild; struct node* rchild; char c; node() { lchild = NULL; rchild = NULL; }}N...原创 2020-03-15 23:08:10 · 99 阅读 · 0 评论 -
简单计算器
简单计算器各个输入函数(字符串输入)1、scanf函数(包含头文件#include <stdio.h>)scanf函数一般格式为scanf(“%s”,st),但scanf默认回车和空格是输入不同组之间的间隔和结束符号,所以输入带空格,tab或者回车的字符串是不可以的。scanf(“%[^c]”,str);其中“c”是一个具体的字符常量(包括控制字符)。当输入字符串时,字符“...原创 2020-02-04 20:47:06 · 224 阅读 · 0 评论 -
括号匹配问题
括号匹配问题堆栈存入数组下标间接实现数组元素的操作不使用堆栈#include<iostream>#include<string>using namespace std;bool find(string& s, int index) { while (index > 0) { index--; if (s[index] == '(') ...原创 2020-02-04 20:44:15 · 417 阅读 · 0 评论 -
贪心算法
贪心算法类型总是向下兼容的,有时候double替换int数据更加方便使用vector a(100);sort(a.begin(), a.begin() + n);的方式节省空间贪心算法中贪心策略的选择开始时间 结束时间 持续时间FatMouse’ Trade#include<iostream>#include<vector>#include<al...原创 2020-02-04 20:42:02 · 130 阅读 · 0 评论 -
查找
查找找x#include<iostream>#include<vector>using namespace std;void func() { int n; while (cin >> n && n != 0) { vector<int> a(n); for (int i = 0;i < n;i++) {...原创 2020-02-04 20:39:37 · 184 阅读 · 0 评论 -
叠筐
叠筐0 1变换(flag + 1) % 2格式输出bool firstline = true;if (firstline == true) { firstline = false;}else { cout << endl;}先排版后输出#include<iostream>using namespace std;void border(in...原创 2020-02-04 20:34:14 · 167 阅读 · 0 评论 -
输出梯形
输出梯形#include<iostream>using namespace std;void func() { int h; cin >> h; int max = 3 * h - 2; int now = 2 * h - 2; for (int i = 0;i < h;i++) { for (int j = 0;j < max;j++) ...原创 2020-02-04 20:16:45 · 154 阅读 · 0 评论 -
sort
sort内置sort方法在oj中时间超时cin cout 改成 scanf printf表示错误空格与换行符的输出是否错误#include<iostream>#include<vector>#include<algorithm>using namespace std;bool cmp(int a, int b) { return a &...原创 2020-02-04 20:14:57 · 161 阅读 · 0 评论 -
统计同成绩学生人数
统计同成绩学生人数cin>>n;while(n!=0){ cin>>n;} 改成while(cin>>n){ if(n==0) break;}while (scanf ("%d",&n) != EOF && n != 0)==while (cin>>n && n != 0)==代码...原创 2020-02-04 20:09:23 · 209 阅读 · 0 评论 -
周数计算
周数计算#include<stdio.h>#include<string.h>int dates[3002][13][32];char NameofWeek[7][20] ={ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};int day...原创 2020-02-04 20:06:00 · 851 阅读 · 0 评论 -
日期差值
日期差值scanf ("%4d%2d%2d",&y1,&m1,&d1) YYYYMMDD格式数据输入预处理二维数组的初始化可以按行分段赋值,也可按行连续赋值。于数组 a[5][3],按行分段赋值应该写作:int a[5][3]={ {80,75,92}, {61,65,71}, {59,63,70}, {85,87,90}, {76,77,85} };按行连续赋...原创 2020-02-04 20:03:05 · 151 阅读 · 0 评论 -
成绩排序
成绩排序#include<iostream>#include<algorithm>#include<vector>using namespace std;typedef struct { string user; int grade;}people;bool cmp(people p1,people p2,int method) { if (...原创 2020-02-04 19:56:33 · 154 阅读 · 0 评论 -
CCF201403-4
CCF201403-4#include<iostream>#include<queue>#include<vector>using namespace std;typedef struct route{ long long x,y; int step; int count;}route;bool below(long long x1,lo...原创 2020-02-02 10:40:24 · 119 阅读 · 0 评论 -
CCF201412-1
CCF201412-1#include<iostream>using namespace std;int* init(int n) { int* res = new int[n]; for (int i = 0;i < n;i++) { cin >> res[i]; } return res;}void fun(int* data, int n...原创 2020-02-02 10:30:25 · 211 阅读 · 0 评论 -
CCF201503-1
CCF201503-1#include<iostream>using namespace std;int** init(int line,int row) { int** data; data = new int* [line]; for (int i = 0;i < line;i++) { data[i] = new int[row]; for (int j...原创 2020-02-02 10:28:47 · 115 阅读 · 0 评论 -
CCF201703-4
CCF201703-4得分15分 待完善#include<iostream>#include<vector>#include<iterator>#include<algorithm>using namespace std;int max(int a, int b) { if (a > b) return a; return...原创 2020-02-02 10:27:04 · 177 阅读 · 0 评论 -
CCF201703-3
CCF201703-3#include<iostream>#include<string>#include<algorithm>using namespace std;void out(string s) { cout << s << endl;}void outString(vector<string> re...原创 2020-02-02 10:19:16 · 173 阅读 · 0 评论 -
CCF201703-2
CCF201703-2#include<iostream>#include<vector>#include<algorithm>#include<iterator>using namespace std;void out(int& i) { cout << i << " ";}void out_vec...原创 2020-01-30 23:30:39 · 134 阅读 · 0 评论 -
CCF201703-1
CCF201703-1#include<iostream>#include<algorithm> using namespace std;bool cmp(int i, int j) { return i < j;}int func() { int n, k; cin >> n >> k; int a[n]; for (i...原创 2020-01-30 23:28:04 · 187 阅读 · 0 评论 -
CCF201709-2
CCF201709-2#include<iostream>#include <algorithm>using namespace std;typedef struct { int time; int num_key; bool is_up;}teacher;int* init_key(int n) { int* keys = new int[n]; f...原创 2020-01-30 23:23:30 · 178 阅读 · 0 评论 -
CCF201712-4
CCF201712-480分 待完善#include<iostream>#include<vector>#define INF 10000000 using namespace std;typedef struct{ int weight; //记录权值 int r; //记录路径当前小路长度 }edge;typedef struct{ int ...原创 2020-01-30 23:20:52 · 164 阅读 · 0 评论 -
CCF201809-3
CCF201809-3我的程序#include<iostream>#include<string>#include<vector>#include<algorithm>#include<cstring>using namespace std;typedef struct TreeNode { string label;...原创 2020-01-30 23:17:10 · 148 阅读 · 0 评论 -
CCF201903-1
CCF201903-1#include<stdio.h>int main(){ int n; int min,max,mid; scanf("%d",&n); int num[n]; for(int i=0;i<n;i++){ scanf("%d",&num[i]); } max=num[0]>=num[n-1]?num[0]:nu...原创 2020-01-30 23:08:08 · 99 阅读 · 0 评论 -
CCF201909-1
CCF201909-1#include<iostream>using namespace std;void func(){ int n,m; cin>>n>>m; int T=0,k,P=-1; int sum,num,decrease; for(int i=0;i<n;i++){ cin>>sum; decrease...原创 2020-01-30 23:04:41 · 208 阅读 · 0 评论 -
CCF201912-3
CCF201912-370分 样例全部通过 待更正。。。#include<iostream>#include<vector>#include<string>#include<stdio.h>#include<algorithm>#include<cstring>using namespace std;ty...原创 2020-01-30 20:51:42 · 271 阅读 · 0 评论 -
CCF201912-2
CCF201912-2#include<vector>#include<algorithm>#include<iostream> using namespace std; typedef struct{ long long x,y; int index; }plot; bool cmp_x(plot p1,plot p2){ ...原创 2020-01-30 20:48:57 · 532 阅读 · 0 评论 -
CCF201912-1
CCF201912-1#include<iostream>#include<vector>using namespace std;bool have(int x){ if(x%7==0) return true; while(x!=0){ if(x%10==7) return true; x = x / 10; } return fals...原创 2020-01-30 20:46:50 · 164 阅读 · 0 评论 -
王道计算机考研机试指南部分代码
成绩排序#include<iostream>#include<algorithm>#include<vector>using namespace std;typedef struct { string user; int grade;}people;bool cmp(people p1,people p2,int method) { if (...原创 2020-01-24 17:04:55 · 637 阅读 · 0 评论 -
CCF201403-2
CCF201403-2#include<iostream>using namespace std;typedef struct{ int x1,x2; int y1,y2; int Num;}Window;Window* init(int n){ Window* ans = new Window[n+1];//ans[0]未被使用 for(int i=1;i&...原创 2019-11-30 09:56:45 · 117 阅读 · 0 评论 -
CCF201403-3 命令行选项
CCF201403-3 命令行选项评测100分代码#include<iostream>#include<stdio.h>#include<string>#include<cstring>#include<vector>#include<algorithm>using namespace std;typede...原创 2019-11-30 09:54:45 · 171 阅读 · 0 评论 -
CCF201403-1
CCF201403-1#include<iostream>#include<vector>using namespace std;void func(){ int n; int ans = 0; cin>>n; int tmp; vector<int> flag(1001,0); for(int i=0;i<n;i++...原创 2019-11-30 09:51:09 · 165 阅读 · 0 评论 -
CCF部分试题
CCF部分试题CCF201903-2CCF 201909-2CCF201604-2原创 2019-11-25 21:00:43 · 385 阅读 · 2 评论 -
CCF201903-2
CCF201903-2题目评测100分代码#include<iostream>#include<string>using namespace std;void print_ans(int* ans){ for(int i=0;i<4;i++){ cout<<ans[i]<<" "; } cout<<endl;...原创 2019-11-25 20:56:58 · 278 阅读 · 0 评论