POJ 1951
摘要:把给定字符串翻译成目标字符串需要满足的条件是:1、开头不能有空格2、末尾不能有空格3、给定标点前不能有空格4、不能有A、E、I、O、U5、空格不能和空格相邻6、相同的字母只能出现1次给出一组测试数据('_'表示空格):input_I_AM_M._outputM.这道题是水题,但是我忽视了一点导致错误。形如"_I_AM_M._"这个输入。我开始的方法是从头扫空格,遇到字母就停下,这样I前的空格很容易就去掉了,但是像此种情况,I和A都是要去掉的字母,而I和A之间又有空格,这样的结果就是输出的M前会多一个空格,PE。避免这种错误的方法很简单,只要得要ans数组以后
阅读全文
HDU 1712 ACboy needs your help
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1712赤裸裸的分组背包View Code #include <iostream>using namespace std ;int dp[101] ;int val[101][101] ;int main(){ int n,m ; while(scanf("%d%d",&n,&m),(n||m)) { for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&val[i]
阅读全文
HDU 2159 FATE
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2159二维费用的背包wa了好多次,要求最大忍耐度,开始没处理好,想当然了View Code #include <iostream>using namespace std ;int dp[101][101] ;int w[101],c[101] ;int main(){ int n,m,k,s ; while(~scanf("%d%d%d%d",&n,&m,&k,&s)) { for(int i=0;i<k;i++) scanf("
阅读全文
HDU 3068 最长回文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3068新学的算法,求回文串用Manacher算法讲解:http://acm.uestc.edu.cn/bbs/simple/?t3258.htmlView Code #include using namespace...
阅读全文
HDU 1757 A Simple Math Problem
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1757还是矩阵+快速幂,注意要把初值乘回去并且注意方向View Code #include using namespace std ;void mul(int a[11][11],int b[11][11],int...
阅读全文
HDU 1575 Tr A
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1575矩阵+快速幂A^k是A*A*A...(k个A相乘)View Code #include using namespace std ;void mul(int a[11][11],int b[11][11],in...
阅读全文
HDU 2065 "红色病毒"问题
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2065dp转移方程:dp[i][1]=2*dp[i-1][1]+dp[i-1][2]+dp[i-1][3];dp[i][2]=dp[i-1][1]+2*dp[i-1][2]+dp[i-1][4];dp[i][3]=...
阅读全文
HDU 1005 Number Sequence
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1005神奇的矩阵View Code #include <iostream>using namespace std ;void mul(int a[2][2],int b[2][2]){ int c[2][2] ; c[0][0]=(a[0][0]*b[0][0]+a[0][1]*b[1][0])%7 ; c[0][1]=(a[0][0]*b[0][1]+a[0][1]*b[1][1])%7 ; c[1][0]=(a[1][0]*b[0][0]+a[1][1]*b[1][0])%7 ; ...
阅读全文
HDU 4339 Query
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4339血与泪,伤与痛,无须多言线段树找数列中任意起点最多有多少连续的1View Code #include <iostream>#include <string.h>using namespace std ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=1000001 ;char s1[maxn],s2[maxn] ;int tree[maxn<<2] ;int n ;v
阅读全文
POJ 1269 Intersecting Lines
摘要:http://poj.org/problem?id=1269两条直线,平行输出NONE,共线输出LINE,相交输出交点坐标p0为交点,求交点坐标的方法是(p1-p0)X(p2-p0)=0 && (p3-p0)X(p4-p0)=0(其中X代表向量叉乘),联立两个方程可求解求得解分母为0时,判断一条直线中的一个点是否在另一条直线上(用上面叉乘的方法),如果是就共线,反之平行View Code #include <iostream>#include <stdio.h>using namespace std ;struct point{ int x,y ;} ;
阅读全文
HDU 2199 Can you solve this equation?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2199找到方程的解,直接二分,注意精度View Code #include <iostream>using namespace std ;const double eps=1e-8 ;double f(double x){ return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6 ;}int main(){ int t ; double mid ; scanf("%d",&t) ; while(t--) { double y ; ...
阅读全文
HDU 3333 Turing Tree
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3333离线算法,和上一题一模一样。。。View Code #include <iostream>#include <algorithm>#include <map>using namespace std ;const int maxn=30001 ;typedef __int64 LL ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1map <int,int> hash ;struct n
阅读全文
HDU 3874 Necklace
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3874今天和涂涂新学的离线算法,太牛了大概就是先接收所有数据,然后按查询右边界排序,从左往右更新,遇到之前加过的数就删掉,因为按右边界排序,所以查询区间不断右移,删掉不会出错View Code #include #...
阅读全文
HDU 2686 Matrix
摘要:http://acm.bjtu.edu.cn/vjudge/problem/viewProblem.action?id=1815经典的双线程dp,dp[i][x1][y1][x2][y2]表示走i步在(x1,y1),(x2,y2)两点处取得的和的最大值,假设矩阵从0-n-1,有i=x+y,五维转化成三维。代码中用了滚动数组,不过在这里意义不大View Code #include <iostream>using namespace std ;int map[31][31],dp[3][31][31] ;int MAX(int a,int b,int c,int d){ a=max(a
阅读全文
HDU 1520 Anniversary party
摘要:http://acm.bjtu.edu.cn/vjudge/problem/viewProblem.action?id=669最最基础的树形dp,父子兄弟结构太爽了,学自hh博客View Code #include <iostream>using namespace std ;struct Tree{ int father ; int child ; int brother ; int happy ; int temp ; int MAX(){ return max(happy,temp) ; } void init(){ ...
阅读全文
HDU 1114 Piggy-Bank
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1114完全背包,求最小值View Code #include <iostream>using namespace std ;int V ;int dp[1000001] ;const int INF=0xfffffff ;void CompletePack(int c,int w){ for(int i=c;i<=V;i++) dp[i]=min(dp[i],dp[i-c]+w) ; return ;}int c[50001],w[50001] ;int main(){ in...
阅读全文
HDU 2844 Coins
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2844求的是能买多少种价钱的物品,多重背包教主很经典的男人八题之一。。。不过据说原题要用单调队列优化,这个二进制优化就过了。。。View Code #include <iostream>using namespace std ;int V ;int dp[100001] ;void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c]+w) ; return ;}void CompletePac...
阅读全文
HDU 1059 Dividing
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1059基础的二进制优化的多重背包View Code #include <iostream>using namespace std ;int V ;int dp[200001] ;void ZeroOnePack(int c,int w){ for(int i=V;i>=c;i--) dp[i]=max(dp[i],dp[i-c]+w) ; return ;}void CompletePack(int c,int w){ for(int i=c;i<=V;i++) ...
阅读全文
HDU 1702 ACboy needs your help again!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1702G++交,基本stl栈和队列操作View Code #include <iostream>#include <stack>#include <queue>using namespace std ;int main(){ int t ; scanf("%d",&t) ; while(t--) { int n,m ; string str ; cin >> n >> str ; if(str=="FIFO&qu
阅读全文
HDU 4314 Save the dwarfs
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4314dp,dp[i][j]表示i个小矮人能逃出去j个时需要之前井中剩下的人的最小a高度之和转移方程dp[i][j]=min(dp[i-1][j]-kk[i-1].a,max(dp[i-1][j-1],h-sumA[i-1]-kk[i-1].b))最神的是解题报告直接把a+b排了个序(a+b最小的先逃脱),这个自己没看出来。。。View Code #include <iostream>#include <algorithm>using namespace std ;const int
阅读全文
|
|