02 2021 档案
-
蓝桥杯--芯片测试
摘要:http://47.104.209.207/problem/old1065 如果超过n/2的芯片测试i为正常,那么i就是正常的。 反证:如果i不是正常的话,那么至少n/2个芯片的测试结果是错误的,与条件相违背。 不漏性证明:即证明如果少于n/2个芯片说i正常,那么i不可能是正常的。 从条件出发,至少 阅读全文
-
蓝桥杯--FJ的字符串
摘要:http://47.104.209.207/problem/old1064 字符串处理。 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 5 using namespace std; 6 int main() 7 阅读全文
-
蓝桥杯--Sine之舞
摘要:http://47.104.209.207/problem/old1063 字符串处理,直接依据定义输出字符串。 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 5 using namespace std; 6 阅读全文
-
蓝桥杯--完美的代价
摘要:http://47.104.209.207/problem/old1061 可以证明直接将头部的字母固定,而后从尾部找与其相同的字母并不会使结果变差。 对于第i个字母,假设与之匹配的为k,他应该放置的位置是n-i-1,那么ans=k-(n-i-1) 如果第i个字母放于其他的位置上,对于第i个字母对, 阅读全文
-
蓝桥杯--矩阵面积交
摘要:http://47.104.209.207/problem/old1060 计算出相交矩阵的左下和右上两个顶点。 1 #include<cmath> 2 #include<iostream> 3 #include<queue> 4 #include<vector> 5 #include<algori 阅读全文
-
蓝桥杯--矩阵乘法
摘要:http://47.104.209.207/problem/old1059 直接用矩阵乘法的性质,注意0次方的时候是变成单位矩阵。 1 #include<cmath> 2 #include<iostream> 3 #include<queue> 4 #include<vector> 5 #inclu 阅读全文
-
蓝桥杯--分解质因数
摘要:http://47.104.209.207/problem/old1058 先用筛法筛出所有质数,然后对每个数进行质因数分解。 1 #include<cmath> 2 #include<iostream> 3 #include<queue> 4 #include<vector> 5 #include 阅读全文
-
蓝桥杯--01字串
摘要:http://47.104.209.207/problem/old1007 直接按位与。 1 #include<iostream> 2 #include<queue> 3 #include<vector> 4 #include<algorithm> 5 using namespace std; 6 阅读全文
-
蓝桥杯--阶乘计算
摘要:http://47.104.209.207/problem/old1072 需要用到高精度乘法(高精度数乘以int)。 1 #include<iostream> 2 #include<queue> 3 #include<vector> 4 #include<algorithm> 5 using na 阅读全文
-
蓝桥杯--高精度加法
摘要:http://47.104.209.207/problem/old1071 直接用模板就好,反过来方便些。 1 #include<iostream> 2 #include<queue> 3 #include<vector> 4 #include<algorithm> 5 using namespac 阅读全文
-
蓝桥杯--huffman树
摘要:http://47.104.209.207/problem/old1070 问Huffman树的费用,直接用堆解决。 1 #include<iostream> 2 #include<queue> 3 4 using namespace std; 5 6 int main(){ 7 int n; 8 阅读全文
-
蓝桥杯--2N皇后问题
摘要:http://47.104.209.207/problem/old1069 先dfs黑皇后然后dfs白皇后,因为麻烦所以直接暴力check当前位置是否合法。 1 #include<iostream> 2 const int N=20; 3 4 using namespace std; 5 int s 阅读全文
-
Codeforces Round #702
摘要:A:给定一个序列,一个操作是向其中任何一个位置插入一个数,问至少需要多少次操作才能保证两两之间的max(a[i],a[i+1])/min(a[i],a[i+1])<=2。 假设在i和i+1之间插入一个数,这个操作并不会影响到其他,所以我们可以线性的考虑整个序列。 那么我们现在只需要考虑如果a和b,m 阅读全文
-
leetcode周赛 227
摘要:A:问能否将一个数组通过轮换的方式得到一个单调不减的数组。 因为范围只有100,直接将数组拷贝并排序,然后对原数组轮换n次,每次进行一下判断。 1 class Solution { 2 public: 3 bool check(vector<int>&a,vector<int>& b){ 4 int 阅读全文
-
AcWing每日一题--拼写正确
摘要:https://www.acwing.com/problem/content/1479/ 水题。 得到sum后可每一次提取个位数字,或直接将其to_string。 解法一: 1 #include<iostream> 2 #include<algorithm> 3 using namespace st 阅读全文
-
AcWing每日一题--数字反转
摘要:https://www.acwing.com/problem/content/447/ 水题。 1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 int n; 5 cin>>n; 6 int res=0; 7 while( 阅读全文
-
AcWing每日一题--质因数分解
摘要:https://www.acwing.com/problem/content/451/ 水题。 确定p有且仅有两个质因子。 故可直接枚举较小的那个质因子。 1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 int p; 5 阅读全文
-
AcWing每日一题--数字统计
摘要:https://www.acwing.com/problem/content/443/ 水题。 1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 int l,r; 5 cin>>l>>r; 6 int cnt=0; 7 f 阅读全文
-
AcWing每日一题(提高组)--聪明的质监员
摘要:https://www.acwing.com/problem/content/501/ 1 #include<iostream> 2 using namespace std; 3 const int N=200010; 4 typedef long long LL; 5 int v[N],w[N]; 阅读全文
-
AcWing每日一题(提高组)--耍杂技的牛
摘要:https://www.acwing.com/activity/content/code/content/846810/ n个牛进行叠罗汉,每头牛有一个重量w和强壮程度s,风险等级定义为头上的牛的质量减去我的强壮程度,问如何叠最大的风险等级最小。 1 #include<algorithm> 2 #i 阅读全文
-
AcWing每日一题--比例简化
摘要:https://www.acwing.com/problem/content/460/ 发现L的范围只有100,直接枚举分子分母。 1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 int gcd(int a,int b) 阅读全文
-
AcWing每日一题(提高组)--糖果传递
摘要:https://www.acwing.com/problem/content/submission/124/ n个同学围成一个圈,每个同学手上有ai个糖果,每传递一个糖果代价为1,问最少代价为多少使得糖果均分。 将解得的x1,x2....xn带入目标式子中。 所以只需要构造一种糖果传递方案,使得每次 阅读全文
-
AcWing每日一题(提高组)--数度简单版
摘要: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], 阅读全文
-
AcWing每日一题(提高组)--K倍区间
摘要:https://www.acwing.com/problem/content/1232/ 求出一个数组中是k的倍数的连续子序列有多少个。 因为数组元素大于0,所以保证前缀和数组是一个单调上升数组。 将前缀和数组分为k类,模k为0,模k为1... 对于每一个前缀和只需要找和他同类的有多少个就可以了。 阅读全文
-
leetcode双周赛 45
摘要: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 } 阅读全文
-
AcWing每日一题(提高组)--牛异或
摘要:https://www.acwing.com/problem/content/1416/ 给定一串序列,要找到异或值最大的子串。 在保证右端点最小的前提下保证长度最小。 对于异或的性质 a^b^a = b,可以将前缀和应用于该题。 这样的话只需要枚举左端点和右端点,但是时间复杂度为n^2,计算之后达 阅读全文
-
数据结构--Trie树
摘要: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 阅读全文
-
AcWing每日一题--明明的随机数
摘要:https://www.acwing.com/problem/content/427/ 水题。 unique函数是将相邻的相同的元素去除掉,返回的是最后一个元素的下一个迭代器,时间复杂度为n。 1 #include<algorithm> 2 #include<iostream> 3 using na 阅读全文
-
AcWing每日一题(提高组)--加分二叉树
摘要:https://www.acwing.com/problem/content/481/ 给定从1~n编号的n个节点和他们各自的权值,构造出一颗中序遍历为1~n的得分最大的二叉树,输出其得分和前序遍历。 得分规则具体如下:如果根节点既有左子树又有右子树,那么得分=左子树*右子树+根节点权值 如果左子树 阅读全文
-
AcWing每日一题--不高兴的津津
摘要: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= 阅读全文
-
AcWing每日一题--陶陶摘苹果
摘要: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 阅读全文
-
AcWing每日一题--数列
摘要: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 阅读全文
-
AcWing每日一题--ISBN号码
摘要:https://www.acwing.com/problem/content/435/ 1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 string s; 5 cin>>s; 6 int res=0; 7 for(int 阅读全文
-
AcWing每日一题--a^b
摘要:https://www.acwing.com/problem/content/91/ 考察快速幂的知识; 1 #include<iostream> 2 using namespace std; 3 typedef long long LL; 4 LL ksm(LL a,LL b,LL p){ 5 L 阅读全文
-
动态规划--线性dp-2
摘要:1、最长公共子序列问题 https://www.acwing.com/problem/content/899/ 写代码时,因为 f ( i-1 , j ) 包含了 f ( i-1 , j-1 ) ,所以一般是不将其写出来的。 初始值的话,根据定义考虑,将 f [ 0 , 0~m ],f [ 0~n 阅读全文
-
AcWing每日一题--献给阿尔吉侬的花束
摘要:https://www.acwing.com/problem/content/1103/ 搜索题,数据范围为1<=n,m<=200。 所以dfs是必然超时的,时间复杂度为(200*200)! 1 void dfs(PII now,PII e,int step){ 2 if(now==e){ 3 re 阅读全文
-
AcWing每日一题(提高组)--星空之夜
摘要:https://www.acwing.com/problem/content/1404/ 考察flood fill 和 图的hash。 这题有两问:1、找出图中的全部连通块 2、根据形状给给将相似的连通块换上同一个字符 对于第一问,可以直接应用flood fill算法。 对于第二问,我们可以通过ha 阅读全文
-
AcWing每日一题--数独检查
摘要:https://www.acwing.com/problem/content/705/ 考虑每个独立方块的左上角和右下角。 单独检查每一个独立方块。 1 #include<iostream> 2 #include<unordered_map> 3 using namespace std; 4 con 阅读全文
-
AcWing每日一题--开心的金明
摘要:https://www.acwing.com/problem/content/428/ 给定总钱数n,和m个物品,每个物品有价格和重要度两个属性。 问在总价格不超过n的情况下,选中物品的价格*重要度的和最大是多少。 可以抽象为01背包模型,总钱数为背包容量,价格为物品体积,价格*重要度为物品价值。 阅读全文