1354 - Mobile Computing (UVA)

题目链接如下:

Online Judge

我的代码如下:

#include <cstdio>
#include <vector>
#include <utility>
// #define debug

int n, s;
double r, maxWidth;
std::vector<int> w;

void dfs(std::vector<int> vec, double loc, std::vector<std::pair<double, double>> &range){
    if (vec.size() == 1){
        range.push_back({loc, loc});
        return;
    }
    int sz = vec.size();
    for (int i = 1; i < ((1 << sz) - 1); ++i){
        std::vector<int> v1, v2;
        for (int j = 0; j < sz; ++j){
            if (i & 1 << j){
                v1.push_back(vec[j]);
            } else {
                v2.push_back(vec[j]);
            }
        }
        int l = 0;
        int r = 0;
        for (int j = 0; j < v1.size(); ++j){
            l += v1[j];
        }
        for (int j = 0; j < v2.size(); ++j){
            r += v2[j];
        }
        double temp = loc - 1.0 * r / (l + r);
        std::vector<std::pair<double, double>> tempRangeL, tempRangeR;
        dfs(v1, temp, tempRangeL);
        dfs(v2, temp + 1, tempRangeR);
        for (int j = 0; j < tempRangeL.size(); ++j){
            for (int k = 0; k < tempRangeR.size(); ++k){
                double tl = std::min(tempRangeL[j].first, tempRangeR[k].first);
                double tr = std::max(tempRangeL[j].second, tempRangeR[k].second);
                range.push_back({tl, tr});
            }
        }
    }
}

int main(){
    #ifdef debug
    freopen("0.txt", "r", stdin);
    freopen("1.txt", "w", stdout);
    #endif
    scanf("%d", &n);
    while (n--){
        scanf("%lf %d", &r, &s);
        w.resize(s);
        for (int i = 0; i < s; ++i){
            scanf("%d", &w[i]);
        }
        maxWidth = -1.0;
        std::vector<std::pair<double, double>> vec;
        dfs(w, 0, vec);
        for (int i = 0; i < vec.size(); ++i){
            double width = vec[i].second - vec[i].first;
            if (width < r && width > maxWidth){
                maxWidth = width;
            }
        }
        if (maxWidth < 0){
            printf("-1\n");
        } else {
            printf("%.16lf\n", maxWidth);
        }
    }
    #ifdef debug
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Self-Aware Computing Systems ISBN-10 书号: 3319474723 ISBN-13 书号: 9783319474724 Edition 版本: 1st ed. 2017 出版日期: 2017-01-23 pages 页数: (722 ) $219.99 This book provides formal and informal definitions and taxonomies for self-aware computing systems, and explains how self-aware computing relates to many existing subfields of computer science, especially software engineering. It describes architectures and algorithms for self-aware systems as well as the benefits and pitfalls of self-awareness, and reviews much of the latest relevant research across a wide array of disciplines, including open research challenges. The chapters of this book are organized into five parts: Introduction, System Architectures, Methods and Algorithms, Applications and Case Studies, and Outlook. Part I offers an introduction that defines self-aware computing systems from multiple perspectives, and establishes a formal definition, a taxonomy and a set of reference scenarios that help to unify the remaining chapters. Next, Part II explores architectures for self-aware computing systems, such as generic concepts and notations that allow a wide range of self-aware system architectures to be described and compared with both isolated and interacting systems. It also reviews the current state of reference architectures, architectural frameworks, and languages for self-aware systems. Part III focuses on methods and algorithms for self-aware computing systems by addressing issues pertaining to system design, like modeling, synthesis and verification. It also examines topics such as adaptation, benchmarks and metrics. Part IV then presents applications and case studies in various domains including cloud computing, data centers, cyber-physical systems, and the degree to which self-aware computing approaches have been adopted within those domains. Lastly, Part V surveys open challenges and future research directions for self-aware computing systems. It can be used as a handbook for professionals and researchers working in areas related to self-aware computing, and can also serve as an advanced textbook for lecturers and postgraduate students studying subjects like advanced software engineering, autonomic computing, self-adaptive systems, and data-center resource management. Each chapter is largely self-contained, and offers plenty of references for anyone wishing to pursue the topic more deeply.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值