zoukankan      html  css  js  c++  java
  • 201909-1 小明种苹果 Java

    思路:
    保存掉落的苹果总数,和树是第几棵即可

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    public class Main {
    	public static void main(String[] args) throws IOException {
    		BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
    		String[] line = buff.readLine().split(" ");
    		int n = Integer.parseInt(line[0]);
    		int m = Integer.parseInt(line[1]);
    		
    		int sum = 0;//总数
    		int maxCnt = 1;//最大掉落数的下标
    		int maxSum = 0;//最大掉落数
    		
    		for ( int i = 1; i <= n; i++ ) {
    			line = buff.readLine().split(" ");
    			int temp = Integer.parseInt(line[0]);//当前树的苹果数
    			int downNum = 0;//掉落的数量
    			for ( int j = 1; j <= m; j++ ) {
    				downNum += Integer.parseInt(line[j]);
    			}
    			downNum = Math.abs(downNum);
    			if ( downNum > maxSum ) {
    				maxSum = downNum;
    				maxCnt = i;
    			}
    			
    			sum += temp-downNum;
    		}
    		System.out.println(sum+" "+maxCnt+" "+maxSum);
    	}
    }
    
  • 相关阅读:
    sparse用法matlab官方说明
    C++双向循环链表
    循环链表以及迭代器的使用c++
    顺序队列c++
    顺序栈c++
    尾插法链表
    邻接表建立图
    深度优先搜索树与广度优先搜索树
    tensorflow-笔记02
    深度学习-框架介绍
  • 原文地址:https://www.cnblogs.com/yu-jiawei/p/12376522.html
Copyright © 2011-2022 走看看