06 2020 档案
摘要:题目链接:幸运数字Ⅱ 打表: #include<bits/stdc++.h> using namespace std; typedef long long ll; ll l,r,j,ans,pos; ll k[10005],g; void dfs(ll x) { if(x>4444444444) r
阅读全文
摘要:题目链接:走出迷宫 DFS解法: #include<bits/stdc++.h> using namespace std; const int maxn=510; int n,m,s1,s2,t1,t2; char mp[maxn][maxn]; int vis[maxn][maxn]; int d
阅读全文
摘要:搜索 • 通过不停的试探去寻找解的一种算法。 • 与其说是一种算法,不如说是一种方法。 • 基础的方法有暴力的搜索法,深搜,广搜三种。 • 更高级的有IDDFS,DBFS,A*,IDA*等等 深度优先搜索(dfs) “一条道走到黑”“走不了了再倒回去” 算法过程: VOID DFS(状态 A) 1.
阅读全文
摘要:老子的全排列呢 #include<bits/stdc++.h> using namespace std; int orders[10];//8个位置 int chosen[10];//标记 void dfs(int x){ if(x>=9){//如果超过8 for(int i=1;i<=8;i++)
阅读全文
摘要:编译型语言和解释型语言 计算机只能识别二进制编码(机器码),所以任何的语言在交由计算机执行时必须要先转换为机器码, 也就是像 print('hello') 必需要转换为类似 1010101 这样的机器码 根据转换时机的不同,语言分成了两大类: 编译型语言 - C语言 - 编译型语言,会在代码执行前将
阅读全文
摘要:Sublime Text 3 纯文本编辑器 Package Control(Sublime的包管理器) Sublime Text3中的插件,通过该插件可以向Sublime中安装新的包 Sublime Text 3的安装 下载链接 添加到右侧菜单(傻瓜试安装) Sublime Text 3的设置 ①P
阅读全文
摘要:逆序数 转载这位大佬的解释 算法讲解 既然我们已经归并排序怎么归的了,那我们就要知道他怎么求逆序数了。 首先我们要知道归并是利用了什么求出来的逆序数:在二路归并的时候,如果序列后面的数跑到前面来了,中间路过了多少个数,他前面就有多少个数比他- 大。 这不就正好是,计算前面有多少个数比他大的过程吗嘿嘿
阅读全文
摘要:分治 当我们求解某些问题时,由于这些问题要处理的数据相当多,或求解过程相当复杂,使得直接求解在时间上相当长,或者根本无法直接求出。对于这类问题,我们往往先把它分解成几个子问题,找到求出这几个子问题的解法后,再找到合适的方法,把它们组合成求整个问题的解法。如果这些子问题还较大,难以解决,可以再把它们分
阅读全文
摘要:[HNOI2003]激光炸弹 二维前缀和问题 每一个点用格子代替 求(0,0)到(i,j)之间的前缀和 :f[i][j]+=f[i-1][j]+f[i][j-1]-f[i-1][j-1]; 计算每一个格子的价值:ans=max(ans,f[i][j]-f[i-R][j]-f[i][j-R]+f[i-
阅读全文
摘要:拼数 把整数转换为字符串 自定义排序函数:如果a+b>b+a,则把a排在前面,否则将b排在前面(对于字符串a、b,a+b表示连接两个字符串形成一个新串) #include<bits/stdc++.h> using namespace std; #define maxn 1010 #define in
阅读全文
摘要:明明的随机数 桶排序,把在区间输入的数都标记为1 适用于这种数据范围不是很大的 #include<bits/stdc++.h> using namespace std; #define maxn 1010 #define inf 0x3f3f3f3f #define mm(a,x) memset(a
阅读全文
摘要:校门外的树 模拟写法 把在区间的所有都标记一下,没标记的计数 这个题数据范围不是很大,可以这样 #include<bits/stdc++.h> using namespace std; const int maxn=1e4+2; int cnt[maxn]; int main(){ int l,m;
阅读全文
摘要:纪念品分组 贪心策略:最大的先和小的组合 先从小到大排列,然后从左右两边开始找符合条件的两件纪念品,如果不符合,就让右边的单独放一组 #include<bits/stdc++.h> #define maxn 30005 using namespace std; int a[maxn]; int ma
阅读全文
摘要:铺地毯 覆盖地面某个点的最上面的那张地毯的编号 从后往前枚举,前提是这个点在地毯上面 #include<bits/stdc++.h> #define maxn 100005 using namespace std; struct Node{ int x,y,up,right; }a[maxn]; i
阅读全文
摘要:数学考试 区间求和问题可以想到一个常用算法:前缀和。区间的和可以用方便地求出。 维护第一个长度为k的最大值,枚举第二个长度为k的起点,答案就是max(ans,当前长度为k的序列和+第一个长度为k的序列和) #include<bits/stdc++.h> using namespace std; #d
阅读全文
摘要:一、枚举 一一列举 不重复、不遗漏 优化枚举的基本思路:——减少枚举次数 1、选择合适的枚举对象 2、选择合适的枚举方向——方便排除非法和不是最优的情况 3、选择合适的数据维护方法——转化问题 eg:数列求和问题 给你一个数列(1≤n≤100000),有q(1≤q≤100000)次询问,每次询问数列
阅读全文
摘要:奇♂妙拆分 简单的质因子拆分题,计数注意是从1开始. #include<bits/stdc++.h> using namespace std; void chai(int n){ int cnt=1; for(int i=1;i<sqrt(n);i++){ if(n%i==0){ n/=i; cnt
阅读全文
摘要:糖糖别胡说,我真的不是签到题目 先假设所有人都不会被消灭,求出第n秒的所有人的战力 从后往前遍历,分别记录两个队的战力最大值,如果第i个人的战力小于后面另一个队的最大战力值,则一定会被消灭 #include<bits/stdc++.h> using namespace std; #define ll
阅读全文
摘要:1017 A除以B (20分) orz柳诺小姐姐的代码 //模拟手动除法的过程,每次用第一位去除以B,如果得到的商不是0就输出,否则就*10+下一位,直到最后的数为余数~ #include <iostream> using namespace std; int main() { string s;
阅读全文
摘要:1013 数素数 (20分) 测试点4就是素数可能超出10000这个大小,所以设置大点,例如:105000 #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstrea
阅读全文
摘要:1007 素数对猜想 (20分) 注意这个条件 i+2<=n ,不然会超出范围 #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream> #include<st
阅读全文
摘要:1003 我要通过! (20分) 得出重要结论:p*(t-p-1)==s.length()-1-t #include<iostream> #include<map> using namespace std; int main(){ int n;cin>>n; while(n--){ int t=0,
阅读全文
摘要:1049 数列的片段和 (20分) #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream> #include<string> #include<cstdio>
阅读全文
摘要:1019 数字黑洞 (20分) 一个字符串的写法,坑点就是可能会出现不到4位的数,进行补零 #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream> #incl
阅读全文
摘要:1035 插入与归并 (25分) 数据比较小,归并不用写合并函数,直接sort 中间序列不包括初始序列 #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream>
阅读全文
摘要:1045 快速排序 (25分) 求划分的主元(比左边的都大,右边的都小) #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream> #include<strin
阅读全文
摘要:1040 有几个PAT (25分) 和1045快排那个思想很像 左边、右边的分别累加在数组中存入 #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream> #i
阅读全文
摘要:1030 完美数列 (25分) 二分查找常用函数: lower_bound() 函数用于在指定区域内查找不小于目标值的第一个元素 upper_bound() 函数定义在头文件中,用于在指定范围内查找大于目标值的第一个元素 第一次写的代码,测试点4没过 下面举个例子,如数组:1,2,3,4,5,6,7
阅读全文
摘要:1020 月饼 (25分) 把单价先计算一下,然后按照单价高依次出售 #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream> #include<string>
阅读全文
摘要:1023 组个最小数 (20分) -做完散列感觉这个好像散列,算法笔记把它分在了贪心emmm #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream> #inc
阅读全文
摘要:1005 继续(3n+1)猜想 (25分) 输入的数列里面,输出“关键数”(没被覆盖的) 标记一下n往后的就可以了,标记的是覆盖的 eg:{3、5、8、4、2、1},标记{5、8、4、2} #include<iostream> #include<vector> #include<cctype> #i
阅读全文
摘要:#include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream> #include<string> #include<cstdio> #include<algorith
阅读全文
摘要:1043 输出PATest (20分) 注意控制已有字符的输出 存放的输出了就减一,存放个数必须大于零 #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream>
阅读全文
摘要:1042 字符统计 (20分) 本题只让输出小写字母 小写字母转换为数字0~25 输出的时候再转换回来 #include<iostream> #include<vector> #include<cctype> #include<map> #include<set> #include<sstream>
阅读全文
摘要:1039 到底买不买 (20分) 甲级也有一样的题 #include<iostream> #include<vector> #include<cctype> #include<algorithm> #include<sstream> #include<string> #include<cstdio>
阅读全文
摘要:1038 统计同成绩学生 (20分) #include<iostream> #include<vector> #include<cctype> #include<algorithm> #include<sstream> #include<string> #include<cstdio> const
阅读全文
摘要:测试点2有个坑就是不能用cin来输入字符 题目保证第二行输入非空,第一行可能是空,cin读不了空字符 #include<iostream> #include<vector> #include<cctype> #include<algorithm> #include<sstream> #include
阅读全文
摘要:1029 旧键盘 (20分) 用str【200】来标记已经输出的字符,散列查找 #include<iostream> #include<vector> #include<ctype.h> #include<algorithm> #include<sstream> #include<string> #
阅读全文
摘要:1015 德才论 (25分) 分四个等级的排序,想简化的朋友可以用结构体数组容器存储啦~ #include<iostream> #include<vector> #include<ctype.h> #include<algorithm> #include<sstream> #include<stri
阅读全文
摘要:1024 科学计数法 (20分) substr():substr(起始位置,往后要几个字符) stoi():string转换为int,参数必须是字符串,字符的话用substr(ch,1)转换为字符串 常用字符串处理函数: 参数是字符即可 isalpha();//是否为字母 isdigit();//是
阅读全文
摘要:1014 福尔摩斯的约会 (20分) 这道题坑多,看清题目要求 第 1 对相同的大写英文字母(大小写有区分)是第 4 个字母 D,只能是A~G 第 2 对相同的字符:0 点到 23 点由数字 0 到 9、以及大写字母 A 到 N 表示 后面两字符串第 1 对相同的英文字母 s 出现在第 4 个位置(
阅读全文
摘要:1031 查验身份证 (15分) 把不符合的输出 没有就输出All passed #include<iostream> #include<ctype.h> #include<sstream> #include<string> #include<cstdio> const int maxn=110;
阅读全文
摘要:知道stringstream这个类型就很简单 用于把空格过滤掉 stringstream ss(s);//初始化ss string word; int cnt=0; while(ss >> word){ str[cnt++]=word;//将输入的一行字符串依次存入字符串数组中 } #include
阅读全文
摘要:1002 写出这个数 (20分) [1002 写出这个数 (20分)](https://pintia.cn/problem-sets/994805260223102976/problems/994805324509200384) #include<iostream> #include<string>
阅读全文
摘要:1021 个位数统计 (15分) #include<iostream> #include<string> #include<cstdio> using namespace std; int main(){ string s;cin>>s; int a[1005]={0}; for(int i=0;i
阅读全文
摘要:1006 换个格式输出整数 (15分) #include<iostream> #include<string> #include<cstdio> using namespace std; int main(){ int n;cin>>n; string s=to_string(n); if(s.le
阅读全文
摘要:1037 在霍格沃茨找零钱 (20分) 跟时间小时分钟题的进制转换大体一样,模拟一下 #include<iostream> #include<cstdio> const int Galleon=17*29; const int Sickle=29; using namespace std; int
阅读全文
摘要:1022 D进制的A+B (20分) 这题是十进制转换为d进制的题 从后往前存入的 do{ z[num++]=n%d; n/=d; }while(n!=0); #include<iostream> using namespace std; int main(){ int a,b,d;cin>>a>>
阅读全文
摘要:1027 打印沙漏 (20分) 注意输出的字符是自己输入的,不是固定的'*' 先求出多少层,然后到一定条件反转一下就行了 #include<iostream> using namespace std; int main(){ int n,m; string s; cin>>n>>s; int lev
阅读全文
摘要:1036 跟奥巴马一起编程 (15分) 注意一下空格就行了 #include<iostream> #include<algorithm> using namespace std; int main(){ int n,m;string s; cin>>n>>s; if(n%2){ m=n/2+1; }
阅读全文
摘要:1032 挖掘机技术哪家强 (20分) 从 1 开始连续编号 #include<iostream> #include<algorithm> const int maxn =100005; using namespace std; struct Node{ int id,grade=0; }stu[m
阅读全文
摘要:用容器存数组简单一些,字符串string好些 一个坑点就是没有有效生日,只输出0 #include<iostream> #include<vector> #include<cstdio> #include<algorithm> using namespace std; struct Node{ st
阅读全文
摘要:1004 成绩排名 (20分) 直接sort了,找最大最小值 #include<iostream> #include<algorithm> using namespace std; struct Node{ string name; string id; int grade; }; bool cmp
阅读全文
摘要:1041 考试座位号 (15分) 先附上自己写的辣鸡代码,第一次非常傻,查找输入的id,用了双重for循环 虽然这次数据小体现不出来,但是下次要注意orz #include<iostream> const int maxn = 1005; using namespace std; struct No
阅读全文
摘要:自己写一个划拳的change函数来调用 并且用字符数组来存放输入的字符 最重要的就是一个循环相克 0 1 2 布 石头 剪刀 (k1+1)%3 == k2 为赢 ,反之为输,k1==k2为平 #include<iostream> #include<cstdio> #include<cstring>
阅读全文
摘要:1012 数字分类 (20分) 有个卡点就是A2可能加加减减就为0了,对此进行排查 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main() { int n; cin>>n; int
阅读全文
摘要:1008 数组元素循环右移问题 (20分) 本题有个注意点:当m超过n的值时,循环重复,本身取余 #include<iostream> #include<algorithm> #include<vector> using namespace std; int main(){ int n,m; cin
阅读全文
摘要:1046 划拳 (15分) 简单模拟 #include<iostream> using namespace std; int main(){ int n;cin>>n; int ans1=0,ans2=0; while(n--){ int a1,a2,b1,b2; cin>>a1>>a2>>b1>>
阅读全文
摘要:1026 程序运行时间 (15分) 自己错误:double用了%来取余,发现不能用,必须用转换为int来取余 1、先四舍五入来往上进一 2、将总共的秒来分别转换为整时整分整秒 秒转换为整时:ans/3600 其余秒转换为整分:ans%3600/60 总共秒取余转换为整秒:ans%60 #includ
阅读全文
摘要:1016 部分A+B (15分) 先掌握一些十进制的转换 ll sum=0,sum=sum*10+a; while(a!=0){a/=10,a%10...} #include<iostream> using namespace std; typedef long long ll; int main(
阅读全文
摘要:1011 A+B 和 C (15分) 注意点: 题目要求A、B在int范围内(int占32位,取值范围为-2147483648~2147483647(-231~ 231-1)) A+B范围(-230~ 232)就超过了int范围,因此用long long #include<iostream> #in
阅读全文
摘要:1001 害死人不偿命的(3n+1)猜想 (15分) 简单的模拟题,根据题来做就行了 #include<iostream> using namespace std; int main(){ int n; cin>>n; int level=0; while(n!=1){ if(n%2==0){ n/
阅读全文