欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

B. RPG Protagonist[Educational Codeforces Round 94 (Rated for Div. 2)]数学枚举

程序员文章站 2022-06-02 21:25:42
...

B. RPG Protagonist


题目大意:就是你有两个人,每个人都有一个最大的体力值p和f,这两个人要去搬运剑和盾牌,剑的数量是cnts,盾的数量是cntw,每个剑的重量是是s,每个盾的重量是w,问你最多可以搬运多少武器


解题思路:一眼就是一个贪心题但是如何贪心确是一个问题?
很显然剑和盾哪个轻就拿哪个为了直观一点,我们可以设出这些自变量了


B. RPG Protagonist[Educational Codeforces Round 94 (Rated for Div. 2)]数学枚举
B. RPG Protagonist[Educational Codeforces Round 94 (Rated for Div. 2)]数学枚举****

#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <limits.h>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1) 
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define log2(a) log(a)/log(2)
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define LLF 0x3f3f3f3f3f3f3f3f
#define hash Hash
#define next Next
#define pb push_back
#define f first
#define s second
using namespace std;
const int N = 1e7 + 10, MOD = 1e9 + 7;
const int maxn = 2e5;
const long double eps = 1e-5;
const int EPS = 500 * 500;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
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;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) 
{
    read(first);
    read(args...);
}
int T, n;
string s;
int main()
{
    read(T);
    while(T --)
    {
        int p, f;
        int cs,cw;
        int s, w;
        read(p,f);
        read(cs,cw);
        read(s,w);
        if (s>w){swap(s,w);swap(cs,cw);}
        int ans = 0;
        for (int s1=0;s1*s<=p && s1<=cs;s1++){
			int w1=min((p-s1*s)/w,cw);
			int s2=min(cs-s1,f/s);
			int w2=min((f-s2*s)/w,cw-w1);
			ans=max(ans,s1+s2+w1+w2);
		}
		cout << ans << endl;
    }
    return 0;
}
相关标签: 枚举