萌新求大佬,部分答案错误,是哪里错了啊
查看原帖
萌新求大佬,部分答案错误,是哪里错了啊
489506
LiXingWang楼主2021/4/13 19:21
# include <iostream>
# include <algorithm>
using namespace std;
struct node{
	int x,y,huangsheng;
}mp[500];
bool cmp (node a,node b)
{
	return a.huangsheng > b.huangsheng;
}
int main ()
{
	int n,m,t;
	cin>>n>>m>>t;
	int k = 0;
	for(int i = 1;i<=n;i++)
	{
		for(int j = 1;j<=m;j++)
		{
			cin>>mp[k++].huangsheng;
			mp[k].x = i,mp[k].y = j;
		}
	}
	sort(mp,mp+k,cmp);
	int ans = 0;
	for(int i = 0;i<n*m;i++)
	{
		if(i == 0)
			if(t >= 2*mp[i].x+1)
			{
				ans += mp[i].huangsheng;
				t -= 1+mp[i].x;
			}
			else
			break;
		else
		{
			if(t >= mp[i].x+1+abs(mp[i-1].x-mp[i].x)+abs(mp[i-1].y-mp[i].y))
				{
					t -= abs(mp[i-1].x-mp[i].x)+abs(mp[i-1].y-mp[i].y)+1;
					ans += mp[i].huangsheng; 
				}
			else
			break;
		}
	}
	cout<<ans<<endl;
	return 0;	
}			 
2021/4/13 19:21
加载中...