当前位置:网站首页>笔试强训第21天
笔试强训第21天
2022-07-22 22:59:00 【库里不会投三分】
选择题
- 单链表虽然可以通过二分查找去确定位置,但是插入可能只能头插或者尾插,所以还是需要遍历
![]()
- 装载因子=有效元素/数组长度 ,装载因子变大,要有效元素变多,要么数组长度变小,那一个都是会增大冲突的几率
编程题
![]()
- 这道题就是找规律,每次读取一个数之后,算出他经过k次洗牌后的位置,只用一个长度为2n数组用来输出根据当前数的位置,可以算出经过一次洗牌后的位置如果当前数小于等于n(即在左手),则他下次出现的位置是 2*当前位置与之对应的当前位置 + n(即在右手)的牌,则他下次出现的位置是 2*当前位置 + 1
package days.day21; import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ int n=sc.nextInt(); int k=sc.nextInt(); int arr[]=new int[2*n]; for(int i=0;i<2*n;i++){ arr[i]=sc.nextInt(); } sort(arr,k,n); t--; } } public static void sort(int []arr,int k,int n){ for(int i=0;i<k;i++){ int newarr[]=new int[2*n]; for(int j=0;j<n;j++){ newarr[2*j]=arr[j]; newarr[2*j+1]=arr[j+n]; } arr=newarr; } for(int i=0;i<2*n;i++){ System.out.print(arr[i]); if(i!=2*n-1){ System.out.print(" "); } } System.out.println(); } }
- 这道题就是完全的分情况去处理,首先分为两个大情况 1字符小于等于4(这样就不会存在跳到最后一页,和第一页的问题,就不需要去处理换页的问题)2字符大于等于4
- 字符大于等于4的情况就有很多种情况 1从第一页跳到最后一页 2从最后一页跳到最后一页 3刷新掉第一行 整体页面向下移动一格 4刷新掉最后一行在,整个页面向上移动一格 5正常光标下移,不刷新页面 6正常光标上移,不刷新页面
package days.day21; import java.util.*; public class Main2 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String str = sc.next(); char arr[] = str.toCharArray(); int now = 1; int list = 1; if (n <= 4) { for (int i = 0; i < arr.length; i++) { if (now == 1 && arr[i] == 'U') { now = n; } else if (now == n && arr[i] == 'D') { now = 1; } else if (arr[i] == 'U') { now--; } else if (arr[i] == 'D') { now++; } } for (int i = 1; i <= n; i++) { System.out.print(i + " "); } System.out.println(); System.out.println(now); } else { for (int i = 0; i < arr.length; i++) { //当光标在第一行第一个的时候 //向上的话需要换到最后一页 if (list == 1 && now == 1 && arr[i] == 'U') { list = n - 3; now = n; //当光标在最后一行 //向下的话需要换到第一页 } else if (list == n - 3 && now == n && arr[i] == 'D') { list = 1; now = 1; } else if (list != 1 && now == list && arr[i] == 'U') { list--; now--; } else if (list != n - 3 && now == list + 3 && arr[i] == 'D') { list++; now++; } else if (arr[i] == 'D') { now++; } else if (arr[i] == 'U') { now--; } } for (int i = list; i <= list + 3; i++) { System.out.print(i + " "); } System.out.println(); System.out.println(now); } } }
边栏推荐
- [reading notes > statistics] 12-01 construction of confidence interval - Introduction to the concept of confidence interval
- 关于常见排序的稳定性
- Initializing, cleaning up and const decorating member functions of constructors
- Change this point to understand
- The cubic root of a number
- Text align: center centered
- Chapter 3 stack
- 张宇高数30讲总结
- 算法---二维数组网格迁移(Kotlin)
- The author believes that the development logic of the meta universe and the Internet is quite different in Chengdu
猜你喜欢
随机推荐
Brief analysis of several key technical points of traditional bank bill printing system
深度解析kube-scheduler调度上下文
Program environment and pretreatment
自从我使用HiFlow场景连接器后,在也不用担心成为“落汤鸡”了
Cloud computing may become a new inflection point in the era? From which point can we see?
Promise (I)
Internet traffic scheduling scheme
Redis 配置文件
go gin : 多文件上传
Typora set the title to automatically add sequence number
Tensorrt plug-in practice (1)
What should Alibaba cloud international account do if it receives an account risk notification?
Google Earth engine app - a complete map legend app (land use classification of western United States)
获取一个控件宽度
算法---使用最小花费爬楼梯(Kotlin)
Algorithm --- 2D array mesh migration (kotlin)
黑马程序员-接口测试-四天学习接口测试-第二天-接口用例设计,测试点,功能测试,安全测试,性能测试,单接口测试,业务场景测试用例,postman简介,安装
昇思易点通 | 经典卷积神经网络的深度学习解析
Genesis公链:夯实Web 3.0发展底座
C语言函数(1)















