My Templet

线段树:

/*
#define maxn 1000005
int gnode[maxn];
long long gnum[maxn*4];

the segment gnum must full binary tree,
the left child is loc*2+1,
and the right child is loc*2+2.
*/

void GxdSegmentTreeAdd(long long* gnum,int glen,int gfl,int gfr,int gnow,int gkeyloc)
{
    gnum[gnow]++;
    if(gfl==gfr) return ;
    int mid = (gfl+gfr)/2;
    if(gkeyloc>mid) GxdSegmentTreeAdd(gnum,glen,mid+1,gfr,gnow*2+2,gkeyloc);
    else GxdSegmentTreeAdd(gnum,glen,gfl,mid,gnow*2+1,gkeyloc);
}

long long GxdSegmentTreeSearch(long long* gnum,int glen,int gfl,int gfr,int gnow,int gkeyl,int gkeyr)
{
    if(gfl==gkeyl&&gfr==gkeyr) return tree[gnow];
    int mid = (gfl+gfr)/2;
    if(gkeyl>mid) return GxdSegmentTreeSearch(gnum,glen,mid+1,gfr,gnow*2+2,gkeyl,gkeyr);
    else if(gkeyr<=mid) return GxdSegmentTreeSearch(gnum,glen,gfl,mid,gnow*2+1,gkeyl,gkeyr);
    else return GxdSegmentTreeSearch(gnum,glen,gfl,mid,gnow*2+1,gkeyl,mid)+GxdSegmentTreeSearch(gnum,glen,mid+1,gfr,gnow*2+2,mid+1,gkeyr);
}

结构体排序:

struct Node{
    int c;
    int v;
};

Node num[maxn];

int cmp(const void* a,const void* b)
{
    Node *x = (Node*)a;
    Node *y = (Node*)b;
    return x->v - y->v; //ascend sort
}
qsort(num,n,sizeof(num[0]),cmp);

Vector容器迭代:

vector<string> cnt;
string ansstr;
for(auto str:cnt)
{
    if(ans[str] > maxnum)
    {
        maxnum = ans[str];
        ansstr = str;
    }
}

运算符重载:

struct Pallet
{
public:
    int l;
    int w;
public:
    void init(int a,int b){l=max(a,b);w=min(a,b);}
    bool operator == (const Pallet& t){if(t.l==l&&t.w==w) return true;return false;}
};

重定向:

#ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    fclose(stdin);
    fclose(stdout);
#endif

整行读取:

//使用fgets(buf,maxn,stdin);来读取一整行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值