日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > > 充電吧
[導(dǎo)讀]題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5433 題面: Xiao Ming climbing Time Limit: 2000/1000

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5433


題面:

Xiao Ming climbing Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 404????Accepted Submission(s): 93


Problem Description Due to the curse made by the devil,Xiao Ming is stranded on a mountain and can hardly escape.

This mountain is pretty strange that its underside is a rectangle which size is?n?m?and every little part has a special coordinate(x,y)and a height?H.

In order to escape from this mountain,Ming needs to find out the devil and beat it to clean up the curse.

At the biginning Xiao Ming has a fighting will?k,if it turned to?0?Xiao Ming won't be able to fight with the devil,that means failure.

Ming can go to next position(N,E,S,W)from his current position that time every step,(abs(H1?H2))/k?'s physical power is spent,and then it cost?1?point of will.

Because of the devil's strong,Ming has to find a way cost least physical power to defeat the devil.

Can you help Xiao Ming to calculate the least physical power he need to consume. ?
Input The first line of the input is a single integer?T(T≤10), indicating the number of testcases.?

Then?T?testcases follow.

The first line contains three integers?n,m,k?,meaning as in the title(1≤n,m≤50,0≤k≤50).

Then the?N?×?M?matrix follows.

In matrix , the integer?H?meaning the height of?(i,j),and '#' meaning barrier (Xiao Ming can't come to this) .

Then follow two lines,meaning Xiao Ming's coordinate(x1,y1)?and the devil's coordinate(x2,y2),coordinates is not a barrier. ?
Output For each testcase print a line ,if Xiao Ming can beat devil print the least physical power he need to consume,or output "NoAnswer" otherwise.

(The result should be rounded to 2 decimal places) ?
Sample Input
3
4 4 5
2134
2#23
2#22
2221
1 1
3 3
4 4 7
2134
2#23
2#22
2221
1 1
3 3
4 4 50
2#34
2#23
2#22
2#21
1 1
3 3


?

Sample Output
1.03
0.00
No Answer


題目大意:

? ? 給定起點和終點。有一個意念值k,其實就是可以走k步。每走一步都會產(chǎn)生體力消耗abs(a1-a2)/x,a1,a2分別為兩個位置的高度,x為當(dāng)前剩余意念值。求在限定步數(shù)內(nèi),從起點到終點到的最小體力消耗。


解題:

? ? 之前的代碼是錯誤的,多謝一抹憂傷|指出。深搜理論上不是不可以,但是還需要加一維代表步數(shù),復(fù)雜度可能會挺高。故正解是,步數(shù)少,且代價低的優(yōu)先隊列配合BFS。


坑點:

? ? 當(dāng)k=0的時候,不管起點和終點是否重合,要直接輸出No Answer,好像題面有提及,意念值為0,就意味著失敗。


錯誤代碼:


錯誤原因:

? ? 并不是新到達(dá)一點時,代價低,就更新該點,可能存在代價低,步數(shù)多不能到達(dá)的情況,而代價高,步數(shù)少,卻能到達(dá)。

#include
using namespace std;
char map[55][55];
double dp[55][55];
int n,m,k,t,sx,sy,dx,dy,dir[4][2]={-1,0,0,1,1,0,0,-1};
bool flag;
void dfs(int x,int y,int step,double cost)
{
    int tx,ty;
    double tcost;
    if(cost>=dp[x][y])return;
    else
    {
        dp[x][y]=cost;
        if(x==dx&&y==dy)
        {
            flag=true;
            return;
        }
        if(step==0)return;
        for(int i=0;i<4;i++)
        {
            tx=x+dir[i][0];
            ty=y+dir[i][1];
            if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&map[tx][ty]!='#')
            {
                tcost=cost+1.0*abs(map[x][y]-map[tx][ty])/step;
                dfs(tx,ty,step-1,tcost);
            }
        }        
    }
}
void init()
{
    flag=false;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            dp[i][j]=1e9;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1;i<=n;i++)
        {
            getchar();
            for(int j=1;j<=m;j++)
              scanf("%c",&map[i][j]);
        }
        scanf("%d%d%d%d",&sx,&sy,&dx,&dy);
        if(k==0)
		{
			printf("No Answern");
			continue;
		} 
        init();
        dfs(sx,sy,k,0.0);
        if(flag)
        {
            printf("%.2lfn",dp[dx][dy]);
        }
        else
          printf("No Answern");
    }
    return 0;
} 


修改代碼:

