
matrix
Liusyu6688
这个作者很懒,什么都没留下…
展开
-
10-3最长有效括号
(解答明天写,今天实在是太多的事情了)int longestValidParentheses(string s){ stack<int>temp; int res=0; int left=0; int i=0; for(i=0;i!=s.size();++i) { if(s[i]=='(') t...原创 2018-12-18 23:25:33 · 309 阅读 · 2 评论 -
6.3 Minefield
原题我们先从简单的情况来考虑:当有两个人的时候,T=max(x1,x2)T=max(x_1,x_2)T=max(x1,x2)当有三个人的时候,T=x1+x2+x3T=x_1+x_2+x_3T=x1+x2+x3当有四个人的时候x1,x2,x3,x4x_1,x_2,x_3,x_4x1,x2,x3,x4(已经按照从小到大顺序排好了),我们有两种选择:第一种是让x1,x2x_1...原创 2018-12-15 12:23:33 · 277 阅读 · 1 评论 -
6-2. Fractal
原题题目大意:就是输入某个数字,输出图形。思路:递归无疑了,因为复杂的图形中都能够找到简单图形的影子,所以一定是递归,而且你看看题目说n不超过7,这说明了什么,因为复杂度太高了啊,这跟递归的定义不是又吻合了么,所以,递归写起来吧,但是,我们怎么递归呢,直接打印么???肯定是不行的,因为一旦换行了右边的图形就打不出来了,所以我们怎么解决呢?先存起来啊,最后再打印。#include<ios...原创 2018-12-15 11:37:57 · 226 阅读 · 0 评论 -
6-1. Code For 1
6.1题目大意:给一个数n,和一个区间[l,r] (r-l<1e5,n<2^50),每次需要把序列中大于1的数字分成(n/2,n%2,n/2)(其中n/2是向下取整),直到所有数变成0或1,问[l,r]区间内有多少个1。注意一点:l和r都是大于1的,所以我们的下标是[l-1,r-1]。之前我做这道题目的时候用的方法是直接模拟,发现能过matrix但是过不了cf,于是我在网上搜索...原创 2018-12-15 10:59:13 · 406 阅读 · 0 评论 -
matrix 期末复习
临近期末,所以打算把这学期的matrix的所有的题目都再做一遍,但是又担心毅力不够,所以想通过写博客的方式来鞭策自己做完,当然做完了这个还有Leetcode的题目需要整理,所以时间还是十分的紧的,无论如何都要加油,努力总是没有错的。...原创 2018-12-15 10:06:51 · 512 阅读 · 1 评论 -
16-4 Chain Reaction
这一道题目我没有找到原题,所以大家如果找到了原题也麻烦发一下给我,方便我再测评一次。这一题的意思就是链式反应,等我有机会再来详细的解释,现在先把代码放上来!#include<bits/stdc++.h>#include<iostream>#include<vector>#include<cmath>#include<algorith...原创 2018-12-20 14:44:25 · 318 阅读 · 0 评论 -
16-3 Russian Doll Envelopes
原题题目大意:将小的信封放到大的信封中,如果宽度相同的话,矮的不能套到大的里面。解题思路:是不是觉得有点像最长上升子序列的长度的那道题目?这题是可以用dp来写的,我一开始就使用dp来写,但是发现我的复杂度太高了,因为我这一次的dp是用两层for循环来写的,所以我找到了这道题目的简化版–二分法!于是还是先按照宽度从小到大的顺序排列,但是当高度相同的时候我们就要将长度高的放在前面,这里就是为了...原创 2018-12-20 14:37:35 · 356 阅读 · 0 评论 -
16-2 Search in Rotated Sorted Array
原题题目大意:将一个单调递增的数组先旋转一下,然后再旋转后的数组中找到target。我们可以先来看一个例子,以[1,2,3,4,5,6,7]为例:那么这个数组的所有旋转后的数组为:2,3,4,5,6,7,1----------(1)3,4,5,6,7,1,2----------(2)4,5,6,7,1,2,3----------(3)5,6,7,1,2,3,4----------(4...原创 2018-12-20 00:10:55 · 204 阅读 · 0 评论 -
11-1 哈夫曼树
题目大意:给定n个叶节点的权值,请建立哈夫曼树,并求出每个叶节点的路径长与权值乘积之和。 路径长指叶节点到根节点的长度。还是一样的,我们需要来分析样例,不分析样例一上来就开始写题是不成熟的,所以,开始分析吧:这里我将不是构造的数字用了圈来表示,你发现了没有37=3+5+10+19!!这说明了什么,我们只需要循环然后每次排序,前两个数字相加存到第一个数字里面,取第一个数字!这样就可以了。...原创 2018-12-21 11:02:55 · 812 阅读 · 0 评论 -
8-1 Substrings Sort
原题题目大意:把子串放到母串的前面的排序。思路:只需要按照长度先排序,如果长度相同的话就按照字典序排列就好。比较简单,很容易解答出来解答:#include<iostream>#include<vector>#include<cmath>#include<algorithm>using namespace std;string te...原创 2018-12-16 10:11:06 · 343 阅读 · 0 评论 -
8-2 War of the Corporations
原题题目大意:就是将第一个串的某些字符和谐掉使第二个串在第一个串中找不到,求和谐字符的最小的数字。思路:我们先来看一个例子:如果长串是efcacacaef短串是caca,我们发现caca在长串中出现了两次,并且是重叠的,于是我们可以采用贪心的思路,每次和谐最后的那一个字符,这样就能满足最小的条件了。下面我们就可以来打码了。#include&lt;iostream&gt;#include&...原创 2018-12-16 10:47:48 · 306 阅读 · 0 评论 -
10-2情感丰富的文字
原题这一题解释的真的好不清楚,其实就是如果S中某个字符跟words[i]对应的字符不相同的时候,以及S中的某个字符的扩张幅度<3且跟words[I]中某个字符的数目不相同,以及S中某个字符的长度小于了words[I]中某个字符的数目,这三种情况都是不能够扩张的,真的是很绕!int expressiveWords(string S, vector<string>& w...原创 2018-12-18 22:04:53 · 309 阅读 · 0 评论 -
12-2 Kefa and Park
#include<iostream>#include<vector>#include<set>#include<map>#include<unordered_map>using namespace std;unordered_map<char,int>temp;int cat[100005];unordered...原创 2018-12-23 13:23:32 · 295 阅读 · 0 评论 -
12-1 二叉树的凹入表示法
#include<iostream>#include<vector>#include<set>#include<map>#include<unordered_map>using namespace std;unordered_map<char,int>temp;int height(string s1,strin...原创 2018-12-23 13:03:39 · 3775 阅读 · 1 评论 -
9-4 打开转盘锁
题目大意:你有一个带有四个圆形拨轮的转盘锁。每个拨轮都有10个数字: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’ 。每个拨轮可以自由旋转:例如把 ‘9’ 变为 ‘0’,‘0’ 变为 ‘9’ 。每次旋转都只能旋转一个拨轮的一位数字。锁的初始数字为 ‘0000’ ,一个代表四个拨轮的数字的字符串。输出最小的旋转次数。思路:典型的BFS,因为有最小...原创 2018-12-17 14:32:57 · 651 阅读 · 0 评论 -
9-3 Team Queue
9-3 Team Queue这道题目的意思就是:每个队里面有一些数字,然后按照数字的进入的顺序分别给每个队里面的数字排序,然后需要注意的是需要按照这些数字所在的队的顺序输出。用一个map记录每个数字的组号;用一个queue来记录组的进入的先后;用一个queue数组记录每个队的数字的进入的顺序;//// main.cpp// 9-2//// Created by 刘斯宇 on...原创 2018-12-17 13:04:37 · 192 阅读 · 0 评论 -
9-2 任务调度器
两个相同种类的任务之间必须有长度为 n 的冷却时间,因此至少有连续 n 个单位时间内 CPU 在执行不同的任务,或者在待命状态。给出需要的最短的时间。其实这一题就是贪心的思想,给出了间隔的时间,那么我们只需要在这段间隔的时间加入任务就好了,如果没有任务了,直接空出来当缓冲就好了。#include <iostream>#include<unordered_map>#i...原创 2018-12-17 11:26:20 · 197 阅读 · 0 评论 -
11-2 Tree Construction
题目大意:构造BST,输出双亲节点。思路:新加进来的点,其父亲要么是比他大的值中最小的,或者是比他小的值中的最大的。那么后加入的那个节点就是该节点的父亲节点。理由:平衡二叉树的中序遍历是有序的,那么#include<iostream>#include<vector>#include<set>#include<map>using na...原创 2018-12-21 19:32:51 · 407 阅读 · 1 评论 -
8-3 迷宫
典型的dfs问题,直接套模版就好,弄一个visited数字完全解决问题。#include<iostream>#include<vector>#include<string>#include<map>#include<set>using namespace std;int num;bool helper(int x,in...原创 2018-12-16 11:17:15 · 235 阅读 · 0 评论 -
stack
#include <iostream>#include <cstdio>using namespace std;struct Node { int number; Node *next;};class myStack {private: Node *mtop; int _size;public: myStack(); myStack(cons...原创 2018-06-10 10:53:54 · 225 阅读 · 0 评论 -
Overloading 重载输入输出
You are to overload the operators “>>”, “<<”, “*” for the Complex class, which respectively mean reading an object from a stream, sending an object to a stream, and the “multiply”...原创 2018-06-08 09:53:35 · 244 阅读 · 0 评论 -
[Inheritance]InstanceOf (eden)
Description In Java, all class are inherited from Object (对象类), but c++ don’t have such feature Also In Java, function instanceOf can return class namePlease implement these class...原创 2018-06-07 14:28:04 · 349 阅读 · 0 评论 -
十进制和十六进制的转换
Description Write two overloaded functions that parse a decimal number into a hex number as a string. The function headers are as follows: char * convertDecimalToHex(int value) vo...原创 2018-06-07 09:45:57 · 537 阅读 · 0 评论 -
T1
Description 写一个sum函数,体会函数缺省值的使用. 对于主程序 int main ( ) {cout << sum() << endl;cout << sum(6) << endl;cout << sum(6, 10) << endl;cout &l...原创 2018-06-07 09:42:49 · 257 阅读 · 0 评论 -
Sequence
DescriptionDesign a class named Sequence to support several operators.The class contains:0、A no-arg constructor that creates a default Sequence.1、A function named size(),return the number of the ...原创 2018-06-11 23:40:42 · 378 阅读 · 0 评论 -
construct
There are four classes A, B, C and D. They all have the same form as follows: class X{public: X() { cout &lt;&lt; "In X()" &lt;&lt; endl; } ~X() { cout &lt;&lt; "In ~X()原创 2018-06-08 10:55:51 · 270 阅读 · 0 评论 -
多继承
写作和赛车是韩少的两大最爱,但在生活的不同时期还是要有所取舍。韩少的原则是:周末:写作优先; 周内:赛车优先;这些可以提现在Weekend和Workday的对象构造中,类继承关系如下:Racing Writing \ / Weekend/Workday其中Racing和Writing如下:...原创 2018-06-08 14:19:04 · 455 阅读 · 0 评论 -
重载日历(一)
Implement the operator ++(prefix), --(prefix), ++(postfix), --(postfix), in the class Dateclass Date{public: Date(int y=0, int m=1, int d=1); static bool leapyear(int year); int getYear() co...原创 2018-06-09 10:23:18 · 293 阅读 · 0 评论 -
Set Operations
You need finish function.Require knowledge:Know set operations:includeintersection(交集)union(并集)the complement of B with respect to A(B对A的补)symmetric difference(对称差)copy constructoroverl...原创 2018-06-10 10:28:16 · 315 阅读 · 0 评论 -
Matrix Calculation
## Description:Please complete the class Matrix.Suppose you have understood the overload operator of C++.Matrix(string, int, int, int**)Matrix(const Matrix &)~Matrix()bool operator ==(...原创 2018-06-10 10:17:55 · 438 阅读 · 0 评论 -
String & Cstring
TaskImplement the two functions which proceed to exchange between string and cstring.(1) std::string change1(const char* cstr);Convert a string of the cstring type to one belonging to the string ...原创 2018-06-10 10:09:38 · 403 阅读 · 0 评论 -
Complex
The complex.h is the class header describing a complex number class.Please write the corresponding implementation file complex.cpp. main.cpp will test it. If we give 2.1+0.2i / 0.2-0.3i, the output ...原创 2018-06-10 10:06:37 · 347 阅读 · 0 评论 -
fraction
this assignment you are required to complete a class for fractions.It stores the numerator and the denominator, with the lowest terms.It is able to communicate with iostreams by the operator <...原创 2018-06-09 11:09:44 · 961 阅读 · 0 评论 -
My memmove
DescriptionImplement a function char* my_memmove(char *dst, const char *src, unsigned int n).DetailSee main.cpp.Try NOT to use another memory/array to do this, just do it in the arraySampl...原创 2018-06-11 23:23:47 · 411 阅读 · 0 评论