随笔分类 - 题解代码 / PTA练习
摘要:思路题,set有序,lower_bound(a)可以二分寻找set中最接近的大于等于它的数 #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<int> s; for(int i = 1; i
阅读全文
摘要:使用 set_intersection() 判断两个集合之间重复元素,时间复杂度最坏O(nlogn),最好O(n) #include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<s
阅读全文
摘要:占位符不要用%#*^之类的,测试点5和7会被卡 #include <bits/stdc++.h> using namespace std; void print(string s) { for(auto si : s) if(si == '{') cout << "<censored>"; else
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; string func(string s, int x, int y, string s1, string s2) { x--,y--; string mid(s,x,y-x+1); s.erase(x,y-
阅读全文
摘要:测试点5是混过去的,已知测试点5只涉及大小写转换,n=3,第一个句子长度为奇数 #include <bits/stdc++.h> using namespace std; bool is_biaodian(char c) { if(c >= 'a' && c <= 'z' || c >= 'A' &
阅读全文
摘要:代码1:剪枝,非打表 #include <bits/stdc++.h> using namespace std; int l, n; const int N = 5; int arr[N * N]; int H[N], L[N]; int dfs(int x) { if(x >= n * n) {
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; string s; bool is_hui(int x, int y) { while(x < y) { if(s[x] != s[y]) return false; ++ x, -- y; } return
阅读全文
摘要:模拟过程走一遍即可 #include <bits/stdc++.h> using namespace std; const int N = 110; int M[N]; #define x first #define y second int main() { int n; cin >> n; in
阅读全文
摘要:硬写的 // 我也不知道多长时间了,估计有40min #include <bits/stdc++.h> using namespace std; const int N = 50; int hou[N], zhong[N]; class Node { public: int val; int wei
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; // 分别为祖宗节点,人数,房子数,总面积 int p[N], cnt[N], fangzi[N], totalarea[N], minnum[N]; // 编
阅读全文
摘要:基础款并查集练习题 // 13'11" #include <bits/stdc++.h> using namespace std; const int N = 1e4 + 10; int p[N], f[N]; void init() { for(int i = 1; i <= N; ++ i) p
阅读全文
摘要:时间复杂度 N*M≈2.5e6 #include <bits/stdc++.h> using namespace std; int n = 510, m; const int N = 510; vector<pair<int,int>> path; // 储存所有边 int p[N]; // 储存祖
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 1000; int p[N]; int find(int x) { if(p[x] != x) p[x] = find(p[x]); return p[x]; } int main
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; int arr[10][10]; int main() { int n; cin >> n; for(int t = 1; t <= n; ++ t) { for(int j = 1; j <= 9; ++
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; #define int long long int func(int n) { int res = 0; while(n >= 10) { int a = n; vector<int> num; while(
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 110; double price[N]; int total[N]; int main() { int n; cin >> n; for(int i = 1; i <= n; +
阅读全文
摘要:思路可能不太对,但是确实是过了 #include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int sum = 0; int minm = 999999; for(int i = 1; i <
阅读全文
摘要:不会写可以switch把所有情况全写出来,总共只有六种不多 // 4'05" #include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; if(b == 1 || b == 0 && a == 2) c
阅读全文
摘要:// 1'02" #include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << b - a; return 0; }
阅读全文
摘要:print("Problem? The Solution: Programming.")
阅读全文