随笔分类 -
HDU
HDU 2089
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2089基础的数位dp,当初不懂数位dp水过去的,今天重新写一下,解释看注释预处理+递推学自http://wenku.baidu.com/view/9de41d51168884868662d623.html#include using namespace std ;int f[8][10] ;//f[i][j]表示第i位是数j时符合条件的数字数量 int digit[9] ;//digit[i]表示n从右到左第i位是多少 void Init(){ f[0][0]=1 ; for(int i=1 ;...
阅读全文
HDU 2268
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2268小学四年级应用题,让我找回了儿时的快乐。。。#include #include #include using namespace std ;int main(){ int a,b,c ; while(~scanf("%d%d%d",&a,&b,&c)) { if(b<=a) { printf("%.3lf\n",c*1.0/a) ; continue ; } double x=c*1.0...
阅读全文
HDU 2273
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2273N辆车排队过马路,不能相撞,问最短时间ans=车的总长度/最小速度#include using namespace std ;int main(){ int n ; while(~scanf("%d",&n)) { int minn=10 ; int a,b ; int cnt=0 ; while(n--) { scanf("%d%d",&a,&b) ; cnt+=a ; ...
阅读全文
hdu 1098
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1098假设x=m时,65|f(m),即65|5*m^13+13*m^5+k*a*m计算f(m+1)=(5*m^13+13*m^5+k*a*m)+65*(m^12+6*m^11+22*m^10+55*m^9+99*m^8+132*m^7+132*m^6+99*m^5+56*m^4+24*m^3+8*m^2+2*m)+(18+k*a)式子的前两部分显然能被65整除,此时如果65|(18+k*a),那么65|f(m+1)。同时观察到f(1)=18+k*a,所以如果65|f(1),则65|f(m+1),此时对于所有x
阅读全文
hdu 4121
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4121中国象棋的简单模拟,给出黑方仅存的老帅坐标,再给出红方棋子坐标,问是否把黑方将死。输入数据有多余空格,所以要用cin,不能用scanf,这块错惨了#include using namespace std ;int abs(int x){ return x>0?x:-x ;}char map[11][11] ;int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}} ;int RGX,RGY ;int xx,yy ;int ok(int x,int y){ if(y!...
阅读全文
HDU 1238
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1238考察基本功的题目,把字符串按长度排序之后暴力即可0的情况需要特判,wa1次脑残没删注释,wa N次。。。#include using namespace std ;typedef struct L{ char s[101] ; int l ;}L ;L kk[101] ;int cmp(L a,L b){ return a.l=0 ;i--) { int idx=0 ; if(flag) break...
阅读全文
HDU 1033
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1033这题的题干说的很绕,结合样例不难理解题意,走折线,A代表顺时针,V代表逆时针,给一个包含A和V的字符串,输出走过的点。不难发现,不管是顺时针走还是逆时针走,x和y坐标的变化都是不一定的。而根据折线的特点我们知道单纯的向一个方向走的周期是4,沿着这个思路模拟出坐标变化就容易多了#include #include using namespace std ;char a[2001] ;int sx,sy ;int flag ;int len ;int main(){ while(~scanf("%s
阅读全文
HDU 2102
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2102中文题,开始以为要时间恰好,写个dfs超时,加个奇偶剪枝还超时,然后疯了问了sx,知道要小于等于那个时间就可以,当时吐血到了传送点必须传送有个trick是从'#'跳到'#'这种情况不能走#include #include using namespace std ;typedef struct L{ int x,y,f ; int step ;}L ;int n,m,t ;char map[2][11][11] ;int vis[2][11][11] ;int dir[4]
阅读全文
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
阅读全文
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
阅读全文
|
|