2017百度实习生招聘笔试真题编程题集合

1,买帽子

2017百度实习生招聘笔试真题编程题集合_第1张图片

AC代码如下:

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class BD001 {

	/*买帽子
	 */
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String s=sc.nextLine();
			String str=sc.nextLine();
			String []arr=str.split(" ");
			int []arrInt=new int[arr.length];
			Set set=new TreeSet();
			set=new HashSet();
			for(int i=0;i


2,度度熊回家

2017百度实习生招聘笔试真题编程题集合_第2张图片

AC代码如下:

 

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class BD002 {

	/*度度熊回家
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String s=sc.nextLine();
			String str=sc.nextLine();
			String []arr=str.split(" ");
			List list=new ArrayList();
			int min=Integer.MAX_VALUE;
			for(int i=0;iresult?result:min;
				list.add(i, temp);
			}
			System.out.println(min);
		}

	}
	public static int fun(List list){
		int distance=0;
		for(int i=1;i


3,寻找三角形

2017百度实习生招聘笔试真题编程题集合_第3张图片

AC代码如下:

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test003 {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int N=sc.nextInt();
			sc.nextLine();
			String []p=new String[N];
			for(int i=0;i list=new ArrayList();
			List> result=new ArrayList();
			backTracking(a, 0, 3, list, result);
			List> readList=new ArrayList();
			double max=0.0;
			for(int i=0;i temp1=result.get(i);
				if(temp1.get(0).c.equals(temp1.get(1).c)&&temp1.get(0).c.equals(temp1.get(2).c)||(!temp1.get(0).c.equals(temp1.get(1).c)&&(!temp1.get(0).c.equals(temp1.get(2).c))&&(!temp1.get(1).c.equals(temp1.get(2).c)))){
					readList.add(temp1);
				}
			}
			for(int i=0;i temp=readList.get(i);
				double area=getArea(temp);
				if(area>max){
					max=area;
				}
			}
			DecimalFormat f=new DecimalFormat("0.00000");
			String format=f.format(max);
			System.out.println(format);

			
		}
		

	}
	
	public static double getArea(List list){
		Point a=list.get(0);
		Point b=list.get(1);
		Point c=list.get(2);
		double disab=Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
		double disbc=Math.sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y)+(b.z-c.z)*(b.z-c.z));

		double disac=Math.sqrt((a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y)+(a.z-c.z)*(a.z-c.z));
		double s=0.5*(disab+disbc+disac);
		double area=Math.sqrt(s*(s-disab)*(s-disbc)*(s-disac));
		return area;

	}
	public static void backTracking(Point []a,int start,int k, List tempList,List> result){

		if(k<0)
			return;
		else if(k==0){
			result.add(new ArrayList(tempList));
		}else{
			for(int i=start;i


4,有趣的排序

2017百度实习生招聘笔试真题编程题集合_第4张图片

AC代码如下:

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

public class BD004 {
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    while(sc.hasNext()){
	    	String s1=sc.nextLine();
	    	String s2=sc.nextLine();
	    	String []arrS=s2.split(" ");
	    	int []arr=new int[arrS.length];
	    	int []result=new int[arr.length];
	    	for(int i=0;i


5,不等式数列

2017百度实习生招聘笔试真题编程题集合_第5张图片

AC代码如下:

import java.util.Scanner;

public class BD005 {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String s=sc.nextLine();
			String []arr=s.split(" ");
			int n=Integer.parseInt(arr[0]);
			int k=Integer.parseInt(arr[1]);
			int [][]dp=new int[n+1][n+1];
			for(int i=1;i<=n;i++){
				dp[i][0]=1;
				dp[i][i-1]=1;
			}
			for(int i=2;i


 

你可能感兴趣的:(2017校招)