上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页

动态规划 46例

摘要: 动态规划是一个重点 但是从来还没有系统的练习过,下面HDU上的46道DP题和其状态转移方程,等以后练习使用这是从百度文库下载的 不知道原作者。。。1.Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和… 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋);正确的方程是:f[j]=max(f[j],f[j-q[i].m 阅读全文
posted @ 2014-02-15 18:40 814jingqi的ACM 阅读(130) 评论(0) 推荐(0) 编辑

zoj 1037 Gridland

摘要: #include#includeusing namespace std;int main(){ int cas; cin>>cas; int n,m; int k=0; for(int i=0;i>n>>m; cout<<"Scenario #"<<i+1<<":"<<endl; if(n%2==0||m%2==0) printf("%d.00\n",m*n); else printf("%d.41\n",m*n); cout<&l 阅读全文
posted @ 2014-01-28 20:22 814jingqi的ACM 阅读(116) 评论(0) 推荐(0) 编辑

hdu 4772 Zhuge Liang's Password ,Regional 2013 杭州 C

摘要: 题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4772思路: 直接暴力 把四种角度全部列举出来,然后逐一看重合个数有多少代码:#include#includeusing namespace std;struct Matrix{ int a[30][30];};Matrix right_turn(Matrix x,int n){ Matrix ans; for(int i=0;i>n) { if(n==0) break; Matrix m[5]; for(int i=0;imax) { ... 阅读全文
posted @ 2013-11-13 02:33 814jingqi的ACM 阅读(121) 评论(0) 推荐(0) 编辑

hdu 3221 Brute-force Algorithm (09上海区域赛)欧拉定理

摘要: 题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3221思路 首先列出n比较小的一些,找到规律,指数就是fibonacci数列,也不难由函数递归的形式猜出。然后如果n#include#include#include#include#define N 1000000using namespace std;typedef long long inta;int fi[40];int prime[N+5];vector primev;int fi_mod[N+5];void pre(){ fi[0]=1; fi[1]=1; for(int ... 阅读全文
posted @ 2013-10-06 02:00 814jingqi的ACM 阅读(124) 评论(0) 推荐(0) 编辑

poj 1562 ,hdu 1241 Oil Deposits dfs,bfs 求连通分支数

摘要: 题目地址:http://poj.org/problem?id=1562 http://acm.hdu.edu.cn/showproblem.php?pid=1241直接遍历求连通分支数, dfs方法:#include#include#includeusing namespace std;int map[105][105];int vis[105][105];int n,m;void dfs(int x,int y){ //cout=0&&y=0&&!vis[x][y-1]&&map[x][y-1]) dfs(x,y-1); if(x-1>= 阅读全文
posted @ 2013-09-26 00:35 814jingqi的ACM 阅读(199) 评论(0) 推荐(0) 编辑

poj 3984 迷宫问题 dfs 求迷宫路径

摘要: 题目地址:http://poj.org/problem?id=3984利用图论中深搜的思想,存在边就是x,y -> x+1,y 还有x,y -> x,y+1 然后仍然是访问未访问的而且不是墙壁的地方。 这样保证不走已经搜索过,走不通的路。唯一一种需要重复访问已经访问的结点的情况是已经无路可走了,只能返回,这样就在栈中将路径取出来,把自己现在的那个先pop掉,然后实现回溯。最后用向量实现栈的自底输出。代码:IDUserProblemResultMemoryTimeLanguageCode LengthSubmit Time12143517814jingqi3984Accepted72 阅读全文
posted @ 2013-09-25 18:03 814jingqi的ACM 阅读(285) 评论(0) 推荐(0) 编辑

poj 1905 Expanding Rods 二分答案

摘要: 题目地址:http://poj.org/problem?id=1905思路:列出方程 2*R*x=L‘ 2*R*sin(x)=L 两式相除即得 x/sin(x) = 1+n*c 前提x!=0 就是 n*c>0 答案就是 L/2* (1/sin(x)-1/tan(x)) 三角函数化简为 L/2*tan(x/2) x 在0~ PI/2 于是关于x是单增的, 反函数也是单增的,x/sin(x) 也是单增的一开始的思路是先用 二分把x/sin(x) = 1+n*c 里面的x解出来,然后带进L/2*tan(x/2) 计算 虽然样例过了,但是还是wa... 阅读全文
posted @ 2013-09-25 15:15 814jingqi的ACM 阅读(129) 评论(0) 推荐(0) 编辑

poj 3122 Pie 二分答案

摘要: 题目地址:http://poj.org/problem?id=3122还是找到了单调函数--分给m人对最大尺寸f(m) 是m的不增函数,那么具体给定m是,二分f(m)使用>=f+1 l=mid 而不是>来保证尽可能取得大细节: 应该直接二分答案,而不是算出比较精确的半径平方,最后*PI输出,会产生误差,然后PI用arccos(-1),否则也会wa代码:#include#include#includeusing namespace std;//const double PI=3.1415926535; //这样写就wa了 是精度不够?const double PI=acos(-1.0 阅读全文
posted @ 2013-09-25 02:19 814jingqi的ACM 阅读(106) 评论(0) 推荐(0) 编辑

zoj 3366 Light Bulb 三分

摘要: 题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3366思路: 题目就是要求函数(h*D-H*x)/(D-x)+x 的最大值,其中 x>=0 x#includeusing namespace std;int main(){ int T; cin>>T; long double H,h,D; while(T--) { cin>>H>>h>>D; long double ans=D*H-D*h; ans=sqrt(ans); ans*=-2; ans... 阅读全文
posted @ 2013-09-24 23:43 814jingqi的ACM 阅读(95) 评论(0) 推荐(0) 编辑

LA 3644 X-Plosives (Europe - Southwestern - 2006/2007)

摘要: 题目地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1645思路: 图论模型化,种类数就是点,对数就是边, 要求始终不存在子图使点数等于边数,就是不允许有环,使用并查集即可。代码:#include#include#define N 100001using namespace std;int p[N+5];int find(int x){ return p[x]==x?x:p[x]=find(p[x]);}vo 阅读全文
posted @ 2013-09-24 21:43 814jingqi的ACM 阅读(140) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 17 下一页