#include 
#include 
using namespace std;
char map[55][55];
double dp[55][55][55];
int n,m,k,t,sx,sy,dx,dy,dir[4][2]={-1,0,0,1,1,0,0,-1};
bool flag;
struct node
{
	int x,y,step;
	double cost;
	bool operator<(const node &a)const
	{
       if(step!=a.step)
		   return step>a.step;
	   else
		   return cost>a.cost;
	}
};
priority_queue  qe;
void bfs()
{
   while(!qe.empty())
      qe.pop();
   int tx,ty,tstep;
   node tmp,cur;
   tmp.x=sx,tmp.y=sy,tmp.cost=0.0,tmp.step=0;
   qe.push(tmp);
   while(!qe.empty())
   {
	   cur=qe.top();
	   qe.pop();
	   if(cur.cost>=dp[cur.x][cur.y][cur.step])
		   continue;
	   else
	   {
		   dp[cur.x][cur.y][cur.step]=cur.cost;
		   if(cur.x==dx&&cur.y==dy)
		   {
			   flag=true;
			   continue;
		   }
		   if(cur.step==k)
			   continue;
	   for(int i=0;i<4;i++)
	   {
		   tx=cur.x+dir[i][0];
		   ty=cur.y+dir[i][1];
		   if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&map[tx][ty]!='#')
		   {
              tmp.x=tx,tmp.y=ty,tmp.step=cur.step+1;
			  tmp.cost=cur.cost+(1.0*abs(map[cur.x][cur.y]-map[tx][ty])/(k-cur.step));
			  qe.push(tmp);
		   }
	   }
	  }
   }
}
void init()
{
    flag=false;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
			for(int x=0;x<=k;x++)
            dp[i][j][x]=1e9;
}
int main()
{
	double ans;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1;i<=n;i++)
        {
            getchar();
            for(int j=1;j<=m;j++)
              scanf("%c",&map[i][j]);
        }
        scanf("%d%d%d%d",&sx,&sy,&dx,&dy);
        if(k==0)
		{
			printf("No Answern");
			continue;
		} 
        init();
        bfs();
        if(flag)
        {
       	   ans=dp[dx][dy][0];
           for(int i=1;i<=k;i++)
		   {
   			  if(dp[dx][dy][i]


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

LED驅(qū)動電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: 驅(qū)動電源

在工業(yè)自動化蓬勃發(fā)展的當(dāng)下,工業(yè)電機(jī)作為核心動力設(shè)備,其驅(qū)動電源的性能直接關(guān)系到整個系統(tǒng)的穩(wěn)定性和可靠性。其中,反電動勢抑制與過流保護(hù)是驅(qū)動電源設(shè)計中至關(guān)重要的兩個環(huán)節(jié),集成化方案的設(shè)計成為提升電機(jī)驅(qū)動性能的關(guān)鍵。

關(guān)鍵字: 工業(yè)電機(jī) 驅(qū)動電源

LED 驅(qū)動電源作為 LED 照明系統(tǒng)的 “心臟”,其穩(wěn)定性直接決定了整個照明設(shè)備的使用壽命。然而,在實際應(yīng)用中,LED 驅(qū)動電源易損壞的問題卻十分常見,不僅增加了維護(hù)成本,還影響了用戶體驗。要解決這一問題,需從設(shè)計、生...

關(guān)鍵字: 驅(qū)動電源 照明系統(tǒng) 散熱

根據(jù)LED驅(qū)動電源的公式,電感內(nèi)電流波動大小和電感值成反比,輸出紋波和輸出電容值成反比。所以加大電感值和輸出電容值可以減小紋波。

關(guān)鍵字: LED 設(shè)計 驅(qū)動電源

電動汽車(EV)作為新能源汽車的重要代表,正逐漸成為全球汽車產(chǎn)業(yè)的重要發(fā)展方向。電動汽車的核心技術(shù)之一是電機(jī)驅(qū)動控制系統(tǒng),而絕緣柵雙極型晶體管(IGBT)作為電機(jī)驅(qū)動系統(tǒng)中的關(guān)鍵元件,其性能直接影響到電動汽車的動力性能和...

關(guān)鍵字: 電動汽車 新能源 驅(qū)動電源

在現(xiàn)代城市建設(shè)中,街道及停車場照明作為基礎(chǔ)設(shè)施的重要組成部分,其質(zhì)量和效率直接關(guān)系到城市的公共安全、居民生活質(zhì)量和能源利用效率。隨著科技的進(jìn)步,高亮度白光發(fā)光二極管(LED)因其獨特的優(yōu)勢逐漸取代傳統(tǒng)光源,成為大功率區(qū)域...

關(guān)鍵字: 發(fā)光二極管 驅(qū)動電源 LED

LED通用照明設(shè)計工程師會遇到許多挑戰(zhàn),如功率密度、功率因數(shù)校正(PFC)、空間受限和可靠性等。

關(guān)鍵字: LED 驅(qū)動電源 功率因數(shù)校正

在LED照明技術(shù)日益普及的今天,LED驅(qū)動電源的電磁干擾(EMI)問題成為了一個不可忽視的挑戰(zhàn)。電磁干擾不僅會影響LED燈具的正常工作,還可能對周圍電子設(shè)備造成不利影響,甚至引發(fā)系統(tǒng)故障。因此,采取有效的硬件措施來解決L...

關(guān)鍵字: LED照明技術(shù) 電磁干擾 驅(qū)動電源

開關(guān)電源具有效率高的特性,而且開關(guān)電源的變壓器體積比串聯(lián)穩(wěn)壓型電源的要小得多,電源電路比較整潔,整機(jī)重量也有所下降,所以,現(xiàn)在的LED驅(qū)動電源

關(guān)鍵字: LED 驅(qū)動電源 開關(guān)電源

LED驅(qū)動電源是把電源供應(yīng)轉(zhuǎn)換為特定的電壓電流以驅(qū)動LED發(fā)光的電壓轉(zhuǎn)換器,通常情況下:LED驅(qū)動電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: LED 隧道燈 驅(qū)動電源
關(guān)閉