USACO 6.3.3 Cowcycles dfs+剪枝
来源:互联网 发布:淘宝客服主管kpi考核 编辑:程序博客网 时间:2024/06/05 18:23
开始先搜索前齿轮的极值,然后搜索后齿轮的极值,这样就有条件算最大最小传动比率,然后筛选有效极值,最后再在最大值最小值之间做普通搜索,因为不符合要求的状态都被提前排除了(I.e.普通搜索中间不符合要求的状态没必要搜),总搜索次数也减小了。
做这题的收获是懂得了搜索时要尽量利用题目给出的条件进行优化,这题就是要缩小搜索区间。
代码:
{ID: ymwbegi1PROG: cowcycleLANG: PASCAL}var i,j,k,l,f,r,a1,b1,c1,f1,f2,r1,r2:longint; ans:real; c:array[0..400] of real; a,b,ansf,ansr:array[1..100] of longint;procedure sort;var i,j:longint;begin for i:=1 to c1-1 do for j:=i+1 to c1 do if c[i]>c[j] then begin c[0]:=c[i];c[i]:=c[j];c[j]:=c[0]; end;end;procedure dfs(x,y:longint);var i,j:longint; s,w:real;begin if (x=f)and(y=r) then begin c1:=0; for i:=1 to f do for j:=1 to r do begin inc(c1); c[c1]:=a[i]/b[j]; end; sort; s:=0; for i:=2 to c1 do s:=s+c[i]-c[i-1]; s:=s/(c1-1); w:=0; for i:=2 to c1 do w:=w+sqr(c[i]-c[i-1]-s); if w<ans then begin ans:=w; ansf:=a; ansr:=b; end; exit; end; if x<f then for i:=a[x-1]+1 to a[f]-1 do begin a[x]:=i; dfs(x+1,y); end else for i:=b[y-1]+1 to b[r]-1 do begin b[y]:=i; dfs(x,y+1); end;end;function min(x,y:longint):longint;begin if x<y then exit(x) else exit(y);end;begin assign(input,'cowcycle.in'); assign(output,'cowcycle.out'); reset(input); rewrite(output); readln(f,r); readln(f1,f2,r1,r2); ans:=maxlongint; for i:=f1 to f2-f+1 do for j:=i+f-1 to f2 do for k:=r1 to r2-r+1 do for l:=k+r-1 to r2 do if j*l>=3*i*k then begin a[1]:=i; a[f]:=j; b[1]:=k; b[r]:=l; dfs(min(f2-f1+1,2),min(r2-r1+1,2)); end; for i:=1 to f do if i>1 then write(' ',ansf[i]) else write(ansf[i]); writeln; for i:=1 to r do if i>1 then write(' ',ansr[i]) else write(ansr[i]); writeln; close(input); close(output);end.
0 0
- USACO 6.3.3 Cowcycles dfs+剪枝
- usaco 4.2 Cowcycles(搜索+剪枝)
- USACO 4.1 Cryptcowgraphy dfs+剪枝
- usaco 4.2 Cowcycles
- usaco 4.2.4 Cowcycles
- USACO Cowcycles 解题报告
- USACO Section 4.2 Cowcycles - 枚举~
- usaco 4.1 Cryptcowgraphy(DFS+hash+剪枝)
- USACO 1.5 Checker Challenge (DFS + 剪枝)
- hdoj--4277--USACO ORZ(dfs+剪枝)
- HDOJ 4277 USACO ORZ DFS+剪枝
- usaco shuttle puzzle(dfs剪枝)
- 洛谷 2210 [USACO] Haywire dfs+剪枝
- USACO 6.3 剪枝
- usaco training 4.2.4 Cowcycles 题解
- Cowcycles
- USACO Section 4.1 Cryptcowgraphy - BT的DFS剪枝..
- USACO 6.3.1 Fence Rails dfsid+剪枝
- ScrollView常用属性
- BZOJ3504危桥
- C语言学习笔记4-数据输入和输出
- Linux Input 子系统Event Interface详解
- Objective-C中数组(NSArray和NSMutableArray)常用用法
- USACO 6.3.3 Cowcycles dfs+剪枝
- Android逆向笔记(2)--- 破解第一个程序
- PS课件
- MVVM设计模式与MVC模式
- centos6.6下hadoop搭建live nodes为0解决方案
- 优化SQL语句一般的步骤
- 纯虚函数和抽象类
- mysql乐观锁总结和实践
- Linux系统引导相关练习题