02 2020 档案
摘要:这道题真的好难啊,必须要好好看看指针的内容了!!! 函数readlist从标准输入读入一系列正整数,按照读入顺序建立单链表。当读到-1时表示输入结束,函数应返回指向单链表头结点的指针 考察尾插法建立链表。 从题目中的printlist函数可以看出,传入的链表是不带头结点的,但是下面的两个函数我都写成
阅读全文
摘要:先序+中序 = 二叉树。 pre[n]存放先序序列,in[n]存放中序序列。 一,递归边界:中序序列的左边界必须小于等于右边界。 二,递归: 1,取当前先序序列[preL,preR]的第一个元素pre[preL]作为根节点root, 2,在当前中序序列中找出根节点root的下标k,把当前中序序列划分
阅读全文
摘要:内心OS:我靠啊!!!我就是偷了一下懒!!!把先序遍历的代码COPY了两份,改成了中序和后序遍历。万万没想到啊!我忘了修改函数中递归函数的名字!!!找这个BUG花了我三个小时~~我哭啊~~,我还以为我的知识体系坍塌了呢?!!~ 总结,这是一道模板题,要先记住大体流程,然后反复练习。 输入格式: 第一
阅读全文
摘要:大致题意就是给出二叉树的后序序列和中序序列,要求重建二叉树,然后输出二叉树的层次遍历序列。 这是一道模板题,要先记住大体流程,然后反复练习。 模板一:后序+中序 = 二叉树。 模板二:层次遍历 即BFS。 1 #include<iostream> 2 #include<queue> 3 #inclu
阅读全文
摘要:内心OS:这道题是去年准备HD复试时,我用来练习DFS的。现在再做这道题,感触颇深,唉,时光蹉跎,物是人非啊~~ 题目: 你有一张某海域NxN像素的照片,”.”表示海洋、”#”表示陆地,如下所示: ……. .##…. .##…. ….##. ..####. …###. ……. 其中”上下左右”四个方
阅读全文
摘要:题目: 给定一个 n x m大小的迷宫,其中 “*” 代表不可通过的墙壁,而 ’.‘代表平地,S表示起点,T表示终点。移动过程中,如果当前位置是(x,y)(下标从0开始),且每次只能往上下左右四个方向的平地移动,求从起点S到达终点T的最少步数。 ..... .*.*. .*S*. .***. ...
阅读全文
摘要:题目: 给定一个 n x m大小的迷宫,其中 “*” 代表不可通过的墙壁,而 ’.‘代表平地,S表示起点,T表示终点。移动过程中,如果当前位置是(x,y)(下标从0开始),且每次只能往上下左右四个方向的平地移动,求从起点S到达终点T的最少步数。 ..... .*.*. .*S*. .***. ...
阅读全文
摘要:题目: 给出一个 m x n 的矩阵,矩阵中的元素为0或1。如果矩阵中有若干个 1是相邻的,那么称这些1构成了一个“块”。求给定的矩阵中“块”的个数。 0 1 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1
阅读全文
摘要:题目: 给出一个 m x n 的矩阵,矩阵中的元素为0或1。如果矩阵中有若干个 1是相邻的,那么称这些1构成了一个“块”。求给定的矩阵中“块”的个数。 0 1 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1
阅读全文
摘要:题目: 给定N 个整数(可能有负数),从中选择 K个数,使得这 K个数之和恰好等于一个给定的整数 X;如果有多种方案,那么选择它们中元素平方和最大的一个。例如,从4个整数{ 2, 3, 3 ,4}中选择 2个数(集合中的每一个数只能被选一次),使它们的和为 6。显然有两种方案{2,4}和{3, 3}
阅读全文
摘要:题目: 有n件物品,每件物品的重量为w[i],价值为c[i]。现在需要选出若干件物品放入一个容量为 V 的背包中,使得在选入背包的物品重量之和,不超过容量V的前提下,让北欧保重物品的价值之和最大,求最大价值。(1<=n<=20) 输入格式: 第一行要求给出 N个物品(1<=N<=20),和容量V;
阅读全文
摘要:麻烦的一批!!!还好题目比较耿直,按要求输出即可,超时就换unordered_map。 新学了小玩意STL-pair,可以理解成一个结构体。 struct pair{ typename1 first; typename2 second; }; 用途: 1.可以代替二元结构体及其构造函数,节省编码时间
阅读全文
摘要:没啥好说的,直接按题意来就可以了。 1 #include"iostream" 2 #include"cmath" 3 #include"algorithm" 4 using namespace std; 5 6 bool isprime(int n) { 7 if(n <=1 ) return fa
阅读全文
摘要:hash就完事了。 1 #include"iostream" 2 using namespace std; 3 4 //由于字符本身是整数,所以用hash判断字符是否是第一次输出 5 bool hashtable[300]= {false}; 6 int main() { 7 string s1,s
阅读全文
摘要:技巧 !!!开一个一维数组,一行一行的接收输入,最后存放的相当于二维数组的每一列的和。 1 #include"stdio.h" 2 #include"string.h" 3 int main() { 4 int a[1001] = {0},N,M,s,i,j,max = -1; 5 scanf("%
阅读全文
摘要:记录一下,用了string的erase函数,erase(起始位置,待删除元素个数),比如str.erase(0,n)表示从起始位置 0 开始删除 n 个数。 1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 int m,k;
阅读全文
摘要:hash就完事了。 新学一招,关于 map<int,vector<int> >的元素的访问。 1 #include<iostream> 2 #include<vector> 3 #include<unordered_map> 4 using namespace std; 5 6 int main()
阅读全文
摘要:第一次做的时候,难得简直让人怀疑人生。。。看别人的代码也搞不懂怎么做。 那天我百度了好久,终于找到了一个比较接地气的题解,总算搞懂了。。。。 这是第二次做了,分析了一波很快就AC了。 题目: 思路分析: 根据题意可以很快得出一个结论,即在N个玩家中,有且仅有一个狼人,一个好人说谎。 首先,我们假设
阅读全文
摘要:注意:我的能力值、丙的能力值可能是double 型,而甲、乙的能力值是 int型,比较的大小的时候要使用double,不然测试点4过不去。 #include<iostream> #include<algorithm> using namespace std; void print(double a,
阅读全文
摘要:hash就完事了。 #include<iostream> using namespace std; bool hashtable[10010] = {false}; int main() { int n,cnt = 0; cin>>n; for(int i = 1; i <= n; ++i) { i
阅读全文
摘要:倒着输出两个数的乘积,比如 101 x 100 = 10100,结果倒着为00101,先跳过高位的00,再输出101。 #include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; string str = to_s
阅读全文
摘要:题目 题意分析: 第一项 为d; 第二项 是对第一项的描述,描述形式为 第一项有1个d,所以第二项为 d1; 第三项 是对第二项的描述,描述形式为 第二项有1个d,1个1,所以第三项为d1 11; 第四项 是对第三项的描述,描述形式为 第三项有1个d,3个1,所以第四项为d1 13; 第五项 是对第
阅读全文
摘要:再次做这道题,收获很多!!! 新技巧get!!!保留结构体的默认构造函数,并构造新的构造函数,用于快速初始化结构体。 用法:结构体名(参数1,参数2,参数3,。。。) 1 #include<iostream> 2 #include<unordered_map> 3 #include<vector>
阅读全文
摘要:hash题。 我刚开始用map做的,因为map按关键字 递减排序,所以我以为倒着输出就可以。代码如下。 结果有的数据根本就无法输出,比如, 输入:2 输入:1 2 输出:(什么也没有) 后来请教了群里的大佬,说有一个反向迭代器。比较简单,比正向迭代器多加一个字母 r ,代码如下。 1 #includ
阅读全文
摘要:水题。 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 5 int main() { 6 int n,id,x,y, MIN = 0x3fffffff,MAX = -1,champion,vegetableBir
阅读全文
摘要:比较坑,注意scanf或者cin 与 getline 之间必须 加一个 getchar(); 坑点与 1078 字符串压缩与解压 一样。 flag1 表示是否存在数字,flag2表示是否存在字母,flag3是否存在非法字符。 1 #include<iostream> 2 #include<cctyp
阅读全文
摘要:这是一道常规体了。 PAT乙级最后一道大题一般是 结构体+排序 +字符串+hash。 1 #include<iostream> 2 #include<unordered_map> 3 #include<algorithm> 4 #include<cmath> 5 using namespace st
阅读全文
摘要:注意点:如果输入的数是 回文数,那么无需计算,直接输出即可。 这题和 B1019数字黑洞 类似,用string处理 即可! ps:第一次做时,写了68行,第二次做时,写了38行。。。 1 #include<iostream> 2 #include<algorithm> 3 using namespa
阅读全文
摘要:比较坑,注意scanf或者cin 与 getline 之间必须 加一个 getchar(); #include<iostream> #include<cctype> using namespace std; int main() { char c; scanf("%c",&c); getchar()
阅读全文
摘要:#include<iostream> #include<algorithm> using namespace std; int hashtable[26] = {0};//统计各个小写字母出现次数 int cnt_alpha = 0,cnt_word = 0,MAX = -1; int main()
阅读全文
摘要:注意点,四舍五入后的数,在输出的时候记得强制转换,不然输出 0 #include<iostream> #include<cmath> #include<algorithm> using namespace std; int main() { int n,m; cin>>n>>m; for(int i
阅读全文
摘要:水题。总结一下吧。 解题一般有两种过程。 第一种,一边输入数据,一边处理数据,一边输出结果。 第二种,首先把所有输入的数据存下,然后处理数据,最后输出结果。 这题属于第一种。 #include<iostream> using namespace std; int main() { int n; ci
阅读全文
摘要:这是我目前为止做过的最麻烦的一道题!!!真不想再碰这道题了!,关于选项的字符串处理相当麻烦!!! 坑点:错误包括 错选 和 漏选。 ps:比 B1058 选择题 麻烦一些。 #include<iostream> #include<algorithm> using namespace std; int
阅读全文
摘要:这是一道 模板题。直接背步骤,写代码。。。。 #include<iostream> #include<algorithm> using namespace std; const int maxn = 100010; struct Node { //第一步:定义静态链表 int address,nex
阅读全文
摘要:坑点一:两个PAT的最高位求和,可能会产生进位carry,最好不要忘了 拼接上 carry。 坑点二:两个PAT的和 可能是 0,要特判输出 0。 #include<iostream> #include<algorithm> using namespace std; int main() { str
阅读全文
摘要:hash题。 解题方法:一边输入数据,一边进行判断和输出。 #include<iostream> using namespace std; bool hashtable[10000] = {false}; int main() { int n,m,temp,cnt1 = 0,cnt2 = 0; ci
阅读全文
摘要:水题。 #include<iostream> using namespace std; int main() { int t,k,n1,b,tt,n2; cin>>t>>k; for(int i = 0; i < k; ++i) { cin>>n1>>b>>tt>>n2; if(tt > t) {
阅读全文
摘要:梳理一下题意就是,如果某个像素点只出现过一次,并且与其周围8个相邻像素之差大于某个阀值tol,那么记录这样的像素点,下面是输出的要求: 方法: 1。用map统计不同像素点出现的次数; 2。用一个函数判断某像素点是否与其周围8个相邻像素之差大于某个阀值tol。 ps:这题给我感觉和 B1089狼人杀
阅读全文
摘要:水题。考STL-map #include<iostream> #include<unordered_map> using namespace std; string str[1010]; unordered_map<string,bool> mp; int main() { int m,n,s; c
阅读全文
摘要:这是一道排序+字符串处理的题目,难度属于PAT乙级,五题中的第三题。 分析:字典序就是字符串在字典中的顺序。例如, 1。“A”的字典序小于“a”; 2。"a"的字典序小于”b“; 3。”aa“的字典序小于”aaaa“ 4。"aaaa"的字典序小于”aab“的字典序,这里从最高位,一个字符一个字符的比
阅读全文
摘要:有种哈夫曼二叉树的思想。 #include<iostream> #include<algorithm> using namespace std; int a[10010] ={0}; int main(){ int n; cin>>n; for(int i = 0 ;i < n;++i) scanf
阅读全文
摘要:坑点一:尝试输入的密码可能包含空格符,所以必须用getline(cin,str)接收一行输入; 坑点二:cin>>str 和getline(cin,str)连用时,中间必须要加getchar()吸收换行符 #include<iostream> using namespace std; int mai
阅读全文
摘要:水题。 看了一下柳婼的代码,发现她是一边输入数据,一边处理后输出数据,这种方法使得代码量少了很多。 #include<iostream> using namespace std; int main() { int m,n,A,B,replace,t; cin>>m>>n>>A>>B>>replace
阅读全文
摘要:任何事物都是质和量的统一体。质和量的统一在度中得以体现。 度是保持质的稳定性的数量界限,即事物的范围、幅度、限度。 超出度的范围,此物就变为它物。 因此,我们必须要坚持底线思维,客观的设定目标,立足最低点,争取最大期望。
阅读全文
摘要:hash题。。。 #include<iostream> #include<algorithm> using namespace std; int hashtable[100500]= {0}; int c[100500] = {0}; int main() { int n,a,b,m; cin>>n
阅读全文
摘要:这道题很容易理解。我第一遍做的时候借助了map,没想到第二遍还是一样,哈哈哈。 但是map用的更娴熟了,开心。 #include<iostream> #include<map> using namespace std; int main() { int n,t,cnt = 0; cin>>n; ma
阅读全文
摘要:水的不能再水。 #include<iostream> #include<cmath> using namespace std; int main() { int n,a,b,MAX = -1; cin>>n; while(n--) { scanf("%d%d",&a,&b); if(MAX < a*
阅读全文
摘要:这道题应该是目前以来第二坑的题,第一坑是 B1051 复数乘法 。 坑点一:分数1可能大于分数2,所以两个分数的值要进行交换。 坑点二:分数必须在开区间内选择(分数1,分数2)。 #include<iostream> #include<algorithm> using namespace std;
阅读全文
摘要:水题。 #include<iostream> using namespace std; int score[200],ans[200] = {0};//分别记录每道题的分值和答案 int main() { int n,m; cin>>n>>m; for(int i = 0; i < m; ++i)
阅读全文
摘要:题意比较难理解, 换句话说 ,就是统计 骑车超过 0公里的 天数 x, 超过 1公里的天数 y,超过 2公里的天数 z,依次类推。。。。 最后找出 骑车天数大于等于 骑车距离,并且骑车距离最远 的骑车天数,好绕啊。。。直接看下面的样例分析吧。。。 分析题目给的样例。 对 10 天的骑车距离按递增排序
阅读全文
摘要:水题,hash题。 #include<iostream> #include<cmath> using namespace std; int hashtable[10000] = {0}; bool isPrime(int n) { //判断是否是素数 if(n <= 1) return false;
阅读全文
摘要:我经常参考别人的代码,可以学到好多有用的技巧,哈哈。 比如说这个题,我把 正确选项个数和所有选项,当成一个整体(字符串实现)看待,方便比较。 比如, 题目的正确答案由,正确选项个数 2,所有选项 a b,组成的话,即 2 a b。 学生给出的答案由,选项个数 2,所有选项 a c,组成的话,即 2
阅读全文
摘要:水题。 #include<iostream> #include<cctype> using namespace std; string str; int main() { getline(cin,str); int sum = 0,r ,cnt0 = 0,cnt1 = 0; for(int i =
阅读全文
摘要:水题。 #include<iostream> using namespace std; int main() { int n,a[10],sum = 0; cin>>n; for(int i = 0; i < n; ++i) cin>>a[i]; for(int i = 0; i < n; ++i)
阅读全文
摘要:根据题目给的信息,倒着来看,在草稿纸上试试,总的来说,有点麻烦。 #include<iostream> #include<algorithm> using namespace std; struct Student { string name; int height; } stu[10010]; s
阅读全文
摘要:这道题很好,可以作为一个简便方法,即判断基本数据类型的某数是否合法,值得回顾。 #include<iostream> #include<cstring> using namespace std; char str1[5000],str2[5000]; int main() { int n,cnt =
阅读全文
摘要:水题,还是要仔细读题。。。。 #include<iostream> using namespace std; int main() { double N,e,D,day,t,ans1 = 0,ans2 = 0; cin>>N>>e>>D; for(int i = 0; i < N; ++i) { s
阅读全文
摘要://坑点一,序号不存在,表示序号可能大于最大值,或者小于最小值。 //坑点二,输出转义字符\,用\\ 注意点: 动态二维数组,只能插入一维数组,不能直接通过语法v[i].push_back(str)实现粒度插入。 但是固定一边的二维数组,可以直接通过语法v[i].push_back(str)实现粒度
阅读全文
摘要:这道题是所有题目中最坑的,可能是之前出题不严谨,也可能是我理解错了题意。 注意点:实部和虚部均保留 2 位小数,并不是指四舍五入后,保留两位小数,而是从小数点后面的第三位开始,直接抹去后面所有的数,此谓保留两位小数。例如,0.008保留 2 位小数后就是0.00。 #include<iostream
阅读全文
摘要:题意: 结果: 分析: 要仔细读题,题目中已经暗示了做题的方法,那么这就是一类简单模拟题。 这个方法就是: 步骤一,把元素向右一直填入矩阵,直到碰到矩阵边界,或者将要填入的位置已存在元素,就停止填入,转步骤二; 步骤二,把元素向下一直填入矩阵,直到碰到矩阵边界,或者将要填入的位置已存在元素,就停止填
阅读全文
摘要:找规律的题目。 题目: 分析: 举例(1,2,3,4)有4个元素,下面是所有可能片段。 情况一,(1),(1,2),(1,2,3),(1,2,3,4),所有片段共有4个1,所以是 4 x 1 x 1 情况二,(2),(2,3),(2,3,4),情况一、二各有3个2,所以是 3 x 2 x 2 情况三
阅读全文
摘要:首先,因为输入的正整数的高位放在存储的低位,所以要对正整数进行逆置。 其次,因为给出的两个正整数的位数可能不一致,所以要处理成位数一致再进行运算。 #include<iostream> #include<algorithm> using namespace std; string hashtable
阅读全文
摘要:水题,hash题。 #include<iostream> #include<unordered_map> using namespace std; int main() { int n,queNum,memNum,score,MAX = -1,index = -1; unordered_map<in
阅读全文
摘要:水题。 #include<iostream> using namespace std; int main() { int n,jiahan,jiahua,yihan,yihua,jia = 0,yi = 0; cin>>n; while(n--) { scanf("%d%d%d%d",&jiahan
阅读全文
摘要:大致题意就是判断给出序列中,哪些元素是主元,即主元元素大于等于其左边的最大值,小于等于其右边的最小值。 例如,1 , 3, 2, 4, 5 1<=1 <=2,所以1是主元。 4<=4<=5,所以4是主元。 5<=5<=INF,所以5是主元。 坑点:输出结束后,必须加一个换行符,不然测试点2显示格式错
阅读全文
摘要:这又是一道hash题。。。 注意点: 地球文如果是13的倍数,那么转换成火星文只输出一个单词,比如 13 要输出 tam; 同样,如果火星文是13的倍数,也只会给出一个单词,比如tam,转换成地球文后输出是13。 #include<iostream> #include<algorithm> usin
阅读全文
摘要:水题。还是一道hash题。 #include<iostream> using namespace std; int main() { int map[128] = {0}; char c; while (scanf("%c",&c) != EOF) map[c]++; while (map['P']
阅读全文
摘要:水题,又是一道hash题。 #include<iostream> #include<cctype> using namespace std; int hashtable[26]= {0}; int main() { char c; while(scanf("%c",&c)!=EOF) { if(is
阅读全文
摘要:水题。发现PAT考察hash很多。 #include<iostream> #include<unordered_map> using namespace std; struct Student { string id;//学号 int sitNum;//考试座位号 }; int main() { i
阅读全文
摘要:分析: PPPATTTTPAT 第一个A的左边有3个P,右边有5个T,此时PAT共有15个。 第二个A的左边有4个P,右边有1个T,此时PAT共有4个。 这个字符串包含的PAT总共有19个。 总结,只要知道每个A的左边共有m个P,右边共有n个T,此时PAT的个数位即为m*n; #include<io
阅读全文
摘要:较水。 #include<iostream> using namespace std; int hashtable1[300] = {0},hashtable2[300]= {0}; int main() { string str1,str2; cin>>str1>>str2; for(int i
阅读全文
摘要:水题。 #include<iostream> using namespace std; int hashtable[111]= {0}; //成绩与人数的映射 int main() { int n,score,k; cin>>n; for(int i = 0; i < n; ++i) { scanf
阅读全文
摘要:水题。 #include<iostream> #include<algorithm> using namespace std; typedef long long LL; int main() { LL G1,S1,K1,G2,S2,K2; scanf("%lld.%lld.%lld %lld.%l
阅读全文
摘要:水题。 #include<iostream> #include<cmath> using namespace std; int main() { int n,m; char c; cin>>n>>c; m = round(n/2.0)-2;//行数 for(int i =0; i< n; ++i)/
阅读全文
摘要:第一种方法。 直接模拟插入排序和非递归的归并排序。。。 #include<iostream> #include<algorithm> using namespace std; int n; int a[111] = {0},b[111]= {0},temp[111] = {0}; bool flag
阅读全文
摘要:这是一种套路题,需要记住大体流程,然后反复练习。 注意点: 因为题目给出的整数可能超过int范围,所以整数都必须用long long型存放,不然最后两个测试点过不去。 #include<iostream> #include<algorithm> using namespace std; typede
阅读全文
摘要:注意点: 一,下划线 _(代表空格),接收输入是真的空格,所以要用getline接收一行输入。 二,判断大写字母能否输出,必须同时上档键+和小写字母的键都未坏。 #include<iostream> #include<cctype> using namespace std; string str1,
阅读全文
摘要:水题。 #include<iostream> using namespace std; int a[100010]= {0}; int main() { int n,num,score,max = -1,pos = -1; cin>>n; for(int i = 0; i < n; ++i) { c
阅读全文
摘要:注意点: 一,加权求和表示,每一位乘以该位的权值最后求和,只对前17位加权求和。 新学一招,整型到字符的hash。 string hashtable = "10X98765432"; #include<iostream> #include<cctype> using namespace std; s
阅读全文
摘要:two pointers通向扫描法。 #include<iostream> #include<algorithm> using namespace std; typedef long long LL; LL a[100010] = {0}; int main() { int n,p,max = -1
阅读全文
摘要:水题。与B1093 字符串A+B 类似。 #include<iostream> #include<cctype> using namespace std; bool hashtable[300] = {false}; int main() { string str1,str2; cin>>str1>
阅读全文
摘要:水题。注意点,可能出现合理生日的总数为0的情况,要特判输出。 #include<iostream> using namespace std; int main() { int n,cnt = 0; string name,birthday; string youngest_name,youngest
阅读全文
摘要:水题。在计算层数的时候卡了十几分钟,我好菜。 #include<iostream> using namespace std; int main() { int N; char c; cin>>N>>c; int layer = 1,sum = 1;//sum表示层数layer对应的总字符数 whil
阅读全文
摘要:水题。 #include<iostream> #include<cmath> using namespace std; int main() { int c1,c2; cin>>c1>>c2; int t = round((c2-c1)/100.0);//不足 1 秒的时间四舍五入到秒 int h
阅读全文
摘要:大致题意就是给出栈的容量M,给出入栈序列的最大元素N(默认入栈顺序是1,2,3,...N), 给出K个可能的出栈序列,判断出栈序列是否合法,合法输出“YES”,否则,输出“NO”。 第一种方法。 首先给出一个结论(以前刷408练习题时看到的): 出栈序列中每个元素的后面的所有比它小的元素,一定可以组
阅读全文
摘要:大致题意就是找出一段话中,最常出现的单词。 注意点: 一,这里的单词由大小写字母和数字组成,坑死我了。 二,使用ctype库中的函数时,如果判断条件写成if(isupper(str[i]) == false),那么代码跑不动!必须写成if( !isupper(str[i]))(巨坑的语法) STL:
阅读全文
摘要:大致题意就是给出N行M列的元素,找出出现次数最多的元素并输出。 #include<iostream> #include<unordered_map> using namespace std; int main() { unordered_map<int,int> mp; int m,n; cin>>
阅读全文
摘要:这是一种套路题,要先记住大体流程,然后反复练习。 其中第一,二,三,四步是套路,第五步按题意处理结点,第六步结点信息的输出方式是套路。 #include<iostream> #include<algorithm> using namespace std; const int maxn = 10010
阅读全文
摘要:题意不难理解,但是做起来比较麻烦。 用的string的erase(迭代器),find(字符串)返回pos和substr. 给出的数用str存放,如果是负数,就输出'-',否则不输出。然后用erase移除第一个符号,无论正负。 然后把str按照E划分成两个部分,前半部为a,后半部为e。 如果e < 0
阅读全文
摘要:水题。//输入为2 0 0 0 0 0 0 0 0 0会输出 00,但是还是对的。奇怪 #include<iostream> using namespace std; int a[10] = {0}; int main() { int flag = 0; for(int i = 0; i < 10;
阅读全文
摘要:使用了STL中的stack,常用操作的时间复杂度大都是O(1)。 总体比较水。考察进制转换的除基取余法。 #include"iostream" #include<stack> using namespace std; int main() { int a,b,d,sum; cin>>a>>b>>d;
阅读全文
摘要:水题。 #include"iostream" using namespace std; int hashtable[10] = {0}; int main() { string str; cin>>str; for(int i = 0; i < str.length(); ++i) hashtabl
阅读全文
摘要:简单贪心算法。 把月饼按单价递减的顺序排列。 需求一定时,每次售出单价最高的月饼存量. #include"iostream" #include<algorithm> using namespace std; struct Moocake { double store,sale,price; } m[
阅读全文
摘要:注意:位数不够四位,就高位补0; 新学一个string函数。str.insert(pos,N,字符)表示在pos位置,插入N个字符。 #include"iostream" #include<algorithm> using namespace std; bool cmp(char a,char b)
阅读全文
摘要:岂可修,居然做错一次,水题。 #include"iostream" using namespace std; int main() { int N; cin>>N; int A = 0, B = 0, C = 0;//A,B,C 表示甲的胜,平,负 int a[3]= {0},b[3]= {0};
阅读全文
摘要:大整数与整数的除法运算,求商q,余数r。 思路就是小学的除法运算。 默认初始余数 r = 0。 第一步,r = r*10+bign[i]-'0'; 第二步求商,q = r/d; 第三步求余数,r = r%d; #include"iostream" using namespace std; int m
阅读全文
摘要:水题。 #include"iostream" using namespace std; int main() { string str1,str2; char da,db; int pa = 0,pb = 0; cin>>str1>>da>>str2>>db; for(int i = 0; i <
阅读全文
摘要:没啥好说的,按题意对数据排序输出即可。 STL:vector,string.用cin/cout可能会超时,改成scanf和printf即可。 #include"iostream" #include"algorithm" #include"vector" using namespace std; st
阅读全文
摘要:题意有点不明不白。 注意点:字符间的比较是在同一下标进行的(不然测试点1,4过不了)。 #include"iostream" #include"cctype" using namespace std; string hashtable1[7] = {"MON ","TUE ","WED ","THU
阅读全文
摘要:我做这题使用了两种方法。 第一种,就是在第N到第M个素数的范围内,一边判断是否是素数,一边输出。 #include"iostream" #include"cmath" using namespace std; bool isPrime(int n) {//判断是否是素数 if(n <= 1) ret
阅读全文
摘要:水题。注意判断就可以了。 #include"iostream" using namespace std; int main() { int n,t,ans1 = 0,ans2 = 0,flag = 2,ans3 = 0,ans4 = 0,num = 0,max = -1; cin>>n; for(i
阅读全文
摘要:#include"iostream" using namespace std; typedef long long LL; int main() { LL a,b,c; int n; cin>>n; for(int i =1; i <=n; ++i) { printf("Case #%d: ",i)
阅读全文
摘要:水题。忘了结构体类型变量之间可以直接赋值。惭愧。 #include"iostream" #include"algorithm" using namespace std; struct Student { string name,id; int score; }; int main() { int n
阅读全文
摘要:大致题意就是按指数递减的方式给出多项式的非零系数和指数。然后求一次导,输出结果即可。 如果给的多项式只有一个常数,就输出0 0 如果给的多项式项数大于1,且包含一个常数,那么输出时,不输出常数项求导的结果。 #include"iostream" using namespace std; //零多项式
阅读全文
摘要:水题。 STL:vector,string #include"iostream" #include"vector" using namespace std; int main() { vector<string> vs; string str; while(cin>>str) vs.push_bac
阅读全文
摘要:给定6个元素:1 2 3 4 5 6 要求循环右移2次,结果:5 6 1 2 3 4. 思路: 首先对1 2 3 4取反,结果:4 3 2 1 5 6 然后对5 6取反,结果 :4 3 2 1 6 5, 最后全部取反,结果:5 6 1 2 3 4.即为所求。 注意点,如果元素个数n 小于 要求循环右
阅读全文
摘要:大致题意就是找出1到N中,满足素数相邻且差值为2的素数对数。 #include"iostream" #include"cmath" using namespace std; //判断素数 bool isPrime(int n) { if(n <= 1) return false; int t = s
阅读全文
摘要:水题。 #include"iostream" using namespace std; int main() { int n; cin>>n; int a = n/100;//百分位 int b = n%100/10;//十分位 int c = n%10;//个位 while(a--) cout<<
阅读全文
摘要:这道题是一道找规律的题目。第一次做时,看了半天题意看不懂。 第3个条件是第2个条件的一种延申。 对于条件2,AAPATAA“答案正确”,再看条件3,AAPAATAAAA必然“答案正确” 对于条件2,AAPAATAAAA“答案正确”,再看条件3,AAPAAATAAAAAA必然答案正确。 ... ...
阅读全文
摘要:#include"iostream" #include"vector" #include"algorithm" using namespace std; bool hashtable[20000] = {false}; //因为待映射的值可能比较大,所以数组开大一点,不然最后两个测试点会出现 段错误
阅读全文
摘要:水题。 #include"iostream" using namespace std; string s[11] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; int main() { int ans = 0; string
阅读全文
摘要:水题。 #include"iostream" using namespace std; int main() { int n,ans = 0; cin>>n; while(n != 1) { if(n % 2==0) n/=2; else n=(3*n+1)/2; ans++; } cout<<an
阅读全文
摘要:大致题意就是给出两个浮点数A,B,首先把它们按 0.(有效数字)*10^(指数) 表示,并且都保留N位有效数字。 最后判断A,B是否相等。 有效数字是指从左边第一个不是0的数开始计数。如果长度不够,则末尾补零。 假设下面的浮点数都保留三位有效数字00.00123表示为0.123*10^(-2)000
阅读全文
摘要:这是一种套路题,要先记住大体流程,然后反复练习。 1.大整数的表示。 struct bign { int d[1000]= {0};//大数的低位数放数组的低位,高位数放数组的高位,即顺位存储,方便加,减,乘。 而除比较特别。 int len = 0;}; 太晚了,改天理思路。 #include"s
阅读全文
摘要:这是一种套路题,要先记住大体流程,然后反复练习。 1.分数的表示。 struct Fraction { long long up,down;//up表示分子,down表示分母}; 规定: 第一点,先使分母非负数,如果分数是负,那么令分子是负的 第二点,如果分数是零,那么令分子是0,分母是1. 第三点
阅读全文
摘要:大致题意就是给出N个整数的集合(编号1到N),然后给出K个不同的查询,每个查询给出集合的两个编号i 和 j,计算这两个集合的相似度。 Nc表示两个集合的交集的不同元素的总个数,Nt表示两个集合合并以后的不同整数的总个数。 计算相似度的公式为 Nc/Nt×100%。 STL:unord
阅读全文
摘要:1039 Course List for Student 依靠unordered_map<string,set<int>> ans 解决问题。 这次依靠unordered_map<int ,vector<string>> ans;如果vector改成set(自带自排序+去重)最后一个测试点会超时导致
阅读全文
摘要:哈哈哈哈!!! 会STL的好处完全体现在了这类题目上!!!简直不要太爽!!! STL:unordered_map<string,set<int> > ans; auto智能指针 #include"iostream" #include"unordered_map" #include"set" usin
阅读全文
摘要:因为N被连续整数 5*6*7整除的结果是3,而3只是相对于连续整数乘积的产物,说明重点是找出连续整数。所以大致题意就是给出一个N,找出一段连续整数,使得N被整除。 观察样例给出的答案发现,N不会被除自身以外大于sqrt(N)的数整除。可以用两个for循环暴力枚举。 #include"iostream
阅读全文
摘要:大致题意就是给定N个数,找出满足第i个数到第j个数的和SUM等于M(如果找不到,也可以找SUM-M>0差值最小)的i和j,并输出i-j。 思路:可以使用数组SUM[i]存放1到i的和,这样i到j的和可以写成SUM[j]-SUM[i-1]。 这题可以用二分法做,但是二分法边界值条件太多,容易出错,推荐
阅读全文
摘要:#include"stdio.h" #include"stdlib.h" typedef struct TBTNode { int data; int ltag,rtag;//ltag == 0表示存在左孩子 ,ltag == 1表示存在前驱线索 struct TBTNode *lchild; st
阅读全文
摘要:题目大意就是给定N个车辆进出校园的信息,给定K个查询,每个查询给出一个时刻,要求输出此时校园内的车辆总数。 最后输出停车时间最长的车牌号,如果车牌号不唯一,按字典顺序输出每个车牌号,最后输出最长停车时间。 思路:首先,把每个车辆信息记录下来,并按时间递增排序。 然后,用unordered_map保存
阅读全文
摘要:大致题意就是有N个学生,有M个学校,每个学校的名额都是正整数。每个学生可以填K个学校志愿,N个学生一起排名以后,排名高的学生先挑学校,不保护一志愿。 题目要求: 首先,把所有学生按总成绩SUM(GE+GI)递减排序,如果SUM相同,那么就按GE递减排序。 然后,根据成绩确定所有学生的名次。如果当前学
阅读全文

浙公网安备 33010602011771号