被百度的大数字题目难倒了,不愧是搞科学的厂子

package baidu;

import java.util.Arrays;
import java.util.Scanner;

public class Problem22 {

public static long solve(long[] array) {
int len = array.length;
int res = 0;
Arrays.sort(array);
if(array[len-1]<len) return 0;
long a = array[len-1];
int index = len - 2;
long b = array[index];
while(a==b&&index>0) {
b=array[--index];
}
long gap = a - b;
long n = gap / (len+1) ;
long k = n-1;
if(k<=0) {
k=1;
}
for(int i=0; i<len-1; i++) {
if(array[i]==array[len-1]) {
array[i] -= k*len;
} else {
array[i] += k;
}
}
array[len-1] -= k*len;
return k;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int num = Integer.parseInt(str);
long[] data = new long[num];
String test = sc.nextLine();
String[] split = test.split(" ");
for(int i=0; i<num; i++) {
data[i] = Long.parseLong(split[i]);
}
long k = 0;
long temp = 0;
while((temp=solve(data))!=0) {
k += temp;
}
System.out.println(k);
}
}
/**
3
737473475237 88435823485328 83485238458345
*/
#笔试题目##百度##吐槽#
全部评论
啥题啊
点赞 回复 分享
发布于 2019-09-24 22:09

相关推荐

不愿透露姓名的神秘牛友
07-25 18:02
来组里2个月了,天天让打杂,写的代码不超过200行。现在已经开始摆烂冲秋招了。我感觉4个月,就算周六日全天睡觉,周一到周五一直看黑马也比我来节子实习学到的东西多。
小熊梦奇:😅节子那么多文档,你是一个都不看啊。 大厂的意义在于内部系统对你开放,看明白事情起因经过结果解决措施,实在看不明白,直接聊天系统搜到对应团队去问当时的负责人,大部分情况下都会给你解答。 这才是大厂实习的精髓
实习生的蛐蛐区
点赞 评论 收藏
分享
07-25 13:42
门头沟学院 Java
安锋:看看老板的腿
点赞 评论 收藏
分享
求offer的大角牛:简历写的第一乱,没有突出重点,第二项目太多太杂看不出来有啥核心技术,第三自我评价太多了,第四获得的荣誉没啥含金量,可以不写,反正问题不少
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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