备战蓝桥之每日一题

P1086 NOIP2004 普及组 花生采摘 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

复制代码
import java.awt.Checkbox;
import java.awt.PageAttributes.OriginType;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.math.MathContext;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main {	
  public static void main(String[] args) throws NumberFormatException, IOException  {
	  Scanner scanner=new Scanner(System.in);
	 BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
	 PrintWriter pw1=new PrintWriter(System.out);
     String[] aStrings=br1.readLine().split(" ");
     int a=Integer.parseInt(aStrings[0]);
     int b=Integer.parseInt(aStrings[1]);
     int c=Integer.parseInt(aStrings[2]);
     int d,e,f,jishu;
     jishu=0;
     for(d=1;d<=a;d++) {
    	 String[] bStrings=br1.readLine().split(" ");
    	 for(e=1;e<=b;e++) {
    		 f=Integer.parseInt(bStrings[e-1]);
    		 if(f!=0) {
    			aa1[jishu]=new huasheng(f, d, e);
    			jishu++;
    		 }
    	 }
     }
     Arrays.sort(aa1,0,jishu);
    int g;
    int answer=0;
    int x1=0;
    int y1=aa1[0].y;
    int haoshi=0;
    for(g=0;g<jishu;g++) {
    	haoshi=haoshi+Math.abs(aa1[g].x-x1)+Math.abs(aa1[g].y-y1)+1+aa1[g].x;
    	
    	if(haoshi<=c) {
    		haoshi=haoshi-aa1[g].x;
    		x1=aa1[g].x;
    		y1=aa1[g].y;
    		answer=answer+aa1[g].number;
    	}
    	else {
    		break;
    	}
    }
    System.out.println(answer);
  }
public static huasheng[] aa1=new huasheng[500];
}
class huasheng implements Comparable<huasheng>{
	int number;
	int x;
	int y;
	public huasheng(int number, int x, int y) {
		super();
		this.number = number;
		this.x = x;
		this.y = y;
	}
	@Override
	public int compareTo(huasheng o) {
		// TODO Auto-generated method stub
		return o.number-this.number;
	}
	@Override
	public String toString() {
		return "huasheng [number=" + number + ", x=" + x + ", y=" + y + "]";
	}
	
}
相关推荐
AI人工智能+电脑小能手3 分钟前
大白话说Java设计模式-34-命令模式(业务实战篇)
java·spring·设计模式·命令模式·异步任务·撤销重做·事务封装
Nil2084 分钟前
leetcode 105从前序和中序遍历序列构造二叉树
算法·leetcode·职场和发展
净重21克6 分钟前
万字长文!TLS协议升级避坑手册:JDK老项目适配TLS1.2/1.3全流程拆解
java·springboot·java安全
一直C9 分钟前
【数据结构】哈希表+算法复杂度与经典排序查找(C语言)
java·linux·开发语言·数据结构·算法·ubuntu·散列表
paopaokaka_luck9 分钟前
基于springboot3+vue3的车间生产管理系统(Echarts图形化分析、BI报表)
java·前端·spring boot·学习·echarts
淡海水11 分钟前
04-02-哈希-Dictionary-TKey-TValue-上-核心数据结构
数据结构·算法·c#·哈希算法·编译·字典·dictionary
戴西软件17 分钟前
国内有哪些数据轻量化格式转换软件?
数据库·算法·安全·信息可视化·自动化·rpa
老洋葱Mr_Onion39 分钟前
【C++】CSP-J初赛模拟卷七错题整理(作者自用)
c++·算法·深度优先
Zane19941 小时前
遍历时删元素为什么报错:modCount 这个"计数器"在背后盯着你
java·后端
土星云SaturnCloud1 小时前
Real-ESRGAN超分辨率算法原理与边缘侧部署实践
服务器·算法·ai·边缘计算·real-esrgan