#include <iostream> #include <thread> #include <mutex> std::timed_mutex mutex; void mythread() { std::chrono::milliseconds timeout(100); //100ms std::chrono::milliseconds sleep(100); while(true) { //if(mutex.try_l
模拟出五个小朋友给相邻的分糖,/3有余数舍弃 #include<bits/stdc++.h>using namespace std;int main(){ int a[7],i,j; for(i=1;i<=5;i++){ cin>>a[i]; } j=a[1]/3; a[1]=j; a[5]=a[5]+j; a[2]=a[2]+j; for(i=2;i<=4;i++){ j=a[i]/3; a[i]=j; a[i+1]=a[i+1]+j; a
给能够到的高度加30,依次比较 #include<bits/stdc++.h>using namespace std;int main(){ int a[17],i,j,s=0; for(i=1;i<=10;i++){ cin>>a[i]; } cin>>j; j=j+30; for(i=1;i<=10;i++){ if(a[i]<=j){ s++; } } cout<<s;}
用分离法得出每位上的2 #include<bits/stdc++.h>using namespace std;int main(){ int l,i,r,s=0,j; cin>>l>>r; for(i=l;i<=r;i++){ j=i; while(j>0){ if(j%10==2){ s++; } j=j/10; } } cout<<s;}
模拟出每天骑士获得的金币,加起来 #include<bits/stdc++.h>using namespace std;int main(){ int n,i,j=0,s=0,bj=1; cin>>n; for(i=1;i<=n;i++){ j++; s=s+bj; if(j==bj){ bj++; j=0; } } cout<<s;}
咕咕咕咕。 E - Sugoroku 3 反着跑DP,或者说逆向归纳。 记从\(i\)开始走到\(n\)的期望步数为\(dp_i\)。易得\(dp_n = 0\),然后\(dp_i\)可以由\(dp_{j}, i + 1 \le j \le i + a_i\)推出,从后往前推即可算出\(dp_1\),也就是答案。 具体就是假设摇骰子摇到\(x\),那么就可以花\(1\)步走到\(
泛型 什么是泛型,泛型的作用,泛型的优势等本文不做介绍,本文只将泛型在 Rust 当中的使用方法. 泛型方法 一个比较两个数大小的并返回其中较大的一个数: fn larget<T: std::cmp::PartialOrd>(a: T, b: T) -> T { if a >= b { a } else { b } } 泛型
#include <bits/stdc++.h> #define debug(x) std::cerr << "[" << __LINE__ << "]: " << #x << " = " << x << "\n" using i64 = long long; const int N = 300 + 5;
概念 std::move:无条件把参数转换为右值; std::forward:根据实参类型决定传递给下一层function的参数类型使用;被称为完美转发 (也叫精确传递); std::forward比较多的是配合 T&& 使用(使用在template代码中);其作用之一是将参数本层调用传递给下一层调用。 void log_and_consume(std::st
Zig 中做Md5 和 Sha1 之类的Hash 非常简单的,现在支持Hash 算法有,blanke2、Blanke3、Gimli、Md5、Sha1、sha2、sha3,还有一个 组合 composition。 Md5 pub fn md5() void { const Md5 = std.crypto.hash.Md5; var out: [Md5.digest_length]u8 = undefined; const inpu
#include <iostream> #include <Windows.h> #include <string> using namespace std; int main() { int n; int ret[32]; int i = 0; cout << "请输入一个正整数:"; cin >> n; if (n < 0) { cout <&
#include <iostream> #include <windows.h> #include <string> using namespace std; int main() { int row; cout << "请输入行数:"; cin >> row; for (int i = 1; i <= row; i++) { for (int k = 0; k <
#include <iostream> #include <future> int mythread() { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::chrono::milliseconds second(3000); std::this_thread::sleep_for(second); r
#include <iostream> #include <Windows.h> #include <string> using namespace std; int main() { int n; long long s; long long a = 1; long long b = 1; cout << "请输入斐波那契数列的个数:"; cin >> n; if (n
#include <iostream> #include <future> int mythread() { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::chrono::milliseconds second(3000); std::this_thread::sleep_for(second); r
今天,我要开始整一下无聊题解,小白们,看过来! 先说第一道题: 时间:1000ms 运行时的内存:262144kb 输入格式: 一行,有两个空格隔开的整数 样例输入: 1 2 样例输出: 3 这道题就是一道新手必刷题,那么先让我们来看一下A掉的代码: #include<bits/stdc++.h> using namespace std; int main(){
所有题目都在橙到绿之间。梦回小学。 UVA [101] - The Blocks Problem 用一个前驱数组和一个后继数组维护一个类似于链表的结构。 然后每次更改根据题意要求,依次递进地更改结点的前驱 / 后继即可。 namespace XSC062 { using namespace fastIO; const int maxn = 35; char t, t1
在 java 上进行 AES128/ECB/PKCS5Padding 加密解密是很简单的 public static String aesDecrypt(String str,String key) throws Exception{ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE,new SecretKeySp
话不多说,直接上示例代码 std::string Base64Encode(const unsigned char* data, size_t size) { size_t base64_len = (size + 2) / 3 * 4; if (base64_len == 0) { return ""; } std::string ret; ret.resize(base64_len); EVP_EncodeBl
#include <iostream> #include <mutex> #include <thread> std::mutex mutex; void msg_func() { std::unique_lock<std::mutex> unique(mutex, std::defer_lock); unique.lock(); while(1) { std::cout << "do some
#include <iostream> #include <mutex> #include <thread> std::mutex mutex; void msg_func() { std::unique_lock<std::mutex> unique(mutex); while(1) { std::cout << "do something" << std::endl;
#include <iostream> #include <mutex> #include <thread> std::mutex mutex; void msg_func() { mutex.lock(); std::unique_lock<std::mutex> unique(mutex, std::adopt_lock); while(1) { std::cout << "do somet
#include <iostream> #include <mutex> #include <thread> std::mutex mutex; void msg_func() { std::lock_guard<std::mutex> guard(mutex); while(1) { std::cout << "do something" << std::endl;
// Online C++ compiler to run C++ program online #include <iostream> struct Base { virtual void print_val() { std::cout << val << std::endl; } double val; int num; }; struct A final : Base { void print_val()
字符串算法,随便学一下。 Trie树 字典树,用来求前缀的匹配。 比较简单,每一个字符都是一个节点,相同字符都是相同节点,然后就完了。 我们可以设这里插入的字符串分别是 abc cab bac bca 这就是 Trie 构造出来的样子,是不是一下就懂了?我们查询的时候根据这个树跳就完了。 代码也很好实