- 博客(21)
- 收藏
- 关注
原创 Molecular Formula
原本打算用栈将中缀表达式转后缀表达式,但这类型代码写的太少,自己一个人写不出来,就参考了网上的思路,用双指针法得结果,由于我是在HD提交,unordered_map居然被禁止使用,导致一直编译错误,最后用map才过 #include<iostream> #include<algorithm> #include<unorder_map>//改成#include&l...
2020-03-29 11:29:02 308
原创 骨牌铺方格
简单的递推,没啥坑点 #include<iostream> using namespace std; long long a[51]; int main() { a[1] = 1,a[2] = 2; for(int i=3;i<=50;i++) a[i] = a[i-1] + a[i-2]; int n; while(cin>>n) c...
2020-03-28 20:40:34 71
原创 折线分割平面
算的上一个递推题,没杀难点 #include<iostream> using namespace std; int a[10010]; int main() { int t,n; a[1] = 2; for(int i=2;i<=10000;i++) a[i] = a[i-1] + 4*(i-1)+1; cin>>t; whil...
2020-03-27 22:44:22 57
原创 DNA Sorting(逆序对)
由于50*100 = 5000,数据并不多,直接暴力即可求逆序对 这里给出另一种树状求法 #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int N = 5010; int a[N],c[N],n,m; struct s{ string...
2020-03-26 09:35:49 390
原创 Tian Ji -- The Horse Racing(贪心)
想到了双指针做法来决定策略,原本以为只要不断用自己最大 来寻找比皇帝小就ans += 200,但wa了,看了网上题解才知道原来还有第二步,通过对比另一边来决定策略 #include<iostream> #include<algorithm> using namespace std; const int N = 1010; int main() { int n; whil...
2020-03-24 15:00:48 69
原创 Spreadsheet(拓扑排序)
瞄了一眼题解才发现原来可以用拓扑排序来解决,用二维数组储存临链表可以过,但链式前向星过不去 注释掉的是链式前向星 #include<iostream> #include<queue> #include<algorithm> #include<cstring> #include<cstdlib> #include<vector>...
2020-03-23 16:56:54 244
原创 Number Sequence(矩阵快速幂)
网上有流传49为一个周期循环,但经过实际打表,发现有部分数据不对(但可以ac),所以应该用矩阵快速幂求解 关系矩阵: A B 1 0 #include<iostream> using namespace std; struct M{ int m[2][2]; }; int A,B; M mul(M a,M b) { M ans; for(int i=0;i<2;i++) ...
2020-03-22 10:23:53 123
原创 Fibonacci Again(水题)
打表找规律即可 #include<iostream> using namespace std; int main() { int n; while(cin>>n) { if(n%4==2) cout<<"yes"<<endl; else cout<<"no"<<endl; } } 在网上找的规律之一,还有其他...
2020-03-21 11:34:51 88
原创 人见人爱A^B
用快速幂求乘积同时取模即可 #include<iostream> using namespace std; const long long MOD = 1000; long long quick(long long a,long long b) { long long ans = 1; while(b) { if(b&1) ans = a...
2020-03-20 15:55:40 82 1
原创 Rightmost Digit
考察快速幂的使用 #include<iostream> using namespace std; const long long MOD = 10; long long quick(long long a,long long b) { long long ans = 1; while(b) { if(b&1) ans = (ans%MOD...
2020-03-19 17:05:01 88
原创 oj最小公倍数(水题)
用辗转相除法或者欧几里得定理即可 #include<iostream> using namespace std; int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int main() { int a,b; while(cin>>a>>b) { cout<&...
2020-03-18 14:33:57 275
原创 Elevator(水题)
电梯从0层开始,只需要用一个指针pre记录之前的位置,然后计算就行 #include<iostream> using namespace std; int main() { int n; while(cin>>n&&n) { int sum = 0,pre = 0; sum += n*5; ...
2020-03-17 14:38:51 95
原创 Sum Problem(水题)
水题,没啥坑点 #include<iostream> using namespace std; int main() { int n; while(cin>>n) { int sum = 0; for(int i=1;i<=n;i++) sum += i; cout<<sum<<endl<<endl; } } ...
2020-03-16 15:50:56 130
原创 Prime Ring Problem(基础dfs)
这是一个基础dfs题,用dfs求全排列就行 #include<iostream> #include<cstring> using namespace std; const int N = 10010; int v[N],prime[N]; int a[N],vis[N]; int n; void isprime()//线性筛优化 { int cnt = 0; ...
2020-03-14 11:41:07 87
原创 Uniform Generator(水题)
可以暴力求解,求mod次的种子然后统计每个数字出现次数 也可以求是否互质(可以根据hash表的设计来理解互质就能good choice原因) #include<iostream> #include<cstring> #include<cstdio> using namespace std; const int N = 100010; int vis[N]; in...
2020-03-14 11:38:06 127
原创 Digital Roots(水题)
唯一的坑点,给的数字非常大,需要用数组来保存 尝试了3次,从int,long long ,直到字符串才ac #include<iostream> #include<string> using namespace std; string get_sum(string number) { string str; long long sum = 0; fo...
2020-03-13 09:14:28 118
原创 Big Number(水题)
第一反应是高精度运算 附上wa代码 #include<iostream> #include<vector> using namespace std; vector<int> mul(int number,vector<int> a) { int carry = 0; vector<int>c; for(int i=...
2020-03-13 08:54:06 98
原创 The Hardest Problem Ever
简单来说就是一个偏移字母的的问题,如果时字母就左移,其他就原样输出,坑点就是读入时注意换行以及读入结束标志 #include<iostream> using namespace std; int main() { string d,seq; while(cin>>d&&d!="ENDOFINPUT") { getcha...
2020-03-12 10:43:37 103
原创 A+B for Input-Output Practice (VII)
简单的输入输出练习,需要注意格式 #include<iostream> using namespace std; int main() { int a,b; while(cin>>a>>b) { cout<<a+b<<endl<<endl; } } ...
2020-03-12 10:38:24 119
原创 A+B for Input-Output Practice (V)&(VI)
简单的输出练习 (V) #include<iostream> using namespace std; int main() { int n,t; cin>>t; while(t--) { int sum = 0; cin>>n; for(int i=0,number;i<n;...
2020-03-11 09:44:12 170
原创 A+B for Input-Output Practice (I)
唯一的坑点:需要判断文件末尾 #incldue<iostream> using namespace std; int main() { int a,b; while(cin>>a>>b) cout<<a+b<<endl; }
2020-03-09 19:31:36 198
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人