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

zoj 1853 The Brick Stops Here

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

zoj 1853 The Brick Stops Here

#include<iostream>#include<vector>#include<string.h>#include<stdio.h>#include<algorithm>using namespace std;struct Node {    unsigned l, a, b;};vector<unsigned> ptr[21];unsigned num, pos, lvl;unsigned cop[208];unsigned pri[208];Node res[108];unsigned * tab[21];void update(unsigned l, unsigned p, unsigned v){    if(tab[l][p] <= v) return;    tab[l][p] = v;        for(unsigned i=0; i<ptr[l].size(); i++){        if(p>=res[ptr[l][i]].a * l && p<=res[ptr[l][i]].b*l && res[ptr[l][i]].l > v){ res[ptr[l][i]].l = v;        }    }}void fun(){    unsigned i, j, k, lim;    for(i=1; i<=lvl; i++){        memset(tab[i], -1, sizeof(unsigned)*(i*1008));    }    for(i=0; i<num; i++){        for(j=lvl-1; j>=1; j--){ lim = j * 1000; for(k=1; k< lim; k++){     if(tab[j][k] == -1) continue;     update(j+1, k+cop[i], tab[j][k]+pri[i]); }        }        update(1, cop[i], pri[i]);    }    for(i=0; i<pos; i++){        if(res[i].l == -1){ printf("impossiblen");        } else { printf("%un", res[i].l);        }    }}int readIn(){    if(scanf("%u", &num)< 0) return 0;    unsigned i;    for(i=1; i<=20; i++){        ptr[i].clear();    }    for(i=0; i<num; i++){        scanf("%u%u", &cop[i], &pri[i]);    }    scanf("%u", &pos);    lvl = 0;    for(i=0; i<pos; i++){        scanf("%u%u%u", &res[i].l, &res[i].a, &res[i].b);        ptr[res[i].l].push_back(i);        lvl = max(lvl, res[i].l);        res[i].l = -1;    }    return 1;}int main(){    int i;    for(i=1; i<= 20; i++){        tab[i] = (unsigned *)malloc(sizeof(unsigned)*(i*1008));    }    i = 0;        while(readIn() > 0){        if(i++) printf("n");        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371148.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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