hdu 1050 (preinitilization or postcleansing, std::fill) 分类: hdoj 2015-06-18 11:33 34人阅读 评论(0) 收藏

时间:2021-04-29 16:45:45

errors, clauses in place, logical ones, should be avoided.

#include <cstdio>
#include <cstring>
#include <algorithm>

int main() {
    //freopen("input.txt","r",stdin);
    const int CorNum=201;
    int ncase, npair, to,from, first,last, res;
    int shared[CorNum]={0};
    if(scanf("%d",&ncase)!=1) return -1;
    while(ncase-- && scanf("%d",&npair)==1) {
        first=CorNum, last=0;
        while(npair--) {
            scanf("%d%d",&from,&to);
            from=(from-1)>>1; to=(to-1)>>1;
            if(from>to) std::swap(from,to);
            first=std::min(first,from); last=std::max(last,to);
            for(;from<=to;++from) ++shared[from];
        }
        for(res=0,from=first;from<=last;++from) res=std::max(res,shared[from]);
        std::fill(&shared[first],&shared[last+1],0);
        printf("%d\n",res*10);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。// p.s. If in any way improment can be achieved, better performance or whatever, it will be well-appreciated to let me know, thanks in advance.