摘要:
https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/ 逆波兰表达式也就是后缀表达式,直接通过栈即可求出答案。 难的不是逆波兰表达式的求值,难的是将中缀表达式转化为后缀表达式。 1 class Solution { 2 p 阅读全文
2021年3月23日
2021年3月21日
摘要:
A:枚举所有可能的情况,判断能否组成两个三角形。 1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 bool three_one(int a){ 5 int cnt0=0,cnt1=0; 6 for(int i=0;i< 阅读全文
2021年3月20日
摘要:
https://www.acwing.com/problem/content/287/ 所谓树形DP,也就是关系的两边变成了树的上层和下层。 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 const int N=6 阅读全文
2021年3月15日
摘要:
A:水题,给定两个字符串,问能否只交换一次使得两字符串相等。 解法1:记录两字符串不相等的位置。 1 class Solution { 2 public: 3 bool areAlmostEqual(string s1, string s2) { 4 int n=s1.length(); 5 int 阅读全文
2021年3月14日
摘要:
A:模拟题,每次进站加上应该要的时间和延迟的时间 每次等待的时候需要题给定的两个条件都满足。 注意:最后一站不需要等待,所以需要单独考虑。 1 #include<cstring> 2 #include<algorithm> 3 #include<iostream> 4 using namespace 阅读全文
2021年3月13日
摘要:
https://www.acwing.com/problem/content/340/ 1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 int get(vector<int> v,int l,int r){ 5 int 阅读全文
2021年3月11日
摘要:
A:给了一个比较复杂的定义,但是仔细读了之后就会发现问的就是字符串s的回文长度是否大于等于k,例如abqewba的回文长度是2. 1 #include<algorithm> 2 #include<iostream> 3 using namespace std; 4 5 int main(void){ 阅读全文
2021年3月10日
摘要:
1、区间选点问题 https://www.acwing.com/problem/content/907/ 给定n个区间,选择尽量少的点使得每个区间都至少包含一个点,问最少的点的数量是多少。 1 #include<algorithm> 2 #include<iostream> 3 using name 阅读全文
2021年3月7日
摘要:
A:水题。 解法1:首先确定一个全为1的串,之后如果在出现1,就返回false 1 class Solution { 2 public: 3 bool checkOnesSegment(string s) { 4 bool flag=true; 5 int n=s.size(); 6 for(int 阅读全文
2021年3月2日
摘要:
https://www.acwing.com/problem/content/902/ 整数划分问题,给定一个正整数n,问有多少种方案使得n=x1+x2+...+xn,不考虑顺序。 解法1:利用完全背包的模型,将1~n每一个数字看成一个物品。 1 #include<iostream> 2 using 阅读全文