随笔分类 - c++
摘要:仔细一看,就是把时间排序,然后把根据时间推进把这些点都连起来,那就是并查集问题,刚写完交上去是90分,加了一个优化变成100了。 #include <bits/stdc++.h> #define testa using namespace std; int n,m; class road{ publ
阅读全文
摘要:多年后再回头看这道题觉得很简单,写起来还是很复杂,我的书写习惯不好,找bug找了很久。 特别注意在构建角色时,一个角色可能会有多个权限,取最大值,又要与无权限的-1区别对待。 #include<bits/stdc++.h> #define N 10001 #define testa using na
阅读全文
摘要:好久没写了,随便写写吧。 长度不超过12,就可以直接暴力了。 class Solution { public: vector<string> ans; vector<int> ind; string p; int dfs(int a){ if (a==ind.size()){ ans.push_ba
阅读全文
摘要:这是个自动机问题,而且是简单题,就不做注解了。 class Solution { public: int romanToInt(string s) { int status=0; int num=0; int i=0; while(i<s.length()){ cout<<i<<" "<<num<<
阅读全文
摘要:思路清晰就好,不是很难只是有点复杂。 #include<bits/stdc++.h> #define atest using namespace std; int n,l,r,t; int mapp[601][601]; int main(){ cin>>n; cin>>l; cin>>r; cin
阅读全文
摘要:class Solution { public: vector<int> largestDivisibleSubset(vector<int>& nums) { int p[1001],q[1001]; memset(q,0,sizeof(q)); sort(nums.begin(),nums.en
阅读全文
摘要:突然想明白这是动态规划 class Solution { public: int numDecodings(string s) { int res[100]; memset(res,0,sizeof(res)); if(s[0]=='0') return 0; res[0]=1; if(s.leng
阅读全文
摘要:#include<bits/stdc++.h> //#define test using namespace std; int mapp[1001][1001]; int visited[1001]; int n,m; int nownum; int ava[1001][1001]; int dfs
阅读全文
摘要:算法导论提到过,虽然这里面有个循环,但是把循环次数平分一下好像就很小。 class Solution { public: vector<int> countBits(int num) { vector<int> res; int n=0,t; int s=0; int a[10000]; memse
阅读全文
摘要:算法导论提到过这题 class Solution { public: int longestCommonSubsequence(string text1, string text2) { int a[1001][1001]; int i,j; for(i=0;i<1001;i++){ a[i][0]
阅读全文
摘要:不难 class Solution { public: int clumsy(int N) { int i; if(N==3) return 6; if(N==2||N==1) return N; int a=N*(N-1)/(N-2)+N-3; N-=4; int sign=1; long lon
阅读全文
摘要:跟导师聊了一会就想明白了 哈哈哈哈哈 开始我在想是不是做成一个函数从中找到递增的曲线,再一想就是先排序再从小到大计算每个信封能套多少个(不是能接受多少),这是个动态规划问题。 排序的谓词函数要加static class Solution { public: static bool comp(vect
阅读全文
摘要:十万个数据就不可能用笨办法去一个一个试了,先将指数递减排序并假定阈值为最大值。阈值不断缩小时根据上一次的记录去修改得到新的阈值的正确率。如果选用下一个阈值时并没有缩小则记录,不立刻操作。 突然发现CSP有下载答卷功能。 #include<bits/stdc++.h> using namespace
阅读全文
摘要:class Solution { public: int lengthOfLIS(vector<int>& nums) { int i=0,j=0,maxx=0; int k; bool flag=true; int len[10000]; for(i=0;i<nums.size();i++){ l
阅读全文
摘要:虽然说这是个简单题,但他通过率低啊。我估计别人都是传统方法一个一个试,而这题目又要求算五百万。 假定所有数都是质数,遍历所有目前认为的质数即从2开始找2的倍数4、6、8标记为合数,接下来找3的倍数。。。。到4就不必寻找因为在之前找2的倍数时,4已被标为合数,4的倍数都已经被标记过了。所以接着找5的。
阅读全文
摘要:记录上一个写入的字母,找除了这个字母以外的出现次数最多的字母插入。 class Solution { public: string reorganizeString(string S) { int alp[26]; int i; for(i=0;i<26;i++){ alp[i]=0; } for(
阅读全文
摘要:class Solution { public: int n; vector<int> a,b,l; vector<vector<int> > res; vector<vector<int> > qwe; int num[10]; int o; string multiply(string num1
阅读全文
摘要:这题很简单,记录当前节点的数, 往左搜索后恢复这个记录的数之后再去搜索右边,仅在左右节点都为空的时候把结果加在数里。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; *
阅读全文
摘要:这题说实话不难,处理起来不太好做,一点一点改改通过了 p数组里最后一个应该定为一个垃圾值让他不满足任何条件以表明这是最后一项 这个搜索到此要停止。 class Solution { public: int longestMountain(vector<int>& A) { if(A.size()==
阅读全文
摘要:我昨晚突然想到这是个背包问题,用stp数组来表示在每一个点能往下跳多远,这样每次就可以直接调用数组而不是在这个vector里查找。第二个循环就是对stp的初始化。接下来对于每一个时间点都去查找前面的时间点能否这样跳到当前的时间节点,如果能的话就修改tim所需片段数。 如此操作时间复杂度是O(n2)
阅读全文

浙公网安备 33010602011771号