ACM算法题
文章平均质量分 65
OuterST
海滨学院
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
递归和动态规划的区别
递归:自上至下,把大问题分解成小问题解决。动态规划:自下至上,通过解决小问题,集合为解决大问题。用递归能解决的问题,一般都可以用动态规划来解决。区别:递归: 缺点:会重复计算相同的问题,相当耗时。 优点:不会记录每个问题的结果,所以内存消耗相对小。动态规划:缺点:会记录每一个问题的结果,内存消耗较大。 优点:不会计算相同问题,时间消耗较小。...原创 2020-06-04 19:05:13 · 3227 阅读 · 0 评论 -
hdu 2076
【水题】【数学】题目链接纯数学题。。 秒会影响分,分影响小时#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main(){ int n; int h,m,s; double ans,m1,m2; scanf("%d",&...原创 2013-08-14 13:26:58 · 974 阅读 · 0 评论 -
hdu 2080
题目链接纯数学题,很多种解法,我用了两种解法根据x表示与x轴的夹角,tanx=y/x;#include #include #include #include using namespace std;#define PI 3.141592653int main(){ double x1,y1,x2,y2,a1,a2,a3; int n;原创 2013-08-15 17:41:48 · 1009 阅读 · 0 评论 -
hdu 2087
题目链接STL+KMP#include #include using namespace std;int main(){ int i,len,sum; char *p; char a[3005],b[3005]; while(scanf("%s",a)&&a[0]!='#') { scanf("%s",b);原创 2013-08-16 08:21:54 · 1166 阅读 · 0 评论 -
hdu 2093
题目链接 三级结构体排序,文件结束怎么是这个样子啊 #include #include #include using namespace std;struct P{ char name[15]; int tm; int sj;}p[1005];int n,m;int cmp(const void *a,const voi原创 2013-08-16 15:47:12 · 901 阅读 · 0 评论 -
hdu 2094
题目链接这题目数据比较水,反EG:a b,b c,d e,e f,f e,这题用并查集吧,我还不会呢#include #include #include #include #include using namespace std;int main(){ int i,j,n,num,k,d[1005]; char s[15],s1[15];原创 2013-08-16 17:39:49 · 1017 阅读 · 0 评论 -
hdu 4737
题目链接 直接暴力,或运算只会越来越大 #include #include using namespace std;#define N 100005int a[N];int main(){ int n,m,cas,i,j,num,v; scanf("%d",&cas); v=1; while(cas--) {原创 2013-09-15 23:23:28 · 1015 阅读 · 0 评论 -
ZOJ 2013 ACM/ICPC Asia Regional Changsha Online E Travel by Bike
题目链接 这道题WA出翔了。。一开始没有考虑取余为0时的情况,到今天才知道是double eps的问题,精度的问题 #include #include #include using namespace std;#define eps 0.000001char str[7][15]={"Monday", "Tuesday", "Wednesday", "Thurs原创 2013-09-26 21:04:44 · 895 阅读 · 0 评论 -
hdu 2688
题目链接开始学习树状数组和线段树题意:R表示k1--k2依次向左循环1位 Q:查询多少升序序列#include <cstdio>#include <cstring>using namespace std;#define maxn 3000005int arr[10005],a[maxn];int lowbit(int x) //判断最右边1的位置{ r...原创 2013-08-17 09:12:57 · 1141 阅读 · 0 评论 -
poj 2182||hdu 2711
题目链接树状数组+二分poj2182 AC hdu2711 WA 有时间在研究吧#include <cstdio>#include <cstring>using namespace std;#define maxn 8005int arr[maxn],a[maxn],s[maxn];int lowbit(int x){ return x&(-x...原创 2013-08-17 23:08:35 · 1043 阅读 · 0 评论 -
POJ 2481
题目链接树状数组 If Si <= Sj and Ej <= Ei and Ei - Si > Ej - Sj,cowi is stronger than cowj.查询比i大的数目按E从大到小排序,再按S从小到大排序,当i>j时,满足Si>=Sj,就满足 Ei - Si <Ej - Sj,cowj is stronger than cowi. #include...原创 2013-08-23 11:59:18 · 972 阅读 · 0 评论 -
poj 2155
题目链接二维树状数组给出矩阵左上角和右下角坐标,矩阵里的元素 1变0 ,0 变1,然后给出询问,问某个点是多少。树状数组下标不能为0二维的每次更新都是从(1,1)到(x,y)要更新(x1,y1)到(x2,y2)的update(x2,y2);update(x2,y1-1);update(x1-1,y2);update(x1-1,y1-1);sum%2==1 时为1。 #include <cst...原创 2013-08-23 17:27:21 · 789 阅读 · 0 评论 -
poj 1990
题目链接借鉴cxlove大神的思路题意:听力v,位置x,2个牛交流声音为max(v1,v2)*(x1-x2),求总的10000^2 tle 用的树状数组做的,排序,2个,小于vi的牛的总数和距离总和 #include <cstdio>#include <cstring>#include <algorithm>using namespace std;#de...原创 2013-08-18 20:53:51 · 835 阅读 · 0 评论 -
POJ 3378
题目链接查找长度为5的上升序列总数用的树状数组+高精度用树状数组求在i前面比i小的数有几个用的4个树状数组,A[i][j]表示长度为i的以j为结尾的个数,A[i][j]=A[i-1][1....flag[n]]对数组下标不能为0一直不太理解,会发生死循环#include <cstdio>#include <iostream>#include <algorithm&...原创 2013-08-24 07:37:56 · 1092 阅读 · 0 评论 -
poj 3321
题目链接题意:一开始1-n都有苹果,Q查询以x为根下存在多少。树状数组+DFS+队列转换这题纠结了2天,一开始一点思路都没有,看大神都是吧树状数组转换成队列来做看了好久都不知道怎么转换的,解决方法:用两个队列,一个是以记录(s,u),s为起点,一个记录s,为终点用DFS查找一棵分支,记录访问次序,这样就可以转换成树状数组了 #include <cstdio> //参照大神的代码#in...原创 2013-08-25 16:37:31 · 951 阅读 · 0 评论 -
hdu 4267
题目链接为了这题学习了树状数组三维树状数组(i-a)%k==0等价于i%k==a%k,所以可以把不同位置按取K的模放到一组里ar[x][k][mod]表示在x位置k=k时,余数为mod的值,求一个位置的值,只要遍历与v%i相等的数的和就行了 #include <cstdio>#include <cstring>#include <algorithm>us...原创 2013-09-04 16:54:14 · 913 阅读 · 0 评论 -
hdu 4740
题目链接 老虎左拐,老鼠右拐,碰到不能走的拐一次,如果还不能走就停下,自己走过的不能走,求相遇的坐标或-1 一个停下之后,另一个还可以走#include #include using namespace std;#define N 1005struct node{ int x,y;}p[N*N],q[N*N];int visi[N][N],原创 2013-09-20 20:53:35 · 1032 阅读 · 0 评论 -
hdu 2077
题目链接盘子分为A,B,C汉诺塔III的公式:f[n]=f[n-1]*3+2=3^n-1 另g(n)=3^n-1,表示n个盘子从A到C按照III的规律执行的次数按IV的规律,最优的情况是n-2个盘子先按III的规律到C,n-1,n依次到B,n-2个再到A,n-1,n到C,n-2再到Cf1[n]=g(n-2)*3+4=3^n+1=f[n-1]*3-2;#include原创 2013-08-15 08:35:05 · 1389 阅读 · 0 评论 -
hdu 3535 分组背包+混合背包
/* 题意:n组数据,容积为v,temp为种类,0类至少选一个,1类至多选一个,2自由选择,求最大价值分组混合背包,分别确定每一组的状态,种类0和2时,状态转移方程相同,只是初始化不同,*/#include #include #include using namespace std;#define INF -999999int dp[105][105];int main(){原创 2014-04-07 22:00:18 · 929 阅读 · 0 评论 -
ACM 计划
初期:一.基本算法:(1)枚举. (poj1753,poj2965)(2)贪心(poj1328,poj2109,poj2586)(3)递归和分治法.(4)递推.(5)构造法.(poj3295)(6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:(1)图的深度优先遍历和广度优先遍历.(转载 2013-08-14 19:34:29 · 1646 阅读 · 0 评论 -
ios 8 地图定位
在xcode6中 苹果地图得定位方法修改了,以前得不能用了报错说明:Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationMa原创 2014-10-10 11:41:30 · 1776 阅读 · 2 评论 -
srm 144 div 2 550
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using nam原创 2013-07-15 17:14:03 · 810 阅读 · 0 评论 -
poj 1656
题目链接改变矩形内颜色#include //二维树状数组#include using namespace std;#define maxn 200int flag[maxn][maxn],col[maxn][maxn];int lowbit(int x){ return x&-x;}void update(int x,int y,int n){ if(f原创 2013-08-18 10:05:08 · 924 阅读 · 0 评论 -
poj 3461
//poj 3461 kmp //1420 KB 125 ms G++#include #include using namespace std;int next[10005],len1,len2;char s[1000005],mod[10005]; //s是主串,mod是模式串int getnext() //求next数组,next数组用来当匹配不相同时,不必返回原创 2014-03-19 22:51:24 · 704 阅读 · 0 评论 -
POJ 2185 KMP (最小循环模块)
/*题意:求最小循环模块的面积必然存在一个最小循环模块的起点为(0,0),对于每一行,对每一个循环串的长度做记录,满足所有行条件的最短长度即为宽b对于长度,颗粒利用strcmp把每一行的字符串看成一个字符,然后进行KMP就可以得到长度*/#include #include #include using namespace std;char s[10005][105];int原创 2014-04-07 14:16:24 · 977 阅读 · 0 评论 -
hdu 1114
/* 完全背包变型题意:存钱罐 重W1 满重w2,给你价值为cost,重量为weight的硬币,求存钱罐中w2时cost最小值*/#include #include using namespace std;#define INF 0x3fffff#define MIN(a,b) (a)<(b)?a:bint dp[10005],sum,cost,weight;i原创 2014-03-30 22:08:57 · 796 阅读 · 0 评论 -
hdu 1494
// hdu 1494 B - 跑跑卡丁车 // Memory 748 KB Time 31 ms G++// DP 01背包//处理好每一个状态#include #include using namespace std;#define MIN(a,b) (a)<(b)?a:b //a,b字符要带括号#define INF 0xFFFFFFF //这里要取到无穷原创 2014-03-19 22:47:31 · 1050 阅读 · 0 评论 -
hdu 1059 dp再现
/* 好久没做DP了,,背包都忘了。。菜 背包01和完全背包 就是循环顺序相反的 背包01:逆序,表示dp[i]替换的是上一状态的完全背包:正序,替换的是当前状态的多重背包:如果某一件物品cost*count>sum,可以把他看成一个完全背包,反之看成01背包,01背包不可以用二进制优化题意:6件物品,第i件物品价值为i,输入第i件物品的数量,求总价值是不是可以平分,1个物品不能原创 2014-03-30 22:02:18 · 880 阅读 · 0 评论 -
hdu 2546
/* 01背包变型 一开始想的是n<=1000,价格最大为50 所以开了50005的数组结果发现余额最大1000,所以数组不必开那么大用5元取一个最大价值的,明显最优,所以先用5元减去一个最大值,就变成了01背包所以最后输出的时候后 dp[cost-5]和减去一个max*/#include #include #include using namespace std原创 2014-03-31 11:09:54 · 908 阅读 · 0 评论 -
hdu 1712
/* 分组背包 怎么感觉没做过分组背包似的,遇到矩阵,读个题意弄半天 n门课程,m天,a[i][j]表示第i门课程,复习j天获得的价值,求在m天最大的价值*/#include #include using namespace std;#define MAX(a,b) (a)>(b)?(a):(b)int dp[105],a[105][105];int main原创 2014-03-31 16:01:56 · 828 阅读 · 0 评论 -
POJ 1088 DP
//经典DP题 一个点一个点的进行搜索#include#includeusing namespace std;#define MAX(a,b) (a)>(b)?(a):(b)int n,m;int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1};int opt[105][105],a[105][105];bool ok(int i,int j){原创 2014-04-04 16:37:59 · 853 阅读 · 0 评论 -
poj 1157 dp
/* 题意:n朵花插到m个瓶子中,花必须全插,第i朵花插到第j个瓶子的价值为value[i][j],求价值的最大值 dp[i][j]表示当第i朵花插到第j个瓶子是的价值最大值,k表示i-1可以放的位置, 动态转移方程:dp[i][j]=MAX(dp[i][j],dp[i-1][k]+value[i][j]);*/#include#include#includeusing原创 2014-04-06 10:38:17 · 893 阅读 · 0 评论 -
hdu 3033 分组背包
/* 看到监狱兔 想起了朱晓凤,以前课间都是给我们放监狱兔看的,记忆犹新啊,不过后来老师走了。。。题意:拥有金钱:m,鞋子分t种样式,每种样式必选一种,输出在<=m时的最大价值。每组数据:样式sim,花费cost,获得价值:weight分组背包dp[i][k]=max(dp[i][k],max(dp[i][k-cost[j]]+weight[j],dp[i-1][k-cost[j]]+we原创 2014-04-06 22:15:29 · 905 阅读 · 0 评论 -
hdu 4268
题目链接先按h从小到大排序,查找离w最近的值,删除他 #include <cstdio>#include <cstring>#include <set>#include <algorithm>using namespace std;#define N 100010multiset<int> myset;multiset<...原创 2013-09-05 18:11:42 · 874 阅读 · 0 评论 -
hdu 4277
题目链接 #include <cstdio> //by-ACMer_xiaohao#include <cstring>#include <map>using namespace std;#define N 50005 //不知道数组为什么开这么大map<int,bool> mp[N];int sum,n,ma[20],ans;void ...原创 2013-09-06 16:28:09 · 762 阅读 · 0 评论 -
poj 1321
链接dfs,由于两处小小的错误,导致浪费好多时间按行搜索,然后在把依搜索的列标记一下 #include <cstdio>#include <cstring>using namespace std;bool visi[100];bool flag[100][100];int ans,cnt,n,k;void dfs(int a){ if(cnt==k) ...原创 2013-09-10 17:56:28 · 787 阅读 · 0 评论 -
HDU 1035
【模拟与枚举】A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions areN north (up th...原创 2012-11-13 09:14:08 · 520 阅读 · 0 评论 -
HDU 1212
【模拟与枚举】As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B.To make the problem easier, I promise that B ...原创 2012-11-12 08:01:18 · 621 阅读 · 0 评论 -
hdu 1034
【模拟与枚举】A number of students sit in a circle facing their teacher in the center. Each student initially has an even number of pieces of candy. When the teacher blows a whistle, each student simultaneou...原创 2012-11-11 07:43:21 · 936 阅读 · 0 评论 -
HDU 1033
【模拟与枚举】#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>int main(){ int a,b,i,m; char c[1005]; while(scanf("%s",&c)!=EOF) { ...原创 2012-11-08 21:16:39 · 636 阅读 · 0 评论
分享