随笔分类 - 题目&题解
摘要:首先用一个结构体存放原始的键值和下标。 然后遍历该结构体数组,如果当前遍历的节点的键值的绝对值没有在前面出现过,那么就再开一个数组用来存该节点的编号,并且标记为出现过,防止后续再次存他的下标。否则如果出现过,那么就再开一个数组存之前出现过的节点的下标。然后将头节点往后移,h = next[h] 如此
阅读全文
摘要:解释看这位大神的:链接 #include <bits/stdc++.h> using namespace std; const int N = 100010; int q[N]; bool st[N]; int n; int main() { cin >> n; for(int i = 0; i <
阅读全文
摘要:这题考察的就是数据结构里面的插入排序和归并排序的每一步的操作和流程。 可惜我太菜了。考试的时候做不出来! #include <bits/stdc++.h> using namespace std; const int N = 110; int a[N], b[N]; int n; int main(
阅读全文
摘要:正着跑一边,然后反着跑的把所有边的方向调换一下就好了。在图基础上加n再方向,这样很方便!orz!!! #include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i = 0; i < int(n); i++) #de
阅读全文
摘要:写题的时候还是太紧张了,心态不够好,导致审题不清,慌慌张张。怎么办呢??? #include <iostream> using namespace std; int main() { string s; cin >> s; int leng = s.size(), flag = 0; for(int
阅读全文
摘要:#include <iostream> #include <cstring> using namespace std; const int N = 1010, INF = 0x3f3f3f3f; int l[N], r[N], val[N], n; int cnt[N], max_depth; vo
阅读全文
摘要:1/A题: https://codeforces.com/contest/1649/problem/A 这一题其实很简单,就是要求最左边和最右边的最小距离(只能跨一次水,no more than once!!!) #include <iostream> #include <cstring> usin
阅读全文
摘要:#include <iostream> using namespace std; int main(){ char op; int sad = 0, happy = 0, unhappy = 0, a = 0, b = 0; while(cin >> op) { if(op == '$') brea
阅读全文
摘要:#include <iostream> #include <algorithm> using namespace std; const int N = 10010; struct Peo { double housenum, area; }people[N]; struct Fam { int id
阅读全文
摘要:#include <iostream> #include <queue> using namespace std; const int N = 40; struct node { int data; node *lchild; node *rchild; }; int last[N], in[N];
阅读全文
摘要:给定一棵树,找出从根节点到叶节点的最长路径(如果有多个最长路径,输出节点数字小的那个); #include <iostream> #include <cstring> using namespace std; const int N = 10010; int h[N], e[N], ne[N], i
阅读全文
摘要:开两个数组,一个数组存物品的数量,一个数组代表箱子,表示第i个箱子的已经存的容量。 #include <iostream> using namespace std; const int N = 1010; int q[N], a[N]; int n; int main() { cin >> n; f
阅读全文
摘要:#include <iostream> using namespace std; const int N = 40; int q[N]; int k, n; void dfs(int st, int cnt, int total) { if(total == n) { k++; cout << n
阅读全文
摘要:这题我想到的就是用二进制,不过我的代码只能拿12分,去网上搜了一下别人的AC代码,有点不理解,但是感觉还行。 #include <iostream> #include <cmath> using namespace std; int main() { int n, m; cin >> n >> m;
阅读全文
摘要:对n行样例边判断边输出,先遍历每个字符判断逗号和句号的前面3个字符是否为ong。是的话开始倒序遍历空格,将第三个空格的下标进行存储,然后正序遍历到存储位置,后面拼接上qiao ben zhong.,否则直接输出Skipped #include <iostream> #include <cstring
阅读全文
摘要:我们用一个二维数组存数据。用g[i][0]存第i个学校的总人数。 然后 我们 以行为学校编号,展开每个学校的人数。 从第一列到最后一列依次由上往下编号。 #include <iostream> using namespace std; const int N = 110; int g[N][N];
阅读全文
摘要:这题实际上是模拟除法;上马原课的时候领悟到了,hh #include <iostream> using namespace std; int main() { int x; cin >> x; int ans = 0, cnt = 0; while(ans < x) { ans = ans * 10
阅读全文
摘要:首先创建一个二维数组,然后将输入的字符串按从左到右的顺序依次从二维数组的倒数第一列开始装入,装满装第二列,以此类推.... #include <iostream> #include <cstring> using namespace std; const int N = 1010; char g[N
阅读全文
摘要:暴力穷举!!! 注意前导0,还有 0 也算一个数,不能用 while(year) 判断循环结束 要不然 0 就加不上了。 #include <iostream> #include <cstring> using namespace std; int judge(int y) { int a[10],
阅读全文
摘要:暴力!!!冲冲冲!!! #include <iostream> #include <cstring> using namespace std; int main() { string A, B; getline(cin, A); getline(cin, B); for(int i = 0; i <
阅读全文