兄弟们什么情况?我看帖子说的怎么都不一样,
Java游戏开发
21道选择题(45)加两道编程(55)
编程:
- 求人围成的圈数(30)
- 求最少减速多少(25)
- 为啥有人说编程不能用IDE啊,我这边可以用啊
- 还有人说伪代码,是什么鬼
- 有简答题的兄弟投的什么岗位啊
AK代码:
- (被这个输入输出恶心到了。。。)
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { static int[] dirs = {0,-1,0,1,0}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); List<int[]> list = new ArrayList<>(); while (sc.hasNextLine()){ String s = sc.nextLine(); if("".equals(s)) break; String[] split = s.split(","); int[] tem = new int[split.length]; for (int i = 0; i < split.length; i++) { tem[i] = Integer.valueOf(split[i]); } list.add(tem); } int m = list.size(); int n = list.get(0).length; int[][] grid = new int[m][n]; int ans = 0; for (int i = 0; i < m; i++) { grid[i] = list.get(i); } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if(grid[i][j] == 1){ back(i,j,m,n,grid); ans++; } } } System.out.println(ans); } static void back(int sx, int sy,int m, int n,int[][] grid){ for (int i = 0; i < 4; i++) { int x = sx+dirs[i]; int y = sy+dirs[i+1]; if(x<0 || y<0 || x>=m || y>=n || grid[x][y]==0) continue; grid[x][y] = 0; back(x,y,m,n,grid); } } }
-
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] grid = new int[n][n]; for (int i = 0; i < n; i++) { String s = sc.next(); String[] split = s.split(","); for (int j = 0; j < n; j++) { grid[i][j] = Integer.valueOf(split[j]); } } int [][] dp = new int[n][n]; dp[0][0] = grid[0][0]; for (int i = 1; i < n; i++) { dp[0][i] = grid[0][i]+dp[0][i-1]; dp[i][0] = grid[i][0]+dp[i-1][0]; } for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { dp[i][j] = Math.min(dp[i][j-1],dp[i-1][j])+grid[i][j]; } } System.out.println(dp[n-1][n-1]); } }
全部评论
(9) 回帖