栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1794 Merging Sequences Pr...

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1794 Merging Sequences Pr...

#include<iostream>#include<string>#include<set>#include<cstdio>#include<cstring>using namespace std;enum {    SIZ = 104,    LIM = 999999999,};int dat[SIZ];struct Node;struct Object {    int hs, sum;    int no;    Node *ptr;    bool operator < (const Object &o) const {        return max(hs, sum + o.hs) < max(o.hs, o.sum + hs);    }};Object sys;struct Node {    int num;    Object obj[SIZ];    void gen(){        int pos = 0, i=0;        memset(obj, 0, sizeof(obj));        while(i < num && dat[i] <= 0){ sys.sum += dat[i]; ++i;        }        while(i < num){ while(i<num&&dat[i]>=0){     obj[pos].hs += dat[i];     obj[pos].sum += dat[i];     ++i; } while(i<num&&dat[i]<=0){     obj[pos].sum += dat[i];     ++i; } obj[pos].ptr = this; obj[pos].no = pos; ++pos;        }        num = pos;    }    int readIn() {        num = 0;        scanf("%d", &dat[num]);        while(dat[num]!=9999 && dat[num]!=-9999){ ++num; scanf("%d", &dat[num]);        }        return dat[num] == 9999;    }};int sn;Node tree[6];void fun(){    set<Object> os;    for (int i=0; i<sn; ++i){        if (tree[i].num){ os.insert(tree[i].obj[0]);        }    }    while(!os.empty()){        Object cur = *os.begin();        os.erase(os.begin());        int hs = sys.sum + cur.hs;        if (hs > sys.hs){ sys.hs = hs;        }        sys.sum += cur.sum;        int no = cur.no + 1;        if (no < cur.ptr->num){ os.insert(cur.ptr->obj[no]);        }    }    printf("%dn", sys.hs);}void readIn(){    memset(&sys, 0, sizeof(sys));    sn = 0;    while(tree[sn].readIn()){        tree[sn].gen();        ++sn;    }    tree[sn].gen();    ++sn;}int main(){    int tn;    scanf("%d", &tn);    while(tn-- > 0){        readIn();        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/369668.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号