国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Pots——廣度優先搜索+結構體數組

2019-11-08 03:20:35
字體:
來源:轉載
供稿:網友

think: 1今天上午AC了自己的第三道英文題,感覺和英文題目的距離不再那么遙遠,而且自己在這個題目開始逐漸嘗試學習使用C++編程,雖然只是頭文件,但感覺自己不再那么畏懼,開始逐漸嘗試戰勝自己的畏懼,害怕難免會有,想起畢淑敏的一句話,你生而有翼,又何必匍匐前行,相信自己可以戰勝自己的消極情緒,做一個積極向上的人,自己曾經考慮過用大學時光來寫一本書,把自己的大學時光記錄下來,或許,自己應該燃起曾經想過的希望,寫一本自己的書,寫一本平凡人的自傳,或許我可以用這本書以記錄我的編程時光為主,日后想想現在的自己,正如現在的自己想想高中的那些努力的時光,那種感動猶如陽光灑在自己的身上,暖暖的 2回歸題目,題意是我們有兩個杯子A和B,需要盛C升水,有3種宏觀操作,共包含6種詳細操作, FILL:1>A歸0,B不變 2>A不變,B歸零 DROP:1>A盛滿,B不變 2>A不變,B盛滿 POUR:1>把A倒入B 2>把B倒入A 注:POUR操作需要注意會不會有一個杯子會有水剩余

sdut原題鏈接

Pots Time Limit: 1000MS Memory Limit: 65536KB

PRoblem Description You are given two pots, having the volume of A and B liters respectively. The following Operations can be performed: FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap; DROP(i) empty the pot i to the drain; POUR(i,j) pour from pot i to pot j; after this operation either the pot j is full (and there may be some water left in the pot i), or the pot i is empty (and all its contents have been moved to the pot j). Write a program to find the shortest possible sequence of these operations that will yield exactly C liters of water in one of the pots.

Input On the first and only line are the numbers A, B, and C. These are all integers in the range from 1 to 100 and C≤max(A,B).

Output The first line of the output must contain the length of the sequence of operations K. If the desired result can’t be achieved, the first and only line of the file must contain the Word ‘impossible’.

Example Input 3 5 4

Example Output 6

Hint FILL(2) POUR(2,1) DROP(1) POUR(2,1) FILL(2) POUR(2,1)

Author

以下為accepted代碼

#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;int a, b, c, tp, op;int vis[104][104];struct node{ int a; int b; int ans;}link[312];void FILL(int x, int y, int size, int l){ struct node f; if(l == 0) { f.a = a; f.b = y; } else if(l == 1) { f.a = x; f.b = b; } if(vis[f.a][f.b] == 0) { f.ans = size + 1; link[tp++] = f; vis[f.a][f.b] = 1; }}void DROP(int x, int y, int size, int l){ struct node f; if(l == 2) { f.a = 0; f.b = y; } else if(l == 3) { f.a = x; f.b = 0; } if(vis[f.a][f.b] == 0) { f.ans = size + 1; link[tp++] = f; vis[f.a][f.b] = 1; }}void POUR(int x, int y, int size, int l){ struct node f; if(l == 4)//a->b { if(x + y <= b) { f.a = 0; f.b = x + y; } else if(x + y > b) { f.a = x + y - b; f.b = b; } } else if(l == 5)//b->a { if(x + y <= a) { f.a = x + y; f.b = 0; } else if(x + y > a) { f.a = a; f.b = x + y -a; } } if(vis[f.a][f.b] == 0) { f.ans = size + 1; link[tp++] = f; vis[f.a][f.b] = 1; }}void BFS(){ struct node t, f; tp = op = 0; memset(vis, 0, sizeof(vis)); t.a = 0; t.b = 0; t.ans = 0; link[tp++] = t; vis[t.a][t.b] = 1; while(op < tp) { f = link[op++]; if(f.a == c ||f.b == c) { printf("%d/n", f.ans); return; } for(int i = 0; i < 6; i++) { if(i == 0) FILL(f.a, f.b, f.ans, i); if(i == 1) FILL(f.a, f.b, f.ans, i); if(i == 2) DROP(f.a, f.b, f.ans, i); if(i == 3) DROP(f.a, f.b, f.ans, i); if(i == 4) POUR(f.a, f.b, f.ans, i); if(i == 5) POUR(f.a, f.b, f.ans, i); } } printf("impossible/n");}int main(){ while(scanf("%d %d %d", &a, &b, &c) != EOF) { BFS(); } return 0;}/***************************************************User name: Result: AcceptedTake time: 0msTake Memory: 200KBSubmit time: 2017-02-17 11:44:12****************************************************/
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汤阴县| 大足县| 冀州市| 兴和县| 炉霍县| 阿克苏市| 陕西省| 北安市| 金坛市| 平顺县| 沾化县| 大新县| 额济纳旗| 广德县| 天台县| 廉江市| 洪湖市| 南开区| 渝北区| 石家庄市| 翁源县| 慈利县| 安平县| 桦南县| 东乡县| 绵阳市| 任丘市| 盖州市| 通江县| 靖边县| 城步| 田东县| 海门市| 江川县| 奉化市| 榆中县| 八宿县| 叶城县| 女性| 新乐市| 永康市|