1 条题解

  • 0
    @ 2025-4-7 21:38:07

    C++ :

    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    using namespace std;
    int hst[21][21];
    int max_x,max_y;
    int c_x,c_y;
    int time=0;
    int cdd=0;
    int main()
    {
    	int m,n,k;
    	scanf("%d%d%d",&m,&n,&k);
    	for(int i=1;i<=m;i++)
    	{
    		for(int j=1;j<=n;j++)
    		{
    			scanf("%d",&hst[i][j]);
    		}
    	}
    	for(int c=1;c<=1000;c++)
    	{
    		//find
    		int max=0;
    		for(int i=1;i<=m;i++)
    		{
    			for(int j=1;j<=n;j++)
    			{
    				if(hst[i][j]>max)
    				{
    					max=hst[i][j];
    					max_x=i;
    					max_y=j;
    					//hst[i][j]=0;
    				}
    			}
    		}
    		//l
    		if(c==1)
    		{
    			c_x=0;
    			c_y=max_y;
    		}
    		if(time+abs(max_x-c_x)+abs(max_y-c_y)+max_x>=k)
    		{
    			break;
    		}
    		else
    		{
    			time+=abs(max_x-c_x)+abs(max_y-c_y);
    			cdd+=hst[max_x][max_y];
    			hst[max_x][max_y]=0;
    			c_x=max_x;
    			c_y=max_y;
    			time++;
    		}
    	}
    	printf("%d",cdd);
    	//system("pause");
    	return 0;
    }
    
    

    Pascal :

    type mytype=record
    x,y,d:integer;
    end;
    var time,all,num,i,j,m,n,k,u,v,z:integer;
    q:array[1..400] of mytype;
    t:mytype;
    begin
    all:=0;
    {assign(input,'peanuts.in');
    reset(input); }
    readln(m,n,k);
    for i:=1 to m do
    begin
    for j:=1 to n do
    begin
    read(u);
    if u>0 then
    begin
    inc(all);
    q[all].x:=i;q[all].y:=j;q[all].d:=u;
    if all>1 then
    begin
    v:=1;
    while q[v].d>u do inc(v);
    t:=q[all];
    for z:=all downto v+1 do q[z]:=q[z-1];
    q[v]:=t;
    end;
    end;
    end;
    readln;
    end;
    //close(input);
    num:=0;time:=0;u:=0;v:=q[1].y;
    for i:=1 to all do
    begin
    if time+abs(q[ i ].x-u)+abs(q[ i ].y-v)+1+q[ i ].x<=k
    then begin
    inc(num,q[ i ].d);
    time:=time+abs(q[ i ].x-u)+abs(q[ i ].y-v)+1;
    u:=q[ i ].x;v:=q[ i ].y;
    end
    else break;
    end;
    {assign(output,'peanuts.out');
    rewrite(output); }
    writeln(num);
    //close(output);
    end.
    
    • 1

    信息

    ID
    1930
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者