科大讯飞 笔试 ak
研发类 第一题贪心,第二题 快排 第三题 判断 第四题 简单判断
import java.util.HashMap;
import java.util.Scanner;
/*
第一题
5 2 2 3 5
55
5 2 2 3 5
135
5 2 2 3 5
685
1 1 0 0 0
6
1 1 1 0 0
16
2 2 2 0 0
32
2 2 2 3 5
632
*/
public class Main {
static HashMap<Integer,Integer> data = new HashMap<>();
static int res = Integer.MAX_VALUE;
static int[] num = {1,5,10,50,100};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for(int i=0;i<5;i++){
int p = sc.nextInt();
data.put(num[i],p);
}
int sum = sc.nextInt();
dfs(sum,0,4);
System.out.println(res==Integer.MAX_VALUE?-1:res);
}
public static void dfs(int sum,int count,int start){
if (sum ==0 ){
res = Math.min(res,count);
return;
}else{
for(int i=start;i>=0;i--){
if (num[i]<=sum&&data.get(num[i])!=0){
int money = data.get(num[i]);
int flag = 0;
if (money*num[i]<=sum){
count+=money;
data.put(num[i],0);
flag = sum - money*num[i];
}else{
int q = sum/num[i];
count+=q;
data.put(num[i],data.get(num[i])-q);
flag = sum - q*num[i];
}
dfs(flag,count,start-1);
return;
}
}
}
}
}
/*
第二题
9
25 84 21 47 15 27 68 35 20
*/
public class Main{
static int[] data;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
data = new int[num];
for(int i=0;i<num;i++){
data[i]=sc.nextInt();
}
sort(0,num-1);
}
public static void sort(int left,int right){
if (left>=right) return;
int start = left;
int end = right;
int now = data[left];
while (left<right){
int n;
int m;
while (left<right&&data[right]>now){
right--;
}
while(left<right&&data[left]<=now){
left++;
}
int tmp = data[right];
data[right] =data[left];
data[left] =tmp;
}
int p = data[start];
data[start] = data[left];
data[left] = p;
print();
sort(start,left-1);
sort(left+1,end);
}
public static void print(){
for(int i=0;i<data.length;i++){
if (i==data.length-1){
System.out.println(data[i]);
return;
}
System.out.print(data[i]+" ");
}
}
}
/*
第三题
0 0 4 3 0 1 5 4
-1 -1 0 0 1 2 3 4
-1 -1 0 0 0 0 3 4
*/
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] a = new int[2][2];
int[][] b = new int[2][2];
for(int i=0;i<2;i++){
a[i][0] = sc.nextInt();
a[i][1] = sc.nextInt();
}
for(int i=0;i<2;i++){
b[i][0] = sc.nextInt();
b[i][1] = sc.nextInt();
}
Arrays.sort(a,(o1,o2)->o1[0]-o2[0]);
Arrays.sort(b,(o1,o2)->o1[0]-o2[0]);
int aminx= Math.min(a[0][0],a[1][0]);
int amaxx= Math.max(a[0][0],a[1][0]);
int aminy= Math.min(a[0][1],a[1][1]);
int amaxy= Math.max(a[0][1],a[1][1]);
int bminx= Math.min(b[0][0],b[1][0]);
int bmaxx= Math.max(b[0][0],b[1][0]);
int bminy= Math.min(b[0][1],b[1][1]);
int bmaxy= Math.max(b[0][1],b[1][1]);
boolean res = find(aminx,aminy,bminx,bmaxx,bminy,bmaxy)||
find(aminx,amaxy,bminx,bmaxx,bminy,bmaxy)||
find(amaxx,aminy,bminx,bmaxx,bminy,bmaxy)||
find(amaxx,amaxy,bminx,bmaxx,bminy,bmaxy)||
find(bminx,bminy,aminx,amaxx,aminy,amaxy)||
find(bminx,bmaxy,aminx,amaxx,aminy,amaxy)||
find(bmaxx,bminy,aminx,amaxx,aminy,amaxy)||
find(bmaxx,bmaxy,aminx,amaxx,aminy,amaxy);
if (res) System.out.println(1);
else System.out.println(0);
}
public static boolean find(int x,int y,int xmin,int xmax,int ymin ,int ymax){
if (x>=xmin&&x<=xmax&&y>=ymin&&y<=ymax){
return true;
}else {
return false;
}
}
}
/*
第四题
+1a2
*/
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String data = sc.nextLine();
int flag = 0;
for(int i=0;i<data.length();i++){
if (i==0&&data.charAt(i)=='-'){
flag =1;
System.out.print('-');
}
if (data.charAt(i)>='0'&&data.charAt(i)<='9'){
System.out.print(data.charAt(i));
}
}
System.out.println();
}
} 求offer
快手公司福利 1244人发布