CCF题库链接:https://blog.csdn.net/weixin_43905586/article/details/88404105
测试链接:http://cspro.org/
问题描述
试题编号: | 201909-1 |
试题名称: | 小明种苹果 |
时间限制: | 2.0s |
内存限制: | 512.0MB |
问题描述: | |
鄙人拙见:
- 分别找出对应的T,k,P;
- 注意:单一实现,避免混乱;
- C代码注意数组空间,定义全局变量
C++参考代码1.0:
#include<iostream>
using namespace std;int apple[1234][1234]; //切记:定义为局部变量的话80分儿int main()
{int N,M;scanf("%d",&N);scanf("%d",&M);for(int i = 0; i < N; i++){for(int j = 0; j < M + 1; j++){scanf("%d",&apple[i][j]);}}int T;int sum = 0;for(int i = 0; i < N; i++){for(int j = 0; j < M + 1; j++){sum = sum + apple[i][j];}}T = sum;//printf("T=%d\n",T);int min[N];for(int i = 0; i < N; i++){min[i] = 0;}for(int i = 0; i < N; i++){for(int j = 1; j < M + 1; j++){min[i] = min[i] + apple[i][j]; }}int k;int minnum = 0;for(int i = 0; i < N; i++){if(min[i] < minnum){minnum = min[i];k = i + 1;}}int p;p = minnum * (-1);printf("%d %d %d",T,k,p);return 0;
}
java参考代码1.0:
import java.util.Scanner;public class Main
{static int Sum(int [][]num,int N,int M){int sum = 0;for(int i = 0; i < N; i++){for(int j = 0; j < M; j++){sum = sum + num[i][j];}}return sum;}static int Number(int [][]num,int N,int M){int number = 0;int min = 0;int sum[] = new int[N];for(int i = 0; i < N; i++){sum[i] = 0;}for(int i = 0; i < N; i++){for(int j = 1; j < M; j++){sum[i] = sum[i] + num[i][j];}if(sum[i] < min){min = sum[i];number = i + 1;}}return number;}static int Min(int [][]num,int N,int M){int min = 0;int sum[] = new int[N];for(int i = 0; i < N; i++){for(int j = 1; j < M; j++){sum[i] = sum[i] + num[i][j];}if(sum[i] < min){min = sum[i]; }}min = min * (-1);return min;}public static void main(String[] args){Scanner input = new Scanner(System.in);int N = input.nextInt();int M = input.nextInt();int num[][] = new int[N][M+1];for(int i = 0; i < N; i++){for(int j = 0; j < M + 1; j++){num[i][j] = input.nextInt();}}int T;T = Sum(num,N,M + 1);int k;k = Number(num,N,M + 1);int P;P = Min(num,N,M + 1);System.out.print(T + " " + k + " " + P);}
}
尾言:作者水平有限,读者思维无限,若有细节错误请见谅,若有好的想法,欢迎评论区留言。
分享名言一句:
- If you ask a good skater how to succeed, he will tell you: "fall down, get up". This is success. ——Newton
- 如果你問一個善於溜冰的人怎樣獲得成功時,他會告訴你:“跌倒了,爬起來”,這就是成功。——牛頓
友情链接分享:
- 我要自学网链接:https://www.51zxw.net/study.asp?vip=21679987
- 在线工具链接:http://tool.lu/?refuid=iq7
- 免费在线流程图思维导图ProcessOn链接:https://www.processon.com/i/5b442a68e4b09a6741627370
- 阅读记录App链接:https://m.yidiansz.com/mobile/invitation/home?shareId=339556#/