![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
诠释你的Mr贾
这个作者很懒,什么都没留下…
展开
-
开心的金明 背包问题
开心的金明 背包问题背包问题解析:https://www.cnblogs.com/yun-an/p/11037618.htmlhttps://blog.csdn.net/qq_38984851/article/details/81133840/#include<iostream>#include<string.h>using namespace std;int a[30];int v[30]; //价格 int w[30]; //重要度 int f[30原创 2021-02-01 14:16:25 · 49 阅读 · 0 评论 -
Flooded! POJ - 1877 模拟题
Flooded! POJ - 1877模拟题这篇文章题解写的很好附上自己的代码#include<iostream>#include<algorithm>using namespace std;int m,n;double wat; //每次总水量double a[1005];int main(){ int cases=1; while(scanf("%d%d",&m,&n)==2 && m && n)原创 2021-01-31 23:38:50 · 88 阅读 · 0 评论 -
Word Amalgamation POJ - 1318 字符串排序
Word Amalgamation POJ - 1318方法一 STL string#include<iostream>#include<string>#include<cstring>#include<algorithm>#include<map>using namespace std;map<string,string> dic;int main(){ string ss; string gg; whi原创 2021-01-30 22:36:11 · 97 阅读 · 0 评论 -
快速排序
快速排序#include<iostream>using namespace std;int a[100005];int partion(int l,int r){ int tmp=a[l]; int low=l; int high=r; while(low<high) { while(low<high && a[high]>=tmp) high--; a[low]=a[high]; while(low<high原创 2021-01-30 19:23:13 · 58 阅读 · 0 评论 -
Brainman POJ - 1804 归并排序求逆序对数
Brainman POJ - 1804 归并排序求逆序对数原理:可以用归并排序计算逆序对数,在归并排序中的交换次数就是这个序列的逆序对数:归并排序是将序列a[l, r]分成两个序列a[l, mid]和a[mid1, r],分别进行归并排序,然后再将这两个有序序列进行归并排序,在归并排序的过程中,设l<=i<=mid,mid+1<=j<=r,当a[i]<=a[j]时,并不产生逆序对数;而当a[i]> a[j]时,则在有序序列a[l, mid]中,在a[i]后面原创 2021-01-30 16:28:49 · 134 阅读 · 0 评论 -
To The Max HDU - 1081 动态规划 最长公共子序列
To The Max HDU - 1081 动态规划 最长公共子序列#includeusing namespace std;int maxnn;int M[105][105];int s[105][105]; //记录 第j列 前i行数之和int n;void dp(int d ,int cur) //矩阵宽度为d,从第cur开始 dp{int max_num;int sum;max_num=s[cur+d-1][1]-s[cur-1][1];sum=s[cur+d-1][原创 2021-01-26 22:06:35 · 48 阅读 · 0 评论 -
最长公共子序列dp Jill Rides Again UVA - 507
最长公共子序列dpdp sum[i] = max{sum[i] + a[i], a[i]}left right maxn 记录最长左右边和最大值#include<iostream>using namespace std;int a[20005];int main(){ int cases; int n; int left,right; int l ,r; int sum; int maxn; scanf("%d",&cases); int n原创 2021-01-26 20:56:45 · 129 阅读 · 1 评论 -
Coin Toss POJ - 3440 -数学计算
Coin Toss POJ - 3440注意 :1.输出字符%,用%%转义而不是/%2.注意可能出现-0,如果都是整数最好加个abs函数#include<iostream>using namespace std;#include<cmath>#define pi 3.1415926535897932384626433832795028841971693993751058209749445int cases;int m,n;double t,c;int mai原创 2021-01-24 14:09:49 · 106 阅读 · 0 评论 -
Simple division 欧几里得算法
Simple division```cpp求输入一行数的最大除数,且余数相同#include#includeusing namespace std;//注意 求两个数a,b的最大公约数,a和b的差值一定为是被除数的整数倍,因此 gcd(a,b)=gcd(b,b%a)int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}int main(){int g=0;int a1,a2,d;while(cin>>a原创 2021-01-21 15:03:10 · 332 阅读 · 0 评论 -
UVA127-“Accordian“ Patience
UVA127-“Accordian” Patience模拟+栈注意开结构体的技巧#include<iostream>using namespace std;struct card{ char a[53][3]; //记录每堆的扑克信息 int top; //记录该堆栈顶位置 }cc[53]; //记录每堆牌 void change(int loc,int dis) //从左往右数,loc位置的顶堆牌放在loc-dis的位置上 { cc[loc-d.原创 2021-01-19 17:20:31 · 127 阅读 · 0 评论 -
Maya Calendar POJ - 1008
Maya Calendar POJ - 1008 解题思路:先将日历转换为总天数,再转换为另外一个日历注意:1.第一个日历天数从0开始,转换为总天数要再加一!! 2.总天数转第二个日历是,当sum%2600,year要减一!!!3.当下标从一开始,仿照:sum%130?13:sum%13,#include<iostream>using namespace std;#include<string>string Haabmonth[20]={"","pop","no",原创 2021-01-19 13:00:49 · 102 阅读 · 0 评论 -
计蒜客 一维跳棋 BFS
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<algorithm>#include<queue>#include<unordered_map>using namespace std;unordered_map<string, bool> vis;struct Node{ stri.原创 2020-12-19 10:53:47 · 158 阅读 · 2 评论 -
一:开门人和关门人 研究生机试 map 二:map插入方法及区别 三:pair
一:先上题解#include<iostream>#include<queue>using namespace std;#include<map>int n;map<string,string> openn;map<string,string> closee;priority_queue<int,vector<int>,greater<int> > myqueue;int main(){ in原创 2020-11-04 12:03:54 · 92 阅读 · 0 评论 -
臭味相投 研究生机试
链接:https://www.nowcoder.com/questionTerminal/0177394fb25b42b48657bc2b1c6f9fcc来源:牛客网“臭味相投”——这是我们描述朋友时喜欢用的词汇。两个人是朋友通常意味着他们存在着许多共同的兴趣。然而作为一个宅男,你发现自己与他人相互了解的机会并不太多。幸运的是,你意外得到了一份北大图书馆的图书借阅记录,于是你挑灯熬夜地编程,想从中发现潜在的朋友。 首先你对借阅记录进行了一番整理,把N个读者依次编号为1,2,…,N,把M本书依次编原创 2020-11-04 11:33:50 · 167 阅读 · 0 评论 -
Head of a Gang 研究生机试 最小生成树
**Head of a Gang 研究生机试 最小生成树**链接:https://www.nowcoder.com/questionTerminal/a31b1ea6c87647bc86e382acaf21c53b来源:牛客网One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between A and B, we say that A原创 2020-11-04 09:30:32 · 70 阅读 · 0 评论 -
最小生成树 Kruskal算法
最小生成树#include<iostream>using namespace std;#include<algorithm>#include<cmath>int n;int height[105];int father[105];int index;double sum;struct Point{ double x; double y;}p[105];struct Eage{ int x; int y; double length;原创 2020-11-04 08:57:10 · 53 阅读 · 0 评论 -
2020-10-02
dfs求正整数最大因子的个数#include<iostream>using namespace std;//注:某个数的因子如 2^3*3^3,因子个数为(3+1)*(3+1),每个因子可以选择0-指数个typedef long long ll;int T;ll n ;int prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; //2*3*5*7*11*13*17*19.....,,15个就到达60次方了ll原创 2020-10-02 11:49:33 · 116 阅读 · 0 评论