5萬多個文件渲染成功了4萬多個,我寫了個程序把它們合并到2560*2560的png圖里,每個圖有128*128圖標400個,伴隨一個.c文件指定了圖標實際大小,比如
置頂隨筆 #
5萬多個文件渲染成功了4萬多個,我寫了個程序把它們合并到2560*2560的png圖里,每個圖有128*128圖標400個,伴隨一個.c文件指定了圖標實際大小,比如
2016年11月15日 #
2016年7月24日 #
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.
For example,
Given nums = [1,3,-1,-3,5,3,6,7]
, and k = 3.
Window position Max
--------------- -----
[1 3 -1] -3 5 3 6 7 3
1 [3 -1 -3] 5 3 6 7 3
1 3 [-1 -3 5] 3 6 7 5
1 3 -1 [-3 5 3] 6 7 5
1 3 -1 -3 [5 3 6] 7 6
1 3 -1 -3 5 [3 6 7] 7
Therefore, return the max sliding window as [3,3,5,5,6,7]
.
Note:
You may assume k is always valid, 1 ≤ k ≤ input array's size.
Follow up:
Could you solve it in linear time?
Hint:
- How about using a data structure such as deque (double-ended queue)?
- The queue size need not be the same as the window’s size.
- Remove redundant elements and the queue should store only elements that need to be considered.
大意是用雙向隊列可以n的線性時間.網友的解法意思是前端移出了滑動窗口的元素要移除
然后新指向的元素和隊列尾部元素比較,尾部小的元素也要移除.這樣保持隊列總是在滑動窗口里從大到小排好.
個人覺得當k比較大而輸入元素基本隨機時不可能是n復雜度.而應該是(k/2)*n左右
所以我的解法干脆用兩個指針:最大值,第二大值來維護.實際運行還比雙端隊列快一點點.(92ms 擊敗90%)
if(nums.size()<2)return nums;
size_t n=nums.size(), maxv=0,secondv=~0;
vector<int> out;
//secondv維持第二大的元素.如果maxv在窗口邊界,secondv就是魔術~0代表不存在第二小元素.
for(size_t i=1;i<k;++i)
{
if(nums[i]>nums[maxv]){
maxv=i;
secondv=~0;
}else if(secondv==~0||nums[i]>nums[secondv]){
secondv=i;
}
}
out.push_back(nums[maxv]);
for(size_t i=k;i<n;++i)
{
if(maxv<=i-k)
{
if(secondv==~0){
maxv=i;
}else{
maxv=secondv;
secondv=secondv+1;
//maxv移出滑動窗口時,如果secondv存在,顯然要更新它找出新的第二大元素.
for(size_t j=secondv+1;j<i;++j)
if(nums[j]>nums[secondv])secondv=j;
}
}
if(nums[i]>nums[maxv]){
maxv=i;
secondv=~0;
}else if(secondv==~0||nums[i]>nums[secondv]){
secondv=i;
}
out.push_back(nums[maxv]);
}
return out;
}
2016年3月27日 #
2016年3月26日 #
2016年3月17日 #
2014年3月16日 #
5萬多個文件渲染成功了4萬多個,我寫了個程序把它們合并到2560*2560的png圖里,每個圖有128*128圖標400個,伴隨一個.c文件指定了圖標實際大小,比如
2013年6月30日 #
就一個main.cpp文件的程序,用了freetype庫和freeimage庫,打開codeblocks工程時注意改這些庫的路徑.
http://m.shnenglu.com/Files/FireEmissary/font2img2.zip
2013年3月10日 #
2012年9月12日 #
有了lambra和std::function,寫和界面有關的代碼回調方便多了.為了界面布局生成了大量的窗口,程序和小但也許比較占系統資源.
這程序比較包括了白酒領域相關的酒精度數轉換,酒度體積百分比和質量百分比兩個數據文件,是我根據網上的word文檔轉碼成txt再觀察結構,刪掉干擾部分然后
寫個數據讀取程序轉換而成;自己敲成代碼可沒這么輕松.
有需要的人士可以放心使用我的代碼和程序.完全免費(MIT許可)
2012年6月28日 #
中配置這些庫路徑.于是寫了個shell腳本如下:
baselib=`dirname $0`
if [ $baselib = '.' ];then
baselib=`pwd`
fi
echo baselib:$baselib
for file in ./*;
do
if test -d $file;then
echo into

cd $file
if test -e ./configure;then
`./configure --prefix=${baselib}/alllibs`
`make`
`make install`
fi
cd ..
fi
done
意思就是加入你把依賴庫都放在某個目錄下的話,腳本進入該目錄的所有子目錄,找configure文件,找到了就./configure make make install了.configure特意指定安裝目錄到工作目錄的alllibs下.
我試了試GraphicsMagick-1.3.16(下的就是那個zip壓縮的帶依賴庫的版本).哈,成功兩個:freetype(ttf目錄那個)和jasper(jp2目錄那個).其它的不成功,不過錯誤信息太深奧我不太懂,有改進的也像我一樣分享下哈.