首页 > 其他分享 >教我卡常

教我卡常

时间:2023-08-21 13:22:05浏览次数:17  
标签:FastIO char while gc isdigit 卡常

感恩卡常模拟赛。

  1. 使用 \n 而不是 endl
  2. 使用常数而非变量
  3. 不要用那个破 cin 了,现在我们都喜欢快读!
namespace FastIO {
#define iL (1 << 20)
#define gc() ((iS == iT) ? (iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin), (iS == iT) ? EOF : *iS++) : *iS++)
  char ibuf[iL], *iS = ibuf + iL, *iT = ibuf + iL;
  template<class T> inline void read(T &x) {
    char c = gc(); bool f = 0; x = 0;
    while(!isdigit(c)) f |= c == '-', c = gc();
    while(isdigit(c)) x = (x << 1) + (x << 3) + (c & 15), c = gc();
    if(f) x = -x;
  }
#undef iL
#undef gc
}

using namespace FastIO;

标签:FastIO,char,while,gc,isdigit,卡常
From: https://www.cnblogs.com/closureshop/p/17645763.html

相关文章

  • 卡常
    1.调换搜索顺序2.调换枚举顺序3.快读快输4.位运算5.循环展开6.register7.longlong只在必要开8.函数里在if里return9.火车头%:pragmaGCCoptimize(3)%:pragmaGCCoptimize("Ofast")%:pragmaGCCoptimize("inline")%:pragmaGCCoptimize("-fgcse")%:pragmaGCC......
  • PAT_Advanced Level_1080 Graduate Admission(C++_模拟_快排_卡常)
    Itissaidthatin2011,thereareabout100graduateschoolsreadytoproceedover40,000applicationsinZhejiangProvince.Itwouldhelpalotifyoucouldwriteaprogramtoautomatetheadmissionprocedure.Eachapplicantwillhavetoprovidetwograd......
  • unordered_map卡常
    加入头文件<chrono>加入以下哈希函数:structcustom_hash{staticuint64_tsplitmix64(uint64_tx){x+=0x9e3779b97f4a7c15;x=(x^(x>>30))*0xbf58476d1ce4e5b9;x=(x^(x>>27))*0x94d049bb133111eb;returnx^(x......
  • Raid卡常用命令
    1.创建删除raid#点3槽位灯:/opt/MegaRAID/MegaCli/MegaCli64-PDLocate-start-physdrv[32:3]-a0关3槽位灯:/opt/MegaRAID/MegaCli/MegaCli64-PDLocate-stop-physdrv[32:3]-a0#删除raid/opt/MegaRAID/MegaCli/MegaCli64-CfgLdDel-L1-A0L1:1为RIAD组TargetId号......
  • [SPOJ] DIVCNT2 - Counting Divisors (square) (平方的约数个数前缀和 容斥 卡常)
    题目vjudgeURL:​​CountingDivisors(square)​​​Letbethenumberofpositivedivisorsof.Forexample,,and.LetGiven,find.InputFirstlinecontains......
  • 卡常科技:树状数组做线段树 1
    树状数组能维护的东西:单点修改,查前缀和。树状数组1直接朴素前缀和,树状数组2就差分一下。对于线段树1的操作,不好用一个树状数组维护。首先得把区间加给变成单点加......
  • 卡常
    事情起因2023.2.4模拟赛,T3该题当时考场上真的想不出来什么正解,于是就开始打暴力第一次提交结果如下图代码:#include<bits/stdc++.h>usingnamespacestd;typ......
  • 卡常技巧整理
    set/map/pbds::gp_hash_table通常情况下:set<map<gp_hash_table。PNR#4A,就是改用了gp_hash_table才过了。gp_hash_table的使用,见pb_ds库构造函数的时间复杂......
  • 究极卡常
    1.register&static&inline在定义局部非char类型的变量时在前面加入register在局部char类型变量前加入static在非主函数和非递归函数前加入inline2.火车头传......
  • 从 Ynoi2011 初始化 看卡常
    一般情况下,程序运行消耗时间主要与时间复杂度有关,超时与否取决于算法是否正确。但对于某些题目,时间复杂度正确的程序也无法通过,这时我们就需要卡常数,即通过优化一些操作的......