zoukankan      html  css  js  c++  java
  • 计蒜客 A1011 爱奇艺的自制节目(贪心)

    题目链接:https://vjudge.net/problem/%E8%AE%A1%E8%92%9C%E5%AE%A2-A1011

    题目大意:w和x节目的拍摄场地是固定的,问你怎么分配x和y节目的时间从而使得他们在两个场地拍摄时间的最大值最小。

      如果y和z同时处理情况会变得很复杂,所以我们可以暴力枚举出y或z分配在两边的数量,然后再用贪心考虑剩下的那一个如何分配最好

    #include<set>
    #include<map>
    #include<list>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<cstdio>
    #include<cctype>
    #include<string>
    #include<vector>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #define endl '\n'
    #define rtl rt<<1
    #define rtr rt<<1|1
    #define lson rt<<1, l, mid
    #define rson rt<<1|1, mid+1, r
    #define maxx(a, b) (a > b ? a : b)
    #define minn(a, b) (a < b ? a : b)
    #define zero(a) memset(a, 0, sizeof(a))
    #define INF(a) memset(a, 0x3f, sizeof(a))
    #define IOS ios::sync_with_stdio(false)
    #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    typedef pair<ll, ll> P2;
    const double pi = acos(-1.0);
    const double eps = 1e-7;
    const ll MOD =  1000000007LL;
    const int INF = 0x3f3f3f3f;
    const int _NAN = -0x3f3f3f3f;
    const double EULC = 0.5772156649015328;
    const int NIL = -1;
    template<typename T> void read(T &x){
        x = 0;char ch = getchar();ll f = 1;
        while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
        while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
    }
    const int maxn = 1e3+10;
    int arr[maxn];
    int main(void) {
        IOS; int t;
        cin >> t;
        while(t--) {
            ll ew, ex, ey, ez, w, x, y, z;
            cin >> ew >> ex >> ey >> ez >> w >> x >> y >> z;
            ew *= w, ex *= x;
            if (y<z) {
                swap(y, z);
                swap(ey, ez);
            }
            ll ans = LLONG_MAX;
            for (int i = 0; i<=ey; ++i) {
                ll ta = ew+i*y, tb = ex+(ey-i)*y;
                if (ta<tb) swap(ta, tb);
                ll sum, tmp = (ta-tb)/z;
                if (tmp >= ez) sum = ta;
                else {
                    tb += tmp*z;
                    ll tz = ez-tmp;
                    sum = tz&1 ? tb+(tz+1)/2*z : ta+tz/2*z;
                }
                ans = min(ans, sum);
            }
            cout << ans << endl;
        }
        return 0;
    }
  • 相关阅读:
    python:封装连接数据库方法
    Python:self理解
    python:pytest优秀博客
    python:pytest中的setup和teardown
    python:单元测试框架pytest的一个简单例子
    java中的static关键字解析
    浅谈Java中的final关键字
    SpringMVC+Spring+Mybatis框架集成
    Mybatis学习总结(四)——输入映射和输出映射
    Mybatis学习总结(三)——SqlMapConfig.xml全局配置文件解析
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12426024.html
Copyright © 2011-2022 走看看