计蒜客 - 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; }