随笔分类 - 刷题
摘要:二分图的最大匹配 代码 #include <bits/stdc++.h> using namespace std; const int N = 505, M = 100005; int h[N], e[M], ne[M], idx; int match[N]; bool st[N]; int n1,
阅读全文
摘要:AcWing 1212.地宫取宝 思路 动态规划,数组f[i][j][a][b]的含义为在i,j这个格子,已经取了a个物品,最大物品价值为b的方案的方案数。 题解 #include<bits/stdc++.h> using namespace std; const int N=55,mod=1e9+
阅读全文
摘要:AcWing 1211.蚂蚁感冒 思路 一直感冒的蚂蚁与另一只蚂蚁撞在一起,然后两个蚂蚁都感冒。这个过程可以看作两个蚂蚁互相穿过,也就是说可以看作那只感冒的蚂蚁行走的方向一直没有改变,那么在它行进的方向上与它方向相反的蚂蚁一定会感冒,而它身后的蚂蚁又会再次被感染。所以感冒的蚂蚁数量=第一只感冒的蚂蚁
阅读全文
摘要:AcWing 1227.分巧克力 思路 首先可以确定是二分,然后就是实现的细节,最开始我左边界设为1,右边界是把所有巧克力的总面积计算出来再除以小朋友的数量(最理想情况下),结果怎么都不对,后来想起来,二分的话,左右边界很大也没太大问题,因为只需要几次就会到正常区间了。所以直接把右边界设为10000
阅读全文
摘要:AcWing 789.数的范围 思路: 整数二分,用二分模板做,先找右侧区间的左端点,再找左侧区间的右端点 题解: #include<bits/stdc++.h> using namespace std; const int N=100010; int f[N]; int n,q,x; int ma
阅读全文
摘要:**链接:**https://www.acwing.com/problem/content/791/ 题目 给定一个按照升序排列的长度为 n 的整数数组,以及 q 个查询。 对于每个查询,返回一个元素 k 的起始位置和终止位置(位置从 0 开始计数)。 如果数组中不存在该元素,则返回 -1 -1。
阅读全文
摘要:一天两题,佛系养生/doge 阶乘计算 #include<bits/stdc++.h> using namespace std; const int N=3000; int f[N],n; int main() { cin>>n; f[1]=1; for(int i=2;i<=n;i++) { fo
阅读全文
摘要:链接:https://www.acwing.com/problem/content/description/3764/ 题目: 给定一个长度为 n 的整数数组 a1,a2,…,an。 请你找到数组中只出现过一次的数当中最小的那个数。 输出找到的数的索引编号。 a1 的索引编号为 1,a2 的索引编号
阅读全文
摘要:**链接:**https://www.acwing.com/problem/content/118/ 题目: “飞行员兄弟”这个游戏,需要玩家顺利的打开一个拥有 16 个把手的冰箱。 已知每个把手可以处于以下两种状态之一:打开或关闭。 只有当所有把手都打开时,冰箱才会打开。 把手可以表示为一个 4×
阅读全文
摘要:**链接:**https://www.acwing.com/problem/content/97/ 题目: 你玩过“拉灯”游戏吗? 25 盏灯排成一个 5×5 的方形。 每一个灯都有一个开关,游戏者可以改变它的状态。 每一步,游戏者可以改变某一个灯的状态。 游戏者改变一个灯的状态会产生连锁反应:和这
阅读全文
摘要:**链接:**https://www.acwing.com/problem/content/description/1210/ 题目: 小明正在玩一个“翻硬币”的游戏。 桌上放着排成一排的若干硬币。我们用 * 表示正面,用 o 表示反面(是小写字母,不是零)。 比如,可能情形是:**oo***ooo
阅读全文
摘要:**链接:**https://www.cnblogs.com/longwind7/p/15531056.html 题目: 100 可以表示为带分数的形式: 还可以表示为: 注意特征:带分数中,数字 1∼9 分别出现且只出现一次(不包含 0)。 类似这样的带分数,100 有 11 种表示法。 输入格式
阅读全文
摘要:链接: 题目: Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one
阅读全文
摘要:**链接:**https://www.acwing.com/problem/content/description/95/ 题目: 从 1∼n 这 n 个整数中随机选出 m 个,输出所有可能的选择方案。 输入格式 两个整数 n,m ,在同一行用空格隔开。 输出格式 按照从小到大的顺序输出所有方案,每
阅读全文
摘要:闰年判断 #include<bits/stdc++.h> using namespace std; //const int N=10001; int n; int main() { cin>>n; if(n%400==0||(n%4==0&&n%100!=0)) cout<<"yes"<<endl;
阅读全文
摘要:特殊回文数 #include<bits/stdc++.h> using namespace std; int n; int f5(int x) { int a[5],sum=0; for(int i=0;i<5;i++) { a[i]=x%10; sum+=a[i]; x/=10; } if(a[0
阅读全文
摘要:基础练习 十进制转十六进制 进制转换忘了怎么转了....又用笔画了一下才弄明白,最后还得加一个0的判断,真烦 #include<bits/stdc++.h> using namespace std; char inttochar(int a) { if(a>=0&&a<=9) return a+'0
阅读全文
摘要:基础练习 十六机制转十进制 #include<bits/stdc++.h> using namespace std; //const int N=201; //int a[N]; //int n; int chartoint(char a) { if(a>='0'&&a<='9') return a
阅读全文
摘要:基础练习 数列排序 #include<bits/stdc++.h> using namespace std; const int N=201; int f[N]; int n; int main() { cin>>n; for(int i=0;i<n;i++) cin>>f[i]; sort(f,f
阅读全文
摘要:**链接:**https://www.acwing.com/problem/content/96/ 题目 把 1∼n 这 n 个整数排成一行后随机打乱顺序,输出所有可能的次序。 输入格式 一个整数 n。 输出格式 按照从小到大的顺序输出所有方案,每行 1 个。 首先,同一行相邻两个数用一个空格隔开。
阅读全文

浙公网安备 33010602011771号