摘要:
https://www.acwing.com/problem/content/1615/ 写出一个正确的dfs就可以了。 1 #include<iostream> 2 using namespace std; 3 char s[9][9]; 4 bool row[9][10],col[9][10],
阅读全文
posted @ 2021-02-10 16:35
greenofyu
阅读(78)
推荐(0)
摘要:
https://www.acwing.com/problem/content/1232/ 求出一个数组中是k的倍数的连续子序列有多少个。 因为数组元素大于0,所以保证前缀和数组是一个单调上升数组。 将前缀和数组分为k类,模k为0,模k为1... 对于每一个前缀和只需要找和他同类的有多少个就可以了。
阅读全文
posted @ 2021-02-09 22:44
greenofyu
阅读(63)
推荐(0)
摘要:
A:水题,求数组中只出现一次的元素的和。 1 class Solution { 2 public: 3 int sumOfUnique(vector<int>& nums) { 4 unordered_map<int,int> m; 5 for(auto x:nums){ 6 m[x]++; 7 }
阅读全文
posted @ 2021-02-09 21:44
greenofyu
阅读(54)
推荐(0)
摘要:
https://www.acwing.com/problem/content/1416/ 给定一串序列,要找到异或值最大的子串。 在保证右端点最小的前提下保证长度最小。 对于异或的性质 a^b^a = b,可以将前缀和应用于该题。 这样的话只需要枚举左端点和右端点,但是时间复杂度为n^2,计算之后达
阅读全文
posted @ 2021-02-09 15:54
greenofyu
阅读(53)
推荐(0)
摘要:
Trie树查找和插入的时间复杂度均为O(n)。 https://www.acwing.com/problem/content/837/ 1 #include<iostream> 2 using namespace std; 3 const int N=1e5+10;//输入字符串的总长度为1e5+1
阅读全文
posted @ 2021-02-09 11:40
greenofyu
阅读(70)
推荐(0)
摘要:
https://www.acwing.com/problem/content/427/ 水题。 unique函数是将相邻的相同的元素去除掉,返回的是最后一个元素的下一个迭代器,时间复杂度为n。 1 #include<algorithm> 2 #include<iostream> 3 using na
阅读全文
posted @ 2021-02-09 11:03
greenofyu
阅读(53)
推荐(0)
摘要:
https://www.acwing.com/problem/content/481/ 给定从1~n编号的n个节点和他们各自的权值,构造出一颗中序遍历为1~n的得分最大的二叉树,输出其得分和前序遍历。 得分规则具体如下:如果根节点既有左子树又有右子树,那么得分=左子树*右子树+根节点权值 如果左子树
阅读全文
posted @ 2021-02-08 23:10
greenofyu
阅读(61)
推荐(0)
摘要:
https://www.acwing.com/problem/content/419/ 水题。 1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 int max_time=0,max_day=0; 5 for(int i=
阅读全文
posted @ 2021-02-07 22:31
greenofyu
阅读(34)
推荐(0)
摘要:
https://www.acwing.com/problem/content/423/ 水题。 1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 int a[10]; 5 for(int i=0;i<10;i++){ 6
阅读全文
posted @ 2021-02-07 22:30
greenofyu
阅读(36)
推荐(0)
摘要:
https://www.acwing.com/problem/content/430/ 考察快速幂相关知识。 1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 int k,n; 5 cin>>k>>n; 6 int res
阅读全文
posted @ 2021-02-06 20:11
greenofyu
阅读(32)
推荐(0)