随笔分类 -  算法

摘要:题目 class Solution { public: int countBinarySubstrings(string s) { int result = 0; int prev = 0; int current = 1; int n=s.size(); for(int i = 1 ; i < n 阅读全文
posted @ 2020-08-10 19:24 飞翔的菜鸟123 阅读(113) 评论(0) 推荐(0)
摘要:Description 题目 Farmer John has built a new long barn, with N (2 ⇐ N ⇐ 100,000) stalls. The stalls are located along a straight line at positions x1,.. 阅读全文
posted @ 2020-07-29 22:43 飞翔的菜鸟123 阅读(112) 评论(0) 推荐(0)
摘要:二分查找 在闭区间查找[begin,end],注意对找不到的处理 int binary_find(vector<int>& nums, int target){ int l=0,r=nums.size()-1;//Notice while(l<r){ int mid=l+(r-l)>>1; if(n 阅读全文
posted @ 2020-07-29 22:43 飞翔的菜鸟123 阅读(142) 评论(0) 推荐(0)
摘要:Description Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) Push element x onto stack. pop() 阅读全文
posted @ 2020-05-12 23:38 飞翔的菜鸟123 阅读(146) 评论(0) 推荐(0)
摘要:Description "Problem" In a country popular for train travel, you have planned some train travelling one year in advance. The days of the year that you 阅读全文
posted @ 2020-05-06 22:44 飞翔的菜鸟123 阅读(132) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only 阅读全文
posted @ 2020-05-06 18:07 飞翔的菜鸟123 阅读(131) 评论(0) 推荐(0)
摘要:1123 Is It a Complete AVL Tree (30分) "题目链接" 存一个模板,以后背这个 阅读全文
posted @ 2020-05-06 18:07 飞翔的菜鸟123 阅读(168) 评论(0) 推荐(0)
摘要:Description Building and maintaining roads among communities in the far North is an expensive business. With this in mind, the roads are build such th 阅读全文
posted @ 2020-02-01 20:32 飞翔的菜鸟123 阅读(187) 评论(1) 推荐(0)
摘要:Description Polygon is a game for one player that starts on a polygon with N vertices, like the one in Figure 1, where N=4. Each vertex is labelled wi 阅读全文
posted @ 2020-01-08 20:26 飞翔的菜鸟123 阅读(159) 评论(0) 推荐(0)
摘要:Description 在一个圆形操场的四周摆放 N 堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分。 试设计出一个算法,计算出将 N 堆石子合并成 1堆的最小得分和最大得分。 数据的第 1 行是正整数 N,表示有N堆石子。 第 阅读全文
posted @ 2020-01-07 19:56 飞翔的菜鸟123 阅读(112) 评论(0) 推荐(0)
摘要:Despription Triangulation of surfaces has applications in the Finite Element Method of solid mechanics. The objective is to estimate the stress and st 阅读全文
posted @ 2020-01-04 20:37 飞翔的菜鸟123 阅读(199) 评论(0) 推荐(0)
摘要:Description You are given the task to design a lighting system for a huge conference hall. After doing a lot of calculation & sketching, you have figu 阅读全文
posted @ 2019-12-30 19:49 飞翔的菜鸟123 阅读(141) 评论(0) 推荐(0)
摘要:String Searching Algorithms Horspool:看pattern每个字符和最后一位字符的距离 Boyer-Moyer:看pattern小字符串和最后一个字符的距离 KMP:看状态转移 单模匹配--KMP 定义两个字符串text和pattern,pattern不断位移的过程中 阅读全文
posted @ 2019-12-28 17:09 飞翔的菜鸟123 阅读(176) 评论(0) 推荐(0)
摘要:Descriprion If you smiled when you see the title, this problem is for you ^_^)For those who don’t know KTV, see: http://en.wikipedia.org/wiki/Karaoke_ 阅读全文
posted @ 2019-12-23 14:00 飞翔的菜鸟123 阅读(215) 评论(0) 推荐(0)
摘要:Problem Description Problems that require minimum paths through some domain appear in many different areas of computer science. For example, one of th 阅读全文
posted @ 2019-12-21 19:49 飞翔的菜鸟123 阅读(343) 评论(0) 推荐(0)
摘要:题目 John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John mu 阅读全文
posted @ 2019-12-18 14:49 飞翔的菜鸟123 阅读(153) 评论(0) 推荐(0)
摘要:题目 Secret agent Maria was sent to Algorithms City to carry out an especially dangerous mission. After several thrilling events we find her in the firs 阅读全文
posted @ 2019-12-17 20:11 飞翔的菜鸟123 阅读(325) 评论(0) 推荐(0)
摘要:算法 类型 Structure function 备注 不变序列算法O(n) 顺序容器/关联容器均适用 iterator min_element(iterator first, iterator last[,Pred op]) iterator max_element(iterator first, 阅读全文
posted @ 2019-12-13 20:58 飞翔的菜鸟123 阅读(284) 评论(0) 推荐(0)
摘要:`1.树的搜索 ` order traverse 思路1:bfs(要建树的数据结构) 思路2:dfs(要Node结构体) cpp const int maxn = 1010; vector g[maxn];//已知结点关系 void dfs(int x, int dp) {//depth运用 pat 阅读全文
posted @ 2019-12-13 20:53 飞翔的菜鸟123 阅读(144) 评论(0) 推荐(0)
摘要:1.数连通分量(并查集) PAT1013 Battle Over Cities 法1:每次dfs前判断visit[i]==0; cpp while(K ){ int v;int num=0; scanf("%d",&v); iota(father,father+N+1,0);//初始化并查集 for 阅读全文
posted @ 2019-12-13 20:44 飞翔的菜鸟123 阅读(118) 评论(0) 推荐(0)