当前位置:网站首页>21st day of written test mandatory training
21st day of written test mandatory training
2022-07-24 03:18:00 【Curry won't throw three points】
choice question
- Although the single linked list can be located by binary search , But the insertion may only be head or tail , So you still need to traverse
![]()
- Loading factor = Valid elements / The length of the array , Load factor increases , There should be more effective elements , Or the array length becomes smaller , That one will increase the probability of conflict
Programming questions
![]()
- This problem is to find rules , After reading one number at a time , Figure out how he passed k Position after the second shuffle , Use only one length 2n Arrays are used to output According to the position of the current number , You can calculate the position after a shuffle if the current number is less than or equal to n( In the left hand ), Then the position of his next appearance is 2* The current position The corresponding current position + n( In the right hand ) The card of , Then the position of his next appearance is 2* The current position + 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(); } }
- This problem is completely handled according to the situation , First, it is divided into two major situations 1 Characters less than or equal to 4( There will be no skipping to the last page , And the question on the first page , There is no need to deal with the problem of changing pages )2 Characters greater than or equal to 4
- Characters greater than or equal to 4 There are many kinds of situations 1 Skip from the first page to the last 2 Skip from the last page to the last page 3 Refresh the first line The whole page moves down one grid 4 Refresh the last line in , The whole page moves up one space 5 Normal cursor down , Do not refresh page 6 Normal cursor moves up , Do not refresh page
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++) { // When the cursor is on the first line // If you go up, you need to change to the last page if (list == 1 && now == 1 && arr[i] == 'U') { list = n - 3; now = n; // When the cursor is on the last line // If you go down, you need to change to the first page } 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); } } }
边栏推荐
- C dynamic memory management details
- 正则表达式 \b \B 深入浅出理解单词边界的匹配
- I developed an app similar to wechat runnable applet with fluent
- Data Lake: introduction to Apache Hudi
- The process of solving a bug at work
- Jump statements break and continue
- Lumberyard game engine of o3de
- kettle
- uva1344
- Hcip day 10 (initial BGP border gateway protocol)
猜你喜欢

Take you into the world of MySQL mvcc

MySQL sub database and sub table and its smooth expansion scheme

Gpushare. COM | how to use tensorboardx visualization tool?
![[hdlbits questions] Verilog language (2) vectors](/img/eb/125c9a7781391dc53e37ce347a475d.png)
[hdlbits questions] Verilog language (2) vectors

数据湖:Apache Hudi简介
![[MySQL learning] install and use multiple versions of MySQL, MySQL 8 and MySQL 5.7 at the same time, compressed version](/img/08/3765b34809cc4c723608f5d2e86ed4.png)
[MySQL learning] install and use multiple versions of MySQL, MySQL 8 and MySQL 5.7 at the same time, compressed version

正则表达式 \b \B 深入浅出理解单词边界的匹配

IDEA Clone的项目报Cannot resolve symbol ‘Override‘

An introductory example of structure and combinatorial ideas in go language

Realize the communication before two pages (using localstorage)
随机推荐
MySQL sub database and sub table and its smooth expansion scheme
Keras deep learning practice (15) -- realize Yolo target detection from scratch
uva11389
Secondary development of ArcGIS JS API -- loading national sky map
Services et configurations FTP
The function of SIP account - tell you what is SIP line
Error code 0x80004005
Is it safe for qiniu to open an account? Is the Commission of 30000 reliable?
New definition of mobile communication: R & scmx500 will improve the IP data throughput of 5g devices
Microsoft win11/10 package manager Winget will support the installation of applications from zip files
Take you into the world of MySQL mvcc
C自定义类型详解
正则表达式 \b \B 深入浅出理解单词边界的匹配
Ways to improve the utilization of openeuler resources 01: Introduction
The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"
IDEA Clone的项目报Cannot resolve symbol ‘Override‘
I developed an app similar to wechat runnable applet with fluent
FTP服务与配置
Water topic: connect rainwater
How to implement desktop lyrics in pyqt





