注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
先说OA,这个题目网上都有了。赛车手排序问题。我的做法第4个case过不去。但是还是拿到店面了。废话少说,直接上代码。我按照题目提示用buckets做的,buckets的大小会影响test case的通过率,我反复调也过不了第4个。
Mitbbs上还有大神用别的方法做的。
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;
class Racer {
int ID;
long start;
long end;
int score;
public Racer(int id,long start,long end){
this.ID = id;
this.start = start;
this.end = end;
}
public void setscore(int score){
this.score = score;
}
public int getscore(){
return this.score;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int n = Integer.parseInt(line);
//arraylist save all racers records
ArrayList<Racer> A = new ArrayList<Racer>();
while ((line = br.readLine()) != null) {
String[] k = line.split(" ");
Racer r1 = new Racer(Integer.parseInt(k[0]),Long.parseLong(k[1]),Long.parseLong(k[2]));
A.add(r1);
}
//sort the A array by start time decending
Collections.sort(A, new Comparator<Racer>(){
public int compare(Racer r1,Racer r2){
if(r1.start > r2.start)
return -1;
else
return 1;
}
});
//System.out.println("A size is "+A.size());
//System.out.println(A.get(0).ID +" "+A.get(0).start );
//use buckets, split and save all racers' data into buckets, then record the start time range of each bucket
//sort each bucket by endtime
ArrayList<ArrayList<Racer>> Buckets = new ArrayList<ArrayList<Racer>>();
int buck_size = Math.max(1500,(int)Math.sqrt(n));
HashMap<long sentance
get all subsets from query vector
ex:
1 1 0 1 1
的subsets包括
1 0 0 0 0
1 1 0 0 0
.....
search in hashmap2
下面是代码,但是我没写完,比较乱,仅作参考
// process data, step 1
HashMap<String,Integer> map = new HashMap<String,Integer>();
int position = 0;
for(i : Ads) // i is single Ad, Ad.ID, Ad.content
for(k : i.content){
if(!map.containsKey(k)){
map.put(k,position);
position++;
}
}
}
HashMap<Integer,vector[]> map1 = new HashMap<Integer,vector[]>();
for(i : Ads){
int[] vector = new int[set.size()];
for(k : i.content){
vector[map.get(k)] = 1;
}
map1.put(i.ID,vector); //ID=1 vector= 1 1 0 0 ....
}
//step 2
int[] Q_vector = new int[set.size()];
for(i : query){
Q_vector[map.get(i)] = 1;
}
//step 3 build map <vector,List<ID>>
HashMap<vector[],ArrayList<Integer>> map2 = new HashMap<vector[],ArrayList<Integer>>;
for(i : map1.keyValue()){
if(!map2.containsKey(map1.get(i))
map2.put(map1.get(i),new ArrayList
}
最后挂了。
|