zoukankan      html  css  js  c++  java
  • 笔记

    1.long long 输入用%lld 输出用%I64d

    (注:今天发现有的输出还得用lld。。。与编译器有关,自己谨慎使用。)

    2.数据输入加速(g++)

    适用于正整数

    //适用于正整数
    template <class T>
    inline void scan_d(T &ret) {
        char c; ret=0;
        while((c=getchar())<'0'||c>'9');
        while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();
    }
    View Code

    适用于正负整数

    //适用于正负整数
    template <class T>
    inline bool scan_d(T &ret) {
       char c; int sgn;
       if(c=getchar(),c==EOF) return 0; //EOF
       while(c!='-'&&(c<'0'||c>'9')) c=getchar();
       sgn=(c=='-')?-1:1;
       ret=(c=='-')?0:(c-'0');
       while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
       ret*=sgn;
       return 1;
    }
    View Code

    适用于正负数,(int,long long,float,double)

    //适用于正负数,(int,long long,float,double)
    template <class T>
    bool scan_d(T &ret){
        char c; int sgn; T bit=0.1;
        if(c=getchar(),c==EOF) return 0;
        while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
        sgn=(c=='-')?-1:1;
        ret=(c=='-')?0:(c-'0');
        while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
        if(c==' '||c=='
    '){ ret*=sgn; return 1; }
        while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
        ret*=sgn;
        return 1;
    }
    View Code

    ④out

    inline void out(int x) {
       if(x>9) out(x/10);
       putchar(x%10+'0');
    }
    View Code

    3.手动扩大栈内存(c++)

    #pragma comment(linker, "/STACK:102400000,102400000")

    4.数组开辟太大也浪费时间。

    见例题:

  • 相关阅读:
    ReentrantReadWriteLock读写锁的使用
    Exchanger的使用
    CyclicBarrier的用法
    Semaphore的使用
    CountDownLatch的使用
    BlockingQueue的使用
    对字符串操作的各种笔试题
    struts2请求过程源码分析
    shell语法使用
    hibernate调用mysql存储过程
  • 原文地址:https://www.cnblogs.com/gongpixin/p/4743453.html
Copyright © 2011-2022 走看看