1 solutions

  • 0
    @ 2025-11-5 16:39:50

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    struct node{
    	int x;
    	int y;
    	int hss;
    };
    float jl(node c,node d)
    {
    	int v=abs(c.x-d.x)+abs(c.y-d.y);
    	return v;//求两颗花生之间的距离
    }
    int my_comp(const node &c,const node &d)
    {
    	return c.hss>d.hss;
    }
    int main()
    {
    	int m,n,k,g=1,h=1;
    	cin>>m>>n>>k;
    	node a[m*n];
    	for(int i=1;i<=m*n;i++)
    		{
    			cin>>a[i].hss;
    			a[i].x=g;
    			a[i].y=h++;
    			if(h>n)
    			  {
    			   	h=1;
    			  	g++;
    			  }
    		}
    	sort(a+1,a+m*n+1,my_comp);
    	float u=0,zs=0;
    	node p;
    	p.x=0;
    	p.y=a[1].y;
    	int o=1;
    	u=jl(p,a[o])+1+a[o].x;
    	zs=a[o].hss;
    	while(u<=k)
    	{	
    		p=a[o];	//p是你的摘花生起点,试探下一个花生意味着你的起点不是路边,而是你试探的花生的生一个花生
    		o++;
    		u=u-p.x+jl(p,a[o])+1+a[o].x;//试探下一个花生能否采摘,上次能摘的花生总时间减去上次从最后一个花生回去
    //时间加上下一个花生和上次最后一个摘的花生距离,再加上从试探的这个花生回路边,一共的时间与k关系,小于等于便可以摘
    		zs+=a[o].hss;			
    	}	
    	cout<<zs-a[o].hss;
    }
    
    

    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

    Information

    ID
    17912
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By