
暑假ACM
hhdmw
这个作者很懒,什么都没留下…
展开
-
SG函数博弈
题目链接一个关于SG的博弈游戏,对于某个堆有MiMi和LiLi,那么这个堆的SG值为SGi=Mi%(Li+1)定义SG(x)=mex(S)),其中S是x的后继状态的SG函数值集合,mex(S))表示不在S内的最小非负的整数。我们先取L=5来看一下当M=1时,由于1的后继状态只有0,由sg定义可得sg[1]=mex{sg[0]}=1,当M=2时,2的后继状态有0,1得...转载 2018-09-26 09:17:57 · 180 阅读 · 0 评论 -
大数加法
#include<iostream>#include<string>using namespace std;struct bign{ int d[1000]; int len; bign(){ memset(d,0,sizeof(d)); len=0; }};bign change(char str[]){ bign a; a.len=s...原创 2018-08-06 20:37:46 · 124 阅读 · 0 评论 -
PAT A1059
给出一个int范围的整数,按照从小到大的顺序来输出其分解为质因数的乘法算式#include<iostream>#include<algorithm>using namespace std;const int maxn=100000;int prime[maxn];bool p[maxn]={false};int num=0;struct factor{...原创 2018-08-06 19:55:12 · 201 阅读 · 0 评论 -
数素数
#include<iostream>using namespace std;const int maxn=10010;int prime[maxn],pnum=0;bool p[maxn]={false};void findprime(int n){ for(int i=2;i<maxn;i++) { if(p[i]==false) { prime...原创 2018-08-06 16:42:07 · 147 阅读 · 0 评论 -
简单贪心月饼PATB1020
算法笔记118-119 #include<iostream>#include<algorithm>using namespace std;struct node{ double cun; double shou; double bi;}nodes[1010];bool cmp(node a,node b){ return a.bi>b....原创 2018-08-01 19:37:37 · 222 阅读 · 0 评论 -
快速排序
#include<iostream>using namespace std; int partition(int a[],int left,int right) { int temp=a[left]; while(left<right) { while(left<right&&a[right]>temp) { r...原创 2018-08-06 10:59:41 · 153 阅读 · 0 评论 -
归并排序
#include<iostream>using namespace std;const int maxn=100;void merge(int a[],int l1,int r1,int l2,int r2){ int i=l1; int j=l2; int temp[maxn]; int index=0; while(i<=r1&&j<...原创 2018-08-06 10:16:36 · 158 阅读 · 0 评论 -
递归求全排列。1-n
#include<iostream>using namespace std;const int maxn=11;int n,p[maxn],hashTable[maxn]={false};void generateP(int index){ if(index==n+1) { for(int i=1;i<=n;i++) { printf("%d",p[i...原创 2018-08-01 16:04:53 · 355 阅读 · 0 评论 -
字符串hash初步
给出N个字符串(三个小写字母),再给出M个查询字符串,问每个查询字符串在N个字符串中出现的次数。#include<iostream>using namespace std;const int maxn=100;char s[maxn][5],temp[5];int hashTable[26*26*26+10];int hashFunc(char s[],int l...原创 2018-08-01 15:20:48 · 211 阅读 · 0 评论 -
动态规划最长公共子序列
#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int N=100;char a[N],b[N];int dp[N][N];int main(){ freopen("C:\\Users\\23535\\Desktop\\in.t...原创 2018-07-28 10:50:32 · 123 阅读 · 0 评论 -
动态规划最长回文序列
#include<iostream>#include<cstring>using namespace std;int main(){ freopen("C:\\Users\\23535\\Desktop\\in.txt","r",stdin); //输入重定向,输入数据将从D盘根目录下的in.txt文件中读取 freopen("C:\\Users\...原创 2018-07-27 23:41:59 · 261 阅读 · 0 评论 -
动态规划最大连续子序列和
#include<iostream>#include<algorithm>using namespace std;int main(){ freopen("C:\\Users\\23535\\Desktop\\in.txt","r",stdin); //输入重定向,输入数据将从D盘根目录下的in.txt文件中读取 freopen("C:\\User...原创 2018-07-27 22:52:04 · 382 阅读 · 0 评论 -
杭电OjCard Game Cheater (模拟田忌赛马)
题目传送门题目分析:亚当夏娃玩扑克牌比大小,当点数相同时比较花色,红桃最大,然后是黑桃,再是方块,最后是梅花。夏娃知道亚当的出牌顺序,她最多能赢几把。做法:讲花色转换成数字的大小进行比较,然后运用田忌赛马的知识,先夏娃的最大的牌与亚当最大的牌比,然后夏娃最小的牌和亚当最小的牌比,然后拿亚当最大的牌和夏娃最小的牌比较。#include<stdio.h>#inclu...转载 2018-09-26 08:53:18 · 1522 阅读 · 0 评论 -
动态规划,寻找最长上升子序列问题
题目链接 FatMouse's Speed 题目大意:给定一些老鼠的体重和速度,要求找出一些序列,体重逐渐增加,速度逐渐减小。要求输出序列中老鼠的个数与编号,答案不唯一。典型的最长是上升子序列问题,但是这个输出编号不会弄。网上找的博客是定义一个数组,数组中存储这个编号的上一只老鼠,即可找出所有符合要求的老鼠的编号。#include <iostream&g...转载 2018-09-20 11:20:39 · 231 阅读 · 0 评论 -
三分查找
已知左右端点L,R,求顶点(极值)的位置。思路通过不断缩小 [L,R] 的范围,无限逼近白点。 做法:先取 [L,R] 的中点 mid,再取 [mid,R] 的中点 mmid,通过比较 f(mid) 与 f(mmid) 的大小来缩小范围 当最后 L=R-1 时,再比较下这两个点的值,我们就找到了答案1、当 f(mid) > f(mmid) 的时候,我们可以断定 mmid 一定在白...原创 2018-09-13 16:23:04 · 158 阅读 · 0 评论 -
并查集&最小生成树Kruskal算法
杭电oj1233 还是畅通工程Problem Description某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。Input测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( &...原创 2018-09-12 21:05:19 · 249 阅读 · 0 评论 -
数论,直线分割平面&球体
一·n条直线最多分割多少平面问题假设n-1条直线分割了f(n-1)个部分,第N条直线最多与n-1条直线相交,有n-1的交点。n-1个交点将第n条直线分割成n-2条线段和2个射线,线段和射线各自将原来的区域分割成两部分,多出了(n-2)+2个部分。故:f(n)=f(n-1)+n=f(n-2)+(n-1)+n……=f(1)+1+2+……+n=n(n+1)/2+1二·n条射线最多分割...原创 2018-09-06 21:37:49 · 875 阅读 · 0 评论 -
匈牙利算法
参考了趣写算法这篇文章来理解匈牙利算法,但是还没有吃透找增广路径算法原理,不能合理带入算法思想,嘤。匈牙利算法用增广路求最大匹配(称作匈牙利算法,匈牙利数学家Edmonds于1965年提出) 算法轮廓:置M为空 找出一条增广路径P,通过取反操作获得更大的匹配M’代替M 重复2操作直到找不出增广路径为止找增广路径的算法我们采用DFS的办法找一条增广路径: 从X部一个未匹配的...转载 2018-09-16 15:14:51 · 419 阅读 · 0 评论 -
牛客网第二场D购买物品求利益
题目利用贪心的思想,寻找上升子序列。。如果下一个商品价格大于当前,继续向下遍历,否则在当前卖出,下一个买入(存到pre).注意要比较pre与判断出要在此处卖出的价格大小。#include<iostream>#include<algorithm>#include<math.h>#include<cstring>#define ll l...原创 2018-08-28 16:47:14 · 251 阅读 · 0 评论 -
PTA A1053 深搜与先根遍历
#include<iostream>#include<algorithm>#include<vector>using namespace std;const int maxn=110;struct node{ int weight; vector<int> child;}nodes[maxn];bool cmp(int a,in...原创 2018-08-16 11:15:50 · 232 阅读 · 0 评论 -
KMP
并没有理解为什么j=next[j];玛德#include<iostream>using namespace std;char s[50];char text[50];char pattern[50];int next[50];void getnext(char s[],int* next,int len){ int j=-1; next[0]=-1; for(...原创 2018-08-13 10:36:33 · 135 阅读 · 0 评论 -
动态规划数字三角形
#include<iostream>using namespace std;int d[100][100];int *maxsum;//int n;int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= ...转载 2018-07-22 19:27:39 · 147 阅读 · 0 评论 -
简单的数学题
简单求和问题SUM(n) = 1 + 2 + 3 + ... + nYou may assume the result will be in the range of 32-bit signed integer.Sample input:10Sample output:55http://acm.hdu.edu.cn/showproblem.php?pid=1001解法:SUM(n) = 1 + 2...原创 2018-07-13 23:01:30 · 270 阅读 · 0 评论 -
杭电OJ1016
#include<iostream>using namespace std;int cnt=1;int n;int vis[21],a[21];int comp(int n){ int i,flag=1; for (i=2;i<=sqrt(n);i++) if (n%i==0) {flag=0;break;} if (flag==1) return 1; else retur...原创 2018-07-13 22:23:42 · 369 阅读 · 0 评论 -
广度优先搜索例二
#include<queue>#include<cstring>#include<cstdio>using namespace std;int X[4]={0,0,1,-1};int Y[4]={1,-1,0,0};int n,m;char maze[1000][1000];bool inq[1000][1000]={false};struc...转载 2018-07-24 22:29:40 · 137 阅读 · 0 评论 -
广度优先搜索算法笔记例一
#include<iostream>#include<queue>#include<stdio.h>using namespace std;const int maxn=100;struct node{ int x,y;}nodes;int n,m;int X[4]={0,0,1,-1};int Y[4]={1,-1,0,0};in...转载 2018-07-24 21:11:37 · 232 阅读 · 0 评论 -
快速幂算法
int PowerMod(int a, int b, int c){int ans = 1;a = a % c;while(b>0){if(b % 2 = = 1)ans = (ans * a) % c;b = b/2; // b/2是整除吗?a = (a * a) % c;}return ans;}博客网址https://www.cnblogs.com/PegasusWang/archi...转载 2018-07-12 23:33:25 · 113 阅读 · 0 评论 -
最大公约数
int gcd(int da,int xiao) { int temp; while (xiao!=0) { temp=da%xiao; da=xiao; xiao=temp; } return(da);}原创 2018-07-12 21:37:21 · 447 阅读 · 0 评论 -
PAT 1002:A+B for Polynomials
#include <iostream>#include <vector>#include <cstdio>using namespace std;int main(){ vector<double> arr(1001); int A; cin >> A; for(int i=0; i<A; i++){ ...转载 2018-07-12 21:22:18 · 99 阅读 · 0 评论 -
杭电Oj1008电梯
#include<iostream>using namespace std;int main(){ int N; while(cin>>N) { if(N==0) { break; } int x[100]={0}; x[0]=0; int sum=0; for(int i=1;i<=N;i++) { cin>>x[i]; ...原创 2018-07-12 20:11:08 · 399 阅读 · 2 评论 -
初识ACM
输入函数scanf(“ %s%s”,str1,str2),在多个字符串之间用一个或多个空格分隔;若使用gets函数,应为gets(str1); gets(str2); 字符串之间用回车符作分隔。通常情况下,接受短字符用scanf函数,接受长字符用gets函数。而getchar函数每次只接受一个字符,经常c=getchar()这样来使用。getline 是一个函数,它可以接受用户的输入的字符,直到已...原创 2018-07-12 18:52:48 · 144 阅读 · 0 评论 -
杭电oj1567
When the old year is leaving and the New Year is coming, people are always looking back over the past while looking forward to the future. "What do you think is the most important events in the...转载 2018-07-17 13:31:15 · 433 阅读 · 0 评论 -
HDU OJ 1071: The area
HDU OJ 1071: The area序言: 刚自学了一个月的算法,算个小萌新吧(其实实在菜的一匹…)。考虑到很多知识点容易遗忘,就准备写些东西来记录一下学习过程。第一次写博客,今天先写个简单的练练手。Problem Description:Ignatius bought a land last week, but he didn’t know the area of the ...转载 2018-07-17 13:28:18 · 423 阅读 · 0 评论 -
贪心算法
一 事件序列问题 (1)区间完全覆盖问题问题描述:给定一个长度为m的区间,再给出n条线段的起点和终点(闭区间),求最少使用多少条线段可以将整个区间完全覆盖?样例:区间长度8,可选的覆盖线段[2,6],[1,4],[3,6],[3,7],[6,8],[2,4],[3,5]。解题过程:1、将每一个区间按照左端点递增顺序排列完后为[1,4],[2,4],[2,6],[3,5],[3,6],[3,7],[...转载 2018-07-14 00:18:07 · 386 阅读 · 0 评论 -
贪心算法(圣诞老人的礼物)百练4110 MOOC
#include<iostream>#include<algorithm>using namespace std;const double eps=1e-6;struct candy{ int v,w; bool operator<(const candy&c) { return double(v)/w-double(c.v)/c.w>eps; }}c...转载 2018-07-14 13:25:45 · 1181 阅读 · 0 评论 -
动态规划01背包算法笔记
#include<iostream>#include<algorithm>using namespace std;int main(){ freopen("C:\\Users\\23535\\Desktop\\in.txt","r",stdin); //输入重定向,输入数据将从D盘根目录下的in.txt文件中读取 freopen("C:\\User...原创 2018-07-27 10:03:31 · 282 阅读 · 0 评论 -
进制转换,将A+B的和转为D进制
#include<iostream>using namespace std;int main(){ int a,b,d; cin>>a>>b>>d; int c; c=a+b; int z[1000],i=0; do { z[i++]=c%d; c=c/d;...原创 2018-07-30 10:25:41 · 493 阅读 · 0 评论 -
四则运算表达式求值
#include<iostream>#include<cstring>#include<cstdlib>using namespace std;int biaodashi();int xiang();int yinzi();int main(){ cout<<biaodashi()<<endl; system("pause"); retu...转载 2018-07-15 23:46:31 · 724 阅读 · 0 评论 -
用递归解决递归形式的问题
#include<iostream>#include<cstdio>using namespace std;double exp(){ char s[20]; cin>>s; switch(s[0]){ case '+': return exp()+exp(); case '-':return exp()-exp(); case '*':return exp()...转载 2018-07-15 21:41:54 · 359 阅读 · 0 评论 -
递归N皇后
#include<iostream>#include<cmath>using namespace std;int a[100];int n;void nqueen(int cnt){ if(cnt==n) { cout<<a[0]+1; for(int i=1;i<n;i++) { cout<<" "<<a[i]+1; ..原创 2018-07-15 20:28:22 · 141 阅读 · 0 评论