360笔试第一题,求表面积,大佬看看问什么ac 0

#360公司##笔试题目#
全部评论
ac100%,明天贴代码
点赞 回复 分享
发布于 2019-08-15 21:48
我ACl18.9%
点赞 回复 分享
发布于 2019-08-15 21:27
AC 100的代码 import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); while(scanner.hasNext()) { int N=scanner.nextInt(); int M=scanner.nextInt(); int[][] all=new int[N][M]; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { all[i][j]=scanner.nextInt(); } } int top=N*M; int num=0; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { if(i>0&&all[i][j]>all[i-1][j]) { num+=all[i][j]-all[i-1][j]; } if(j>0&&all[i][j]>all[i][j-1]) { num+=all[i][j]-all[i][j-1]; } if(i<N-1&&all[i][j]>all[i+1][j]) { num+=all[i][j]-all[i+1][j]; } if(j<M-1&&all[i][j]>all[i][j+1]) { num+=all[i][j]-all[i][j+1]; } if(i==0) num+=all[i][j]; if(j==0)     num+=all[i][j]; if(i==N-1) num+=all[i][j]; if(j==M-1) num+=all[i][j]; } } int result=top*2+num; System.out.println(result); } } }
点赞 回复 分享
发布于 2019-08-16 10:39
楼主有输出吗= =
点赞 回复 分享
发布于 2019-08-15 22:07
是不是因为没有循环输入。 public class Main1 {     public int getSum(int[][] cube, int M, int N){         int sum = 0;         for(int temi = 1; temi <= M; temi++){             int temsum = 0;             for(int temj = 1; temj <= N; temj++){                 int val = cube[temi][temj];                 temsum += (val > cube[temi-1][temj])?val-cube[temi-1][temj]:0;                 temsum += (val > cube[temi+1][temj])?val-cube[temi+1][temj]:0;                 temsum += (val > cube[temi][temj-1])?val-cube[temi][temj-1]:0;                 temsum += (val > cube[temi][temj+1])?val-cube[temi][temj+1]:0;             }             sum += temsum;         }         return sum;     }     public static void main(String[] args){         Scanner sc = new Scanner(System.in);         Main1 obj = new Main1();         while(sc.hasNext()){             int M, N;             M = sc.nextInt();             N = sc.nextInt();             int[][] cube = new int[M+2][N+2];             for(int temi = 1; temi <= M; temi++){                 for(int temj = 1; temj <= N; temj++){                     cube[temi][temj] = sc.nextInt();                 }             }             int sum = obj.getSum(cube, M, N);             System.out.println(sum+2*M*N);         }     } }
点赞 回复 分享
发布于 2019-08-15 21:58
你这读数据的函数没对吧,in.nextLine()是不是把下一行给读进去了?下面的代码应该是没错的
点赞 回复 分享
发布于 2019-08-15 21:47
分享下我的思路 public void first() {         Scanner scanner = new Scanner(System.in);         int N = scanner.nextInt();         int M = scanner.nextInt();         int[][] nums = new int[N + 2][M + 2];         int result = 0;         for (int i = 1; i <= N; i++) {             for (int j = 1; j <= M; j++) {                 nums[i][j] = scanner.nextInt();             }         }         for (int i = 1; i <= N; i++) {             for (int j = 1; j <= M; j++) {                 if (nums[i][j] < 1) {                     continue;                 }                 int ***Num = nums[i][j];                 result += 2;                 int up = ***Num - nums[i - 1][j];                 int down = ***Num - nums[i + 1][j];                 int left = ***Num - nums[i][j - 1];                 int right = ***Num - nums[i][j + 1];                 if (up > 0) {                     result += up;                 }                 if (down > 0) {                     result += down;                 }                 if (left > 0) {                     result += left;                 }                 if (right > 0) {                     result += right;                 }             }         }         System.out.println(result);     }
点赞 回复 分享
发布于 2019-08-15 21:37

相关推荐

03-19 18:27
已编辑
门头沟学院 C++
26学院本太难了,很多公司机筛就给我刷了。机会都难拿到如果是简历存在问题也欢迎拷打————————————————————分割线——————————————————————2026.3.4更新:发完贴之后,时不时投递又收到了不少的笔试/面试邀请。主要是之前投递简历出去之后基本上都是沉默状态,年后好转了不少timeline:2026.01.21&nbsp;文远知行笔试,半年多没刷算法题&nbsp;-&gt;挂&nbsp;(后续HR说春招可以重新安排笔试)2026.2.4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;小鹏汇天&nbsp;技术一面,第二周收到结果&nbsp;-&gt;挂2026.2.12&nbsp;&nbsp;&nbsp;大众Cariad代招&nbsp;技术二面&nbsp;-&gt;Offer2026.2.28&nbsp;&nbsp;&nbsp;多益网络技术面试,由于风评太差,一直在犹豫要不要接面试&nbsp;-&gt;推迟-----------分割线-----------2026.3&nbsp;月前的某一天,临时去电网报名了二批计算机岗位的笔试2026.3.6&nbsp;从上家公司实习离职,氛围最好的一家公司,leader&nbsp;说可以帮忙转正,但是流程太长,而且我们部门据说只有一个&nbsp;hc,更想要研究生,我很有可能是会被签外包公司在这里干活,就离职了。2026.3.9&nbsp;入职新公司,大众Cariad&nbsp;以外部公司的身份进组,项目组签了三年,后续三年应该都可以在这里呆,不知道有没有希望原地跳槽。2026.3.10&nbsp;电网考试居然说我通过资格审查了,短信约我去参加资格审查,请假一天,买了&nbsp;12&nbsp;号晚上的机票回成都2026.3.15&nbsp;参加国家电网三新计算机类的笔试2026.3.17&nbsp;电网出成绩了,感觉很低。觉得已经🈚️了2026.3.18&nbsp;收到电网面试通知,通知&nbsp;3.22-3.25&nbsp;这个时间去面试,我的岗位只招&nbsp;1&nbsp;个人。据说面试只有&nbsp;2-3&nbsp;人,不知道能不能成功
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务