演算法(三十八)

2021-10-04 08:46:28 字數 1183 閱讀 9178

1、使用者模型檔案去重。

抖音上不同的使用者型別我們有不同的使用者模型檔案。我們有乙個模型配置檔案,裡面有很多的不同使用者型別和他們對應的模型檔案。我們需要找出每個模型檔案對應的是哪些使用者型別。

給定一行輸入,格式為:

a ba表示這個使用者的使用者型別,b表示這個使用者對應的模型檔案。請你輸出每個模型檔案對應的使用者型別。

注意:每個模型檔案可能對應多個使用者型別,使用者型別之間用空格作為切分。

注意2:如果有多個使用者型別輸出,使用者型別之間的排序按照字母表排序。

eg:輸入:

abc 1.txt

輸出如下:

1.txt abc

public class test020 

}for(map.entry> entry: map.entryset())

}}

2、 貪心演算法,補給飲用水

假設你要從0點開始沙漠旅行到終點d,總共d個站點,每走一公里消耗一公升的水量,初始攜帶的水量為w,但是在路途中是可以補給到一些水的,這些站點的位置在pos陣列中給出,在sup陣列的對應位置給出了在站點能獲得的水量多少。即:在pos[i] 站點能獲得的水量為sup[i],現在要求最少需要加多少次水,如果在路途中會被渴死,直接返回-1

public class test021 

for(int i=0; i<3; i++)

system.out.print(d+" ");

system.out.print(w);

system.out.println();

for (int j=0; j<3; j++)

system.out.println();

for (int k=0; k<3; k++)

system.out.println();

int res = solve(d, w, pos, sup);

system.out.println("次數最少為:"+res+"次");

}public static int solve(int d, int w, int pos, int sup)

}// 沒水了,而且也沒有水站可以取水,可能在路途上被渴死

if(maxindex==-1) return -1;

used[maxindex] = true;

res++;

}return res;

}}

每日演算法之三十八 Anagrams

given an array of strings,return all groups of strings that are anagrams.note all inputs will be in lower case.回文字串是指 兩個字串的字元個數全然同樣,這兩個字串是anagrams。因此a...

每日演算法之三十八 Anagrams

given an array of strings,return all groups of strings that are anagrams.note all inputs will be in lower case.回文字串是指 兩個字串的字元個數全然同樣,這兩個字串是anagrams。因此a...

(三十八)會話Session

說起會話,我們經常登入到linux系統,執行各種各樣的程式,這都牽涉到會話。但是,一般情況下我們又很少會去關注到會話的存在,很少會去了解它的來龍去脈。維繫乙個會話,最常見的有兩種方式 一是基於某種憑證,比如web 的登入會話,在登入驗證之後,伺服器就會返回乙個session id作為憑證。使用者之後...