zoukankan      html  css  js  c++  java
  • POJ 1018 Communication System DP

    这道DP真是没想出来怎么做,不过看了别人的代码后发现也只能这么想了,只有B的状态是可以确定的,然后枚举B,

    还可以再优化一下,但是数据量不大,就没这个必要了……

    #include <iostream>
    #include <cstdio>
    #include <vector>
    using namespace std;
    const int N = 105;
    
    vector<int> B[N], P[N]; //由于是不定长数组,所以用vector
    int BMin, BMax;
    
    void input( int& n ) { //输入数据,并且获取BMin, BMax的值.
        int m, b, p;
        scanf("%d", &n);
        for( int i = 0; i < n; ++i ) {
            B[i].clear(), P[i].clear();
            scanf("%d", &m);
            int temp = -1;
            while(m--) {
                scanf("%d%d", &b, &p);
                BMin = min(BMin, b);
                temp = max(temp, b);
                B[i].push_back(b), P[i].push_back(p);
            }
            BMax = min(BMax, temp);
        }
    }
    
    void slove( ) {
        BMin = 100000000, BMax = 100000000;
        int n; input(n); double ans = 0;
        for( int i = BMin; i <= BMax; ++i ) {
            double PSum = 0;
            for( int j = 0; j < n; ++j ) {
                int Size = B[j].size(), temp = 100000000;
                for( int k = 0; k < Size; ++k ) {
                    if( B[j][k] >= i && P[j][k] < temp ) temp = P[j][k];
                }
                PSum += temp;
            }
            ans = max( ans, i / PSum );
        }
        printf("%.3lf
    ", ans);
    }
    
    int main() {
        int t;
        scanf("%d", &t); while(t--) slove();
        return 0;
    }
    
  • 相关阅读:
    清除浮动float
    overflow属性
    轮播图的小圆圈鼠标移上去变样式
    大banner居中
    网站logo
    VS里面设置类似于#1或者#2之类的程序快捷输入
    优先级运算简单顺口溜
    对2的次幂求模
    VS2019离线安装
    unity ContentSizeFitter设置verticalFit立即生效
  • 原文地址:https://www.cnblogs.com/yaling/p/3452555.html
Copyright © 2011-2022 走看看