【2021】阿里巴巴编程题
子集
链接:https: / / www. nowcoder. com/ questionTerminal/ a55198d2e65746009110226f2f6c8533
来源:牛客网
import java. io. * ;
import java. util. * ;
public class Main {
private static Comparator < int [ ] > comparator = new Comparator < int [ ] > ( ) {
@Override
public int compare ( int [ ] o1, int [ ] o2) {
if ( o1[ 0 ] > o2[ 0 ] ) return 1 ;
else if ( o1[ 0 ] < o2[ 0 ] ) return - 1 ;
else {
if ( o1[ 1 ] > o2[ 1 ] ) return - 1 ;
else if ( o1[ 1 ] == o2[ 1 ] ) return 0 ;
else return 1 ;
}
}
} ;
public static void main ( String [ ] args) throws IOException {
BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in) ) ;
String str = bf. readLine ( ) ;
int n = Integer . parseInt ( str) ;
for ( int i = 0 ; i < n; i++ ) {
String str1 = bf. readLine ( ) ;
int m = Integer . parseInt ( str1) ;
String [ ] str2 = bf. readLine ( ) . split ( " " ) ;
String [ ] str3 = bf. readLine ( ) . split ( " " ) ;
int [ ] [ ] items = new int [ m] [ 2 ] ;
for ( int j = 0 ; j < m; j++ ) {
items[ j] = new int [ ] { Integer . parseInt ( str2[ j] ) , Integer . parseInt ( str3[ j] ) } ;
}
Arrays . sort ( items, comparator) ;
int res = 1 ;
int [ ] [ ] dp = new int [ m + 1 ] [ 2 ] ;
dp[ 1 ] = items[ 0 ] ;
for ( int j = 1 ; j < m; j++ ) {
if ( dp[ res] [ 1 ] < items[ j] [ 1 ] ) dp[ ++ res] = items[ j] ;
else if ( dp[ res] [ 1 ] > items[ j] [ 1 ] ) {
int l = 1 , r = res, pos = 0 ;
while ( l <= r) {
int mid = ( l + r) >> 1 ;
if ( dp[ mid] [ 1 ] < items[ j] [ 1 ] ) {
pos = mid;
l = mid + 1 ;
} else {
r = mid - 1 ;
}
}
if ( dp[ pos] [ 0 ] != items[ j] [ 0 ] ) dp[ pos + 1 ] = items[ j] ;
}
}
System . out. println ( res) ;
}
}
}
SQL刷题
185. 部门工资前三高的所有员工
SELECT
Department. NAME AS Department,
e1. NAME AS Employee,
e1. Salary AS Salary
FROM
Employee AS e1, Department
WHERE
e1. DepartmentId = Department. Id
AND 3 > ( SELECT count ( DISTINCT e2. Salary )
FROM Employee AS e2
WHERE e1. Salary < e2. Salary AND e1. DepartmentId = e2. DepartmentId )
ORDER BY Department. NAME, Salary DESC ;
华为机试
HJ19 简单错误记录
import java. util. LinkedHashMap ;
import java. util. Map ;
import java. util. Scanner ;
public class Main {
public static void main ( String [ ] args) {
Scanner sc= new Scanner ( System . in) ;
Map < String , Integer > map= new LinkedHashMap < String , Integer > ( ) ;
while ( sc. hasNext ( ) ) {
String str= sc. next ( ) ;
int linenum= sc. nextInt ( ) ;
String [ ] arr= str. split ( "\\\\" ) ;
String s= arr[ arr. length- 1 ] ;
if ( s. length ( ) > 16 )
s= s. substring ( s. length ( ) - 16 ) ;
String key= s+ " " + linenum;
int value= 1 ;
if ( map. containsKey ( key) )
map. put ( key, map. get ( key) + 1 ) ;
else {
map. put ( key, value) ;
}
}
int count= 0 ;
for ( String string: map. keySet ( ) ) {
count++ ;
if ( count> ( map. keySet ( ) . size ( ) - 8 ) )
System . out. println ( string+ " " + map. get ( string) ) ;
}
}
}