跳至主要内容

博文

目前显示的是 四月, 2020的博文

在console打印字符串中乱码的解决方法

std::string safeprint(const std::string &str) {     std::string ret;     for (int i = 0; i < str.length(); ++i) {         unsigned char byte = str[i];         if ((byte >= 32 && byte <= 126) || ispunct(byte)) {             ret += byte;         } else {             ret += "\\" + std::to_string(byte);         }     }     return ret; }

简单的整数最小乘积的解法

给定 n 个整数,每次可以从剩下的整数中取走两个整数并计算这两个整数的积。 若该操作进行 m 次,求每次计算的积之和的最小值。 Input / 输入格式 有多组测试数据。第一行输入一个整数 T(约 30)代表测试数据组数,对于每组数据: 第一行输入两个整数 n 和 m(1≤n≤10​5​​, 0≤m≤​2​​n​​),它们的含义如题中所述。 第二行输入 n 个整数 a​1​​,a​2​​,⋯,a​n​​(0≤a​i​​≤10​4​​)表示给定的整数。 Output / 输出格式 每组数据输出一行一个整数,表示积之和的最小值。 Sample Input / 样例输入 3 4 2 1 3 2 4 3 1 2 3 1 4 0 1 3 2 4 Sample Output / 样例输出 10 2 0   Hint / 样例说明 对于第一组样例数据,答案是 1×4+3×2=10。 对于第二组样例数据,答案是 2×1=2。 package main import (         "bufio"         "fmt"         "os"         "sort"         "strconv"         "strings" ) var data []int var n int func dodo(datastr string, m int) {         if m == 0 {                 fmt.Printf("%d\n", 0)                 return         }         data = data[0:0]         for _, s := range strings.Split(datastr, " ") {                 n, _ := strconv.Atoi(s)                 data = append(data, n)         }         sort.Ints(data)         n = len(data)       

简单的整数相减题目的解法

给定 n 个整数,每次可以进行如下操作:选择其中最大的整数 a 与最小的整数 b,并将它们都替换为 (a−b)。 是否可以在有限次操作内使得所有整数都相等?如果是,最后的结果是什么? 有多组测试数据。第一行输入一个整数 T(约 20)代表测试数据组数。对于每组测试数据: 第一行输入一个整数 n(2≤n≤10)代表给定整数的数量。 第二行输入 n 个整数 a​1​​,a​2​​,⋯,a​n​​(−10​5​​≤a​i​​≤10​5​​)代表给定的整数。 每组数据输出一行。若可以将所有整数变为相等,输出最终产生的那个整数;否则输出 "Impossible"(不输出引号)。 Sample Input / 样例输入 2 3 1 2 3 2 5 5 Sample Output / 样例输出 2 5 package main import (         "bufio"         "container/heap"         "fmt"         "os"         "strconv"         "strings" ) // An IntHeap is a min-heap of ints. type MinIntHeap []*Item func (h MinIntHeap) Len() int           { return len(h) } func (h MinIntHeap) Less(i, j int) bool { return h[i].value < h[j].value } func (h MinIntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i]; h[i].IndexMin, h[j].IndexMin = i, j } func (h *MinIntHeap) Push(x interface{}) {         // Push and Pop use pointer receivers becaus

ubuntu 添加root登录

Login to your server as root. As the root user, edit the sshd_config file found in  /etc/ssh/sshd_config : vim /etc/ssh/sshd_config ( For details on working with Vim check out our article here !) Add the following line to the file, you can add it anywhere but it’s good practice to find the block about authentication and add it there. PermitRootLogin yes Save and exit the file. Restart the SSH server: systemctl restart sshd or service sshd restart

raspberry的netplan设置

WPA2 Personal network: version: 2 wifis: wlan0: renderer: NetworkManager match: {} dhcp4: true access-points: "wpa2 network": password: "Our passphrase for our network" Open network network: version: 2 wifis: wlan0: renderer: NetworkManager match: {} dhcp4: true access-points: "open network": {}       $ sudo netplan –debug try $ sudo netplan –debug generate $ sudo netplan –debug apply      sudo reboot  

windows卡顿排查

To diagnose the CPU usage issues, you should use Event Tracing for Windows (ETW) to capture CPU Sampling data / Profile. To capture the data, install the Windows Performance Toolkit , which is part of the Windows SDK . The Windows 10 WPT can be used on Windows 8/Server 2012, Windows 8.1/Server 2012R2 and Windows 10/Server 2016. If you still use Windows 7, use the SDK/WPT with Build 15086 . (all other entries can be unselected) Now run WPRUI.exe , select First Level , under Resource select CPU usage and click on start . Now capture 1 minute of the CPU usage. After 1 minute, click on Save . Now analyze the generated ETL file with the Windows Performance Analyzer by dragging and dropping the CPU Usage (sampled) graph to the analysis pane and ordering the columns like you see in the picture: Inside WPA, load the debug symbols and expand Stack of the SYSTEM process. In this demo, the CPU usage comes from the nVIDIA driv