当前位置:网站首页>Tencent machine test questions
Tencent machine test questions
2022-07-02 07:23:00 【Drizzle】
Time :2019.04.05
1
topic :
Small Q I like orange juice very much , His parents gave him a gift on his birthday n A bottle of orange juice , The first i The volume of bottle orange sweat is v i v_i vi Ascending . Small Q Want to drink some first , Drink the rest slowly . He wants to pour it out first s Ml for yourself , At the same time, in order to get double happiness , He wants the smallest volume of the remaining orange juice to be as large as possible . Please help him calculate when he falls s What is the smallest volume of orange juice left after ml of juice and double happiness
Note that the volume of orange juice taken from each bottle of orange juice can only be an integer .
Input description :
The first line has two integers n,s, Separate... With a space ;
The second line n It's an integer v i v_i vi, Indicates the volume of each bottle of juice , Every two positive integers are separated by a space .
Satisfy 1 < = n < = 1000 , 1 < = s < = 1 0 9 , 1 < = v i < = 1 0 9 1 <= n <= 1000, 1 <= s <= 10^9, 1 <= v_i <= 10^9 1<=n<=1000,1<=s<=109,1<=vi<=109
Output description :
An integer , Represents the minimum volume of orange juice . If you can't pour it out s Ml orange juice , Then output one 1.
Example 1
Input
3 5
1 1 1
Output
-1
Example 2
Input
2 9
5 10
Output
3
case Passing rate 40%
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int s = sc.nextInt();
int [] v = new int[n];
int sum = 0;
int min = 1000000001;
for(int i = 0; i < n; i++){
v[i] = sc.nextInt();
sum += v[i];
if(min > v[i]) {
min = v[i];
}
}
if(s > sum) {
System.out.println(-1);
} else if((sum - s)/ n < min ) {
System.out.println((sum - s)/ n);
} else {
System.out.println(min);
}
}
}
2
topic :
Small Q Plan to cross the monster Valley . He can't play strange , But he has money . He knows that , Just give the monster a certain amount of gold , Monsters will one Directly escorted him out of the valley .
In the valley , He will meet in turn N A monster , Every monster has its own force value and wants “ Bribe compensation ” The number of gold coins it needs . If small Q No, “ Bribe compensation ” Some monster , And this monster “ Force value ” And more than the sum of the monster forces escorting him , This monster will attack him .
Small Q Want to know , To successfully cross the monster valley without being attacked , How many gold coins should he prepare at least .
Input description :
Enter an integer in the first line N, The number of monsters .
Second line input N It's an integer d 1 , d 2 , . . . , d n d_1,d_2,...,d_n d1,d2,...,dn, Represents force value
In the third line, enter N It's an integer p 1 , p 2 , . . . , p n p_1,p_2,...,p_n p1,p2,...,pn, On behalf of buying N The number of gold coins needed by a monster .
Output description :
Output an integer , Represents the minimum number of gold coins required
Example 1
Input
3
8 5 10
1 1 2
Output
2
Example 2
Input
4
1 2 4 8
1 2 1 2
Output
6
This question AC
import java.util.Scanner;
public class Main {
static long [] power;
static int [] gold;
static int n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
power = new long [n];
gold = new int [n];
for(int i = 0; i < n; i ++) {
power[i] = sc.nextLong();
}
for(int i = 0; i < n; i ++) {
gold[i] = sc.nextInt();
}
System.out.println(foo(power[0], gold[0], 1));
}
static int foo(long self, int sum, int i) {
if(i == n) {
return sum;
}
if(self < power[i]) {
return foo(self + power[i], sum + gold[i], i + 1);
} else {
int a = foo(self + power[i], sum + gold[i], i + 1);
int b = foo(self, sum, i + 1);
return a < b ? a : b;
}
}
}
3
topic :
Small Q One day I had a whim , hold 1 To 2 ∗ n 2 * n 2∗n The number of is divided into two groups of the same size A and B( That is, the length is n).
Then sort from small to large , about 1 <= i <= n, All meet abs(A[i] - B[i]) >= k. among abs Identify the absolute value .
Small Q I don't think this problem is a challenge for him , So I want to test you , Let you calculate the number of distribution schemes that meet the conditions .
Input description :
Enter two integers n (1 <= n <= 50),k (1 <= k <= 10).
Output description :
Output an integer
Example 1
Input
2 2
Output
2
explain
A = {1, 2} B = {3, 4}
A = {3, 4} B = {1, 2}
This question is not finished .. But it's one step away .
import java.util.Scanner;
public class Main {
static int n;
static int k;
static int [] a;
static int [] b;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = 2 * sc.nextInt());
k = sc.nextInt();
a = new int [n / 2];
b = new int [n / 2];
System.out.println(sum(0, 0, true) + sum(0, 0, false));
}
static int sum(int i, int j, boolean b) {
if(i + j + 2 == n) {
return judge()?0:1;
}
if(b) {
a[i] = i + j;
return sum(i + 1, j, true) + sum(i + 1, j, false);
} else {
b[j] = i + j;
return sum(i, j + 1, true) + sum(i, j + 1, false);
}
}
static boolean judge() {
}
}
Original picture
1
2
3
边栏推荐
- RMAN incremental recovery example (1) - without unbacked archive logs
- 【Ranking】Pre-trained Language Model based Ranking in Baidu Search
- How to efficiently develop a wechat applet
- ssm+mysql实现进销存系统
- 【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
- Data warehouse model fact table model design
- ORACLE EBS ADI 开发步骤
- SSM personnel management system
- Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
- SSM garbage classification management system
猜你喜欢
User login function: simple but difficult
【信息检索导论】第三章 容错式检索
【Ranking】Pre-trained Language Model based Ranking in Baidu Search
Only the background of famous universities and factories can programmers have a way out? Netizen: two, big factory background is OK
ssm垃圾分类管理系统
[paper introduction] r-drop: regulated dropout for neural networks
第一个快应用(quickapp)demo
MapReduce与YARN原理解析
MySQL has no collation factor of order by
MySQL无order by的排序规则因素
随机推荐
How to efficiently develop a wechat applet
CRP implementation methodology
使用 Compose 实现可见 ScrollBar
使用Matlab实现:Jacobi、Gauss-Seidel迭代
Data warehouse model fact table model design
【调参Tricks】WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach
使用MAME32K进行联机游戏
Cognitive science popularization of middle-aged people
oracle EBS标准表的后缀解释说明
ssm人事管理系统
[torch] the most concise logging User Guide
[introduction to information retrieval] Chapter II vocabulary dictionary and inverted record table
ORACLE EBS接口开发-json格式数据快捷生成
架构设计三原则
CRP实施方法论
【Torch】最简洁logging使用指南
Feeling after reading "agile and tidy way: return to origin"
【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding
Oracle 11g uses ords+pljson to implement JSON_ Table effect
pySpark构建临时表报错