网易互娱第三题有没有用JAVAA的?

网易互娱第三题自己本地都可以过,调试就是0。😭😭😭求求菜***,到底是什么问题。#网易##笔试题目#
全部评论
import java.util.Scanner; public class Main {     public static void main(String[] args){         Scanner in = new Scanner(System.in);         int T = in.nextInt();         for (int j=0;j<T;j++) {             int K = in.nextInt();             int M = in.nextInt();             if (M == 0){                 System.out.println((31+2*K)/(K+1) - 1);             }else {                 int[] arr = new int[M];                 for (int i = 0; i < M; i++) {                     arr[i] = in.nextInt();                 }                 int sum = M;                 for (int i = 0; i < M - 1; i++) {                     sum += (arr[i + 1] - arr[i]) / (K + 1) - 1;                 }                 sum += (arr[0] + K) / (K + 1) - 1;                 sum += (30 + K + 1 - arr[arr.length - 1]) / (K + 1) - 1;                 System.out.println(sum);             }         }     } }
点赞 回复 分享
发布于 2019-09-07 21:58
//我的代码有什么问题求大佬看一下 import java.util.*; public class Main {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);         int T = scan.nextInt();         int[] res = new int[T];         for (int i = 0; i < T; i++) {             int k = scan.nextInt();             int m = scan.nextInt();             int[] nums = new int[m];             for (int j = 0; j < nums.length; j++) {                 nums[j] = scan.nextInt();             }             res[i] = find(nums, k);         }         for (int i = 0; i < T; i++) {             System.out.println(res[i]);         }     }     private static int find(int[] nums, int k) {         int[] help = new int[31];         int cnt = nums.length;         for (int i = 0; i < nums.length; i++) {             help[nums[i]] = 1;         }         int cnt1=0;         int cnt2=0;         boolean bool=true;         for (int i = 1; i < help.length; i++) {             if (help[i]!=0){                 if (bool){                     cnt2=cnt1/(k+1);                 }else {                     cnt2=(cnt1-k)/(k+1);                 }                 bool=false;                 cnt+=cnt2;                 cnt1=0;             }else {                 cnt1++;             }         }         if (cnt1!=0){             cnt2=cnt1/(k+1);             cnt+=cnt2;         }         return cnt;     } }
点赞 回复 分享
发布于 2019-09-07 21:52
求大神解答。。我这个做法哪里没对 public static void main(String[] args) {         Scanner in = new Scanner(System.in);         while (in.hasNext()) {             int num = in.nextInt();             for (int i = 0; i < num; i++) {                 int k = in.nextInt();                 int m = in.nextInt();                 int max=30/(k+1);                 if (m == 0)                      System.out.println(max);                else {                     int result = m;                             List<Integer> a = new ArrayList<Integer>(m);                     for (int j = 0; j < m; j++) {                         a.add(in.nextInt());                     }                     if (k == 0)                         System.out.println(30);                     else {                         int teml=(a.get(0)-1)/(k+1);                         if(teml>=1)                           result=result+teml;                         int temr=(30-a.get(a.size()-1))/(k+1);                         if(temr>=1)                               result=result+temr;                             for(int r=0;r<a.size()-1;r++)                             {                                                int tem=(a.get(r+1)-a.get(r))/(k+1);                                if(tem>1)                                    result=result+tem-1;                                                                                                                                         }                         System.out.println(result);                     }                                      }             }         }     }
点赞 回复 分享
发布于 2019-09-07 21:37
package wy4; import java.util.Scanner; public class Main {     public static void main(String[] args) {         Scanner sc=new Scanner(System.in);         int num=sc.nextInt();         sc.nextLine();         while(sc.hasNext())         {             int jiange=sc.nextInt();             int subNum=sc.nextInt();             int[] arr=new int[subNum];             if(subNum!=0){                 sc.nextLine();                 for(int i=0;i<arr.length;i++)                     arr[i]=sc.nextInt();}            // System.out.println(arr);             if(jiange==0)                 System.out.println(30);             else if(subNum==0)             {                 int count=0;                 int i=1;                 while(i<=30)                 {                     if(i+jiange+1<=30)                         count++;                     i=i+jiange+1;                 }                 System.out.println(count+1);             }             else{                 int num1111=method(jiange+1,arr);                 System.out.println(num1111+1);             }             sc.nextLine();         }     }     public static int method(int jiange,int[] arr)     {         int count=0;         for(int i=0;i<arr.length;i++)         {             if(i==0)             {                 int temp=arr[i];                 while(temp>=1)                 {                     if(temp-jiange>=1)                         count++;                     temp-=jiange;                 }             }             int temp1=arr[i];             int temp2;             if(i+1<arr.length)                 temp2=arr[i+1];             else                 temp2=30;             while(temp1<=temp2)             {                 if(temp1+jiange<=temp2)                     count++;                 temp1+=jiange;             }         }         return count;     } }
点赞 回复 分享
发布于 2019-09-07 21:35
无限数组越界。。。找不出是什么鬼
点赞 回复 分享
发布于 2019-09-07 21:34
import java.util.*; public class Caffe {     public static void main(String[] args) {         Scanner cin = new Scanner(System.in);         int t=cin.nextInt();         for (int i = 0; i <t ; i++) {             int[] a=new int[30];             int k=cin.nextInt();             int m=cin.nextInt();             for (int j = 0; j <m ; j++) {                 int temp=cin.nextInt();                 a[temp-1]=1;             }             if (k==0)                 System.out.println(30);             else {                 int count = 0;                 int s = 0;                 while (s < 30) {                     if (a[s] == 0) {                         int q;                         for (q = s + 1; q<= s + k && q < 30; q++) {                             if (a[q] != 0)                                 break;                         }                         if (q == 30 && a[29] == 0) {                             a[s] = 1;                             break;                         }                         if (q == s + k + 1 && (s+ k) < 30 && a[s + k] == 0) {                             a[s] = 1;                             s = q;                         }                         else                             s = q + k + 1;                     } else{                         s = s+ k + 1;                 }             }                 for (int n = 0; n <30 ; n++) {                     count += a[n];                 }                     System.out.println(count);                 }         }     } }
点赞 回复 分享
发布于 2019-09-07 21:34
蹲一个解答,到底什么m=0后面到底什么测试数据
点赞 回复 分享
发布于 2019-09-07 21:34
就是喝咖啡的哪一题,都不知道哪里出现了问题
点赞 回复 分享
发布于 2019-09-07 21:33
我是用JAVA的
点赞 回复 分享
发布于 2019-09-07 21:33
本地通过,一测全为0
点赞 回复 分享
发布于 2019-09-07 21:33
你是固定喝咖啡那题吗?我也是,自测很多条都过了 调试就是0
点赞 回复 分享
发布于 2019-09-07 21:32
我也是,本地都过了
点赞 回复 分享
发布于 2019-09-07 21:32
一样 感觉思路也不难 不知道哪出问题了
点赞 回复 分享
发布于 2019-09-07 21:32

相关推荐

05-28 16:06
门头沟学院 Java
嵐jlu:我是山川🐔里🐔🧱的,阿里系简历全过; 你这简历一看就还是半成品啊,没有荣誉经历奖项什么的吗?
投递阿里巴巴集团等公司10个岗位
点赞 评论 收藏
分享
07-23 12:04
门头沟学院 Java
现在是很缺人吗
码农索隆:缺分母,不缺分子,这样好作为炫耀的资本
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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