classSolution{public:longlongmaximumTripletValue(vector<int>& nums){vector<longlong> num;for(auto&item:nums){num.push_back(item*1ll);}longlong z =0,f =1000000;longlong ans =0;longlong maxx = num[0],minn = num[0];for(int i =1;i < nums.size();i ++){if(i >1){if(nums[i]>0){ans =max(ans,num[i]*z);}else{ans =max(ans,num[i]*f);}}z =max(z,maxx-num[i]);f =min(f,minn-num[i]);minn =min(minn,num[i]);maxx =max(maxx,num[i]);}return ans;}};
有序三元组中的最大值 II
classSolution{public:longlongmaximumTripletValue(vector<int>& nums){vector<longlong> num;for(auto&item:nums){num.push_back(item*1ll);}longlong z =0,f =1000000;longlong ans =0;longlong maxx = num[0],minn = num[0];for(int i =1;i < nums.size();i ++){if(i >1){if(nums[i]>0){ans =max(ans,num[i]*z);}else{ans =max(ans,num[i]*f);}}z =max(z,maxx-num[i]);f =min(f,minn-num[i]);minn =min(minn,num[i]);maxx =max(maxx,num[i]);}return ans;}};
无限数组的最短子数组
题意
思路 把target/nums_sum 个数加上,剩下的就是拼接一下找最短子数组
classSolution{public:intminSizeSubarray(vector<int>&nums,int target){longlong total =accumulate(nums.begin(), nums.end(),0LL);int n = nums.size();int ans = INT_MAX;int left =0;longlong sum =0;for(int right =0; right < n *2; right++){sum += nums[right % n];while(sum > target % total){sum -= nums[left++% n];}if(sum == target % total){ans =min(ans, right - left +1);}}return ans == INT_MAX ?-1: ans + target / total * n;}};
有向图访问计数(待补)
题意
思路
代码
classSolution{public:vector<int>countVisitedNodes(vector<int>& edges){int n = edges.size();// e[sn] 表示从 sn 出发的反向边(即原图以 sn 为终点的边)vector<int> e[n];for(int i =0; i < n; i++) e[edges[i]].push_back(i);// vis 数组用来求环长int vis[n];memset(vis,0,sizeof(vis));// dis[i] 表示从点 i 走到环上的距离int dis[n];memset(dis,-1,sizeof(dis));vector<int>ans(n);// 对每个连通块分别求答案for(int S =0; S < n; S++)if(dis[S]==-1){// 从任意一点出发,都能走到环上,模拟求环长int now = S, cnt =1;for(; vis[now]==0; now = edges[now], cnt++) vis[now]= cnt;int loop = cnt - vis[now];// 从环上每个点开始,在反向边上 bfs,求每个点走到环上的距离queue<int> q;q.push(now); dis[now]=0;for(int sn = edges[now]; sn != now; sn = edges[sn]) q.push(sn), dis[sn]=0;while(!q.empty()){int sn = q.front(); q.pop();// 答案就是环长 + 走到环上的距离ans[sn]= dis[sn]+ loop;for(int fn : e[sn])if(dis[fn]==-1){q.push(fn);dis[fn]= dis[sn]+1;}}}return ans;}};
关闭进程:
stop-dfs.sh
格式化:
hadoop namenode -format
出现报错信息:
23/10/03 22:27:04 WARN fs.FileUtil: Failed to delete file or dir [/usr/data/hadoop/tmp/dfs/name/current/fsimage_0000000000000000000.md5]: it still exi…
1、加噪过程
1、将 图像 x 0 x_0 x0 像素值映射到 [-1, 1] 之间 x 255 2 − 1 , w h e r e x 为图像中的像素值 \quad \frac{x}{255} \times 2-1, \quad where \; x 为图像中的像素值 255x2−1,wherex为图像中的像素值 \quad
2、生成一张尺寸相同的噪声图片,像…