I AK EGOI (萌新最后一个点WA了,有数据
查看原帖
I AK EGOI (萌新最后一个点WA了,有数据
1399526
BoooFar楼主2024/9/11 20:50

最后一个点WA了

#include<bits/stdc++.h>
using namespace std;
int m,n,k,h[25][25],da,daa,t,x,y,ke,ci,xx,yy,xxx;
int main(){
	cin>>m>>n>>k;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			cin>>h[i][j];
		}
	} 
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(daa<h[i][j]){
				daa=h[i][j];
				xxx=i;
			}	
		}
	} 	
	if(2*xxx+1>k){
		cout<<ke;
		return 0;
	}
	da=0;
	for(int i=1;i<=m;i++){
		if(i*2+1>k){
			for(int j=1;j<=n;j++){
				h[i][j]=0;
			}
		}else{
			for(int j=1;j<=n;j++){
				if(da<h[i][j]){
					da=h[i][j];
				}
			}
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(h[i][j]!=da){
				if(ci<h[i][j]){
					ci=h[i][j];
					xx=i;
					yy=j;
				}
			}
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(da==h[i][j]){
				t=i+1;
				x=i;
				y=j;
				ke+=h[i][j];
				h[i][j]=0;
			}
		}
	}
	
	if(da==0){
		cout<<0;
		return 0;
	}
	while(da!=0){
		da=0;
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				if(t+abs(x-i)+abs(y-j)+i+1>k){
					h[i][j]=0;
				}
				if(da<h[i][j]){
					da=h[i][j];
				}
			}
		}
		if(h[xx][yy]==0){
			cout<<ke;
			return 0;
		}
		ci=0;
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				if(h[i][j]!=da){
					if(ci<h[i][j]){
						ci=h[i][j];
						xx=i;
						yy=j;
					}
				}
			}
		}
		if(da==0){
			return 0;
		}
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				if(da==h[i][j]){			
					t+=abs(x-i)+abs(y-j)+1;
					x=i;
					y=j;					
					ke+=h[i][j];
					h[i][j]=0;					
				}
			}
		}	
	}	
}   

数据: 20 20 400

0 182 0 324 64 24 0 354 0 0 156 344 0 0 0 0 346 0 34 0 0 0 0 378 0 302 0 0 276 0 16 0 218 216 326 0 306 0 270 168 0 190 0 0 22 128 0 0 296 340 348 0 376 174 102 0 0 372 18 100 0 86 286 110 274 118 0 0 30 360 94 0 10 338 0 212 240 0 210 114 2 0 150 0 0 0 0 0 186 358 0 0 308 224 396 398 0 0 244 0 180 0 56 0 0 66 122 388 172 0 0 0 0 0 0 294 0 0 0 14 268 384 0 170 266 0 0 0 0 0 0 0 0 362 0 0 6 0 0 0 394 0 0 364 0 0 0 0 60 0 0 332 0 0 0 0 0 374 0 282 226 88 134 106 0 200 196 0 0 0 32 230 0 144 214 76 46 284 0 0 140 0 0 0 72 0 96 314 250 316 0 154 0 0 206 0 0 318 0 132 90 38 0 368 160 26 0 0 44 194 280 382 138 0 334 188 242 0 238 0 0 0 0 84 158 380 258 202 0 248 4 68 0 232 80 178 28 0 246 322 0 0 0 300 0 54 0 0 0 0 0 254 0 0 236 0 0 228 204 0 0 0 0 278 304 0 164 0 312 0 0 264 62 124 0 0 320 0 0 104 208 198 0 98 0 356 0 12 0 352 126 0 0 0 262 120 0 82 0 288 148 252 0 0 74 392 0 78 0 0 330 92 192 0 0 0 50 36 298 0 0 0 0 370 366 0 0 256 184 0 386 0 116 0 112 8 290 0 176 130 70 152 58 166 162 0 142 0 272 0 0 234 0 0 0 48 328 0 350 0 0 292 0 40 0 0 222 390 0 0 0 0 260 0 310 0 0 0 220 0 0 0 136 0 342 336 42 0 0 0 108 0 146 20 0 0 0 52 0 0

2024/9/11 20:50
加载中...