ICode9

精准搜索请尝试: 精确搜索
  • C++ timed_mutex2022-08-13 13:31:01

    #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

  • 一本通 例2.17 分糖果2022-08-13 08:33:03

    模拟出五个小朋友给相邻的分糖,/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

  • [2005年NOIP普及组] 陶陶摘苹果2022-08-13 08:32:29

    给能够到的高度加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;}

  • [2010年NOIP普及组] 数字统计2022-08-13 08:30:40

    用分离法得出每位上的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;}

  • [2015年NOIP普及组] 金币2022-08-13 08:30:18

    模拟出每天骑士获得的金币,加起来 #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;}

  • AtCoder Beginner Contest 2632022-08-13 00:34:24

    咕咕咕咕。 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 基础(06) 泛型2022-08-12 00:02:24

    泛型 什么是泛型,泛型的作用,泛型的优势等本文不做介绍,本文只将泛型在 Rust 当中的使用方法. 泛型方法 一个比较两个数大小的并返回其中较大的一个数: fn larget<T: std::cmp::PartialOrd>(a: T, b: T) -> T { if a >= b { a } else { b } } 泛型

  • P2014 [CTSC1997] 选课 -树形dp2022-08-10 22:34:32

            #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及使用2022-08-10 21:32:42

    概念 std::move:无条件把参数转换为右值; std::forward:根据实参类型决定传递给下一层function的参数类型使用;被称为完美转发 (也叫精确传递); std::forward比较多的是配合 T&& 使用(使用在template代码中);其作用之一是将参数本层调用传递给下一层调用。 void log_and_consume(std::st

  • 【Zig】Zig 中 Hash 的使用,如 Md5、Sha12022-08-10 21:00:36

    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

  • C++用短除法把十进制转换为二进制输出2022-08-08 21:04:53

    #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 <&

  • 输入行数,用C++打印金字塔型星号2022-08-08 19:33:52

    #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 <

  • C++ wait_for2022-08-08 19:03:51

    #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

  • 用C++输出指定项的斐波那契数列2022-08-08 19:01:34

    #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

  • C++异步async2022-08-08 15:00:08

    #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

  • 无聊题解第1期2022-08-08 08:00:08

    今天,我要开始整一下无聊题解,小白们,看过来! 先说第一道题: 时间:1000ms 运行时的内存:262144kb 输入格式: 一行,有两个空格隔开的整数 样例输入: 1 2 样例输出: 3 这道题就是一道新手必刷题,那么先让我们来看一下A掉的代码: #include<bits/stdc++.h> using namespace std; int main(){

  • 归档:220807 | 开门水题:STL 系列模板题2022-08-08 00:32:47

    所有题目都在橙到绿之间。梦回小学。 UVA [101] - The Blocks Problem 用一个前驱数组和一个后继数组维护一个类似于链表的结构。 然后每次更改根据题意要求,依次递进地更改结点的前驱 / 后继即可。 namespace XSC062 { using namespace fastIO; const int maxn = 35; char t, t1

  • C/C++ 使用 openssl 进行 AES/ECB/PKCS5Padding 加密解密2022-08-07 21:05:10

    在 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

  • C/C++ 使用 openssl 进行 base64 编解码2022-08-07 21:02:11

    话不多说,直接上示例代码 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

  • unique_lock加锁defer_lock2022-08-07 13:31:35

    #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

  • unique_lock加锁2022-08-07 13:03:33

    #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;

  • unique_lock加锁adopt_lock2022-08-07 13:00:46

    #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

  • lock_guard加锁2022-08-07 12:35:04

    #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;

  • C++ final的用法2022-08-07 00:00:51

    // 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数和AC自动机2022-08-06 20:02:31

    字符串算法,随便学一下。 Trie树 字典树,用来求前缀的匹配。 比较简单,每一个字符都是一个节点,相同字符都是相同节点,然后就完了。 我们可以设这里插入的字符串分别是 abc cab bac bca 这就是 Trie 构造出来的样子,是不是一下就懂了?我们查询的时候根据这个树跳就完了。 代码也很好实

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有