1005 Jugs,1005jugs
辗转相减,新手入门题。两个容量的灌水题,无所谓最优解。
1 #include
2
3 intmain(){4 intA,B,T,sA,sB;5 while(scanf("%d %d %d",&A,&B,&T)>=0){6 sA=sB=0;7 while(1){8 if(sA==0){9 printf("fill A\n");10 sA=A;11 }12 else{13 printf("pour A B\n");14 sB+=sA;15 if(sB>=B){16 if(B!=T){17 printf("empty B\n");18 sA=sB-B;19 sB=0;20 }21 else
22 sB=B;23 }24 else
25 sA=0;26 }27 if(sB==T){28 printf("success\n");29 break;30 }31 }32 }33 return 0;34 }
一道DP经典题最好自创带标程
zju搜索dp题目总结收藏
|
搜索:
50道搜索题
1002 Fire Net -ok
1004 Anagrams by Stack -ok
1005 Jugs -ok
1008 Gnome Tetravex -ok but not ac
1091 Knight Moves -ok
1101 Gamblers -ok
1204 Additive equations
1221 Risk
1230 Legendary Pokemon
1249 Pushing Boxes
1364 Machine Schedule
1368 BOAT
1406 Jungle Roads ---ok
1411 Anniversary
1453 Surround the Trees 凸包
1516 Uncle Tom's Inherited Land ---ok
1525 Air Raid 算网络流问题可能更合适一点
1586 QS Network
1602 Multiplication Puzzle dp
1649 Rescue
1671 Walking Ant----ok
1711 Sum It Up dfs----ok
1901 A Star not a Tree? 说他搜索可能有点争议(不管了)
1940 Dungeon Master----ok
2100 Seeding ----ok
2110 Tempter of the Bone
2140 Ball
(27道)
上面的题可能比较简单,就当练练基本算法吧
===============================================================================
下面的题没有容易做的。
难题&经典
1003 Crashing Balloon
1015 Fishing Net 完美图
1144 Robbery
1149 Dividing up
1161 Gone Fishing
1197 Sorting Slides
1217 Eight
1228 Farewell, My Friend
1237 Fans and Gems
1455 Schedule Problem
1456 Minimum Transport Cost 图论 最短路径 要保存路径
1492 Maximum Clique 图论 经典算法--最大团
1600 Market Place
1605 One-way Traffic
1568 WishingBone's Room Plan
1742 Gap 至今一点想法都没有,难!!!
1743 Concert Hall Scheduling
1827 The Game of 31 博弈
1855 Maze
1903 Jogging Trails 中国邮路问题
1909 Square 经典的dfs.
2064 Bomberman - Just Search! 经典!
2094 Max Angle 计算几何+博弈
2125 Rocket Mania
2126 Rocket Mania Plus
2127 Zuma
2128 Seven Seas
2129 Mummy Maze
2142 Light The Square
(24道)
===========================================
dp
50道dp的题
1499 Increasing Sequenc......余下全文>>
C语言中的最佳分油方案程序设计
能不能把问题贴出来啊?
我做了一道ZOJ1005题,差不多吧
In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puzzle.
You have two jugs, A and B, and an infinite supply of water. There are three types of actions that you can use: (1) you can fill a jug, (2) you can empty a jug, and (3) you can pour from one jug to the other. Pouring from one jug to the other stops when the first jug is empty or the second jug is full, whichever comes first. For example, if A has 5 gallons and B has 6 gallons and a capacity of 8, then pouring from A to B leaves B full and 3 gallons in A.
A problem is given by a triple (Ca,Cb,N), where Ca and Cb are the capacities of the jugs A and B, respectively, and N is the goal. A solution is a sequence of steps that leaves exactly N gallons in jug B. The possible steps are
fill A
fill B
empty A
empty B
pour A B
pour B A
success
where "pour A B" means "pour the contents of jug A into jug B", and "success" means that the goal has been accomplished.
You may assume that the input you are given does have a solution.
Input
Input to your program consists of a series of input lines each defining one puzzle. Input for each puzzle is a single line of three positive integers: Ca, Cb, and N. Ca and Cb are the capacities of jugs A and B, an......余下全文>>
http://www.dengb.com/Cyy/889009.htmlwww.dengb.comtruehttp://www.dengb.com/Cyy/889009.htmlTechArticle1005 Jugs,1005jugs 辗转相减,新手入门题。两个容量的灌水题,无所谓最优解。 1 #includestdio.h 2 3 int main(){ 4 int A,B,T,sA,sB; 5 while (scanf( " %d %d...