FZU - 2252 Yu-Gi-Oh! (枚举+贪心)

2023-11-23 00:59
文章标签 贪心 枚举 oh fzu yu gi 2252

本文主要是介绍FZU - 2252 Yu-Gi-Oh! (枚举+贪心),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


 Problem 2252 Yu-Gi-Oh!

Accept: 68    Submit: 447
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

另一个平行宇宙的YellowStar,是一名游戏王决斗者,某一天它正在进行一场决斗,它的场面上拥有A只磁石战士a,B只磁石战士β,C只磁石战士γ。

现在它要把这些怪物进行一波强力的融合,并且它知道:

将磁石战士a和β融合成为磁石战士aβ,战斗力为AB

将磁石战士a和γ融合成为磁石战士aγ,战斗力为AC

将磁石战士β和γ融合成为磁石战士βγ,战斗力为BC

由于YellowStar是一名人生经验丰富的决斗者,因此它在本回合可以进行无限次的融合。它想知道经过融合它能得到最大的战斗力是多少。

 Input

第一行输入T,表示有T组样例(T <= 20)

每组样例为两行,每行3个数字

第一行为A, B, C (1 <= A, B, C <= 1e6),表示每种怪物的数量

第二行为AB, AC, BC (1 <= AB, AC, BC <= 1e6),分别表示AB,AC,BC融合之后的战斗力

 Output

每组样例输出一个数字表示答案

 Sample Input

21 1 11 2 310 23 155 4 9

 Sample Output

3175

 Hint

第一个样例由于每种怪物只有一只,因此它选择融合出战斗力最为强大的磁石战士βγ,答案为3

long long类型请用%I64d输出

 Source

FOJ有奖月赛-2017年4月(校赛热身赛)


思路:一开始想着三个贪心就好了,都先给最大的,很容易找出反例。。 如果只能合成俩种的话, 那不是很简单吗。。 比如abc 只能合成 ab ac, 这样怎么做, 肯定把所有资源都给大的,然后剩下的给小的。。肯定不会不给大的给小的把。。然后就枚举某一个组合的个数, 然后剩下两个就贪心就好了。。具体看代码


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
int main()
{int t;cin >> t;while(t--){ll a, b, c, ab, ac, bc;scanf("%I64d%I64d%I64d%I64d%I64d%I64d", &a, &b, &c, &ab, &ac, &bc);ll temp1 = min(a, b);ll ans = 0;for(int i = 0; i <= temp1; i++)  //枚举 最终答案有几个ab{ll tempb = b-i, tempc = c, tempa = a-i;  ll sum = 0;   //贪心,先给价值最大的if(ac >= bc){ll temp2 = min(tempa, tempc);tempa -= temp2;tempc -= temp2;ll temp3 = min(tempb, tempc);sum = ab*i + ac*temp2 + bc*temp3;}else{ll temp2 = min(tempb, tempc);tempb -= temp2;tempc -= temp2;ll temp3 = min(tempa, tempc);sum = ab*i + ac*temp3 + bc*temp2;}ans = max(ans, sum);}printf("%I64d\n", ans);}return 0;
}


这篇关于FZU - 2252 Yu-Gi-Oh! (枚举+贪心)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/414177

相关文章

usaco 1.3 Barn Repair(贪心)

思路:用上M块木板时有 M-1 个间隙。目标是让总间隙最大。将相邻两个有牛的牛棚之间间隔的牛棚数排序,选取最大的M-1个作为间隙,其余地方用木板盖住。 做法: 1.若,板(M) 的数目大于或等于 牛棚中有牛的数目(C),则 目测 给每个牛牛发一个板就为最小的需求~ 2.否则,先对 牛牛们的门牌号排序,然后 用一个数组 blank[ ] 记录两门牌号之间的距离,然后 用数组 an

hdu 2489 (dfs枚举 + prim)

题意: 对于一棵顶点和边都有权值的树,使用下面的等式来计算Ratio 给定一个n 个顶点的完全图及它所有顶点和边的权值,找到一个该图含有m 个顶点的子图,并且让这个子图的Ratio 值在所有m 个顶点的树中最小。 解析: 因为数据量不大,先用dfs枚举搭配出m个子节点,算出点和,然后套个prim算出边和,每次比较大小即可。 dfs没有写好,A的老泪纵横。 错在把index在d

poj 3190 优先队列+贪心

题意: 有n头牛,分别给他们挤奶的时间。 然后每头牛挤奶的时候都要在一个stall里面,并且每个stall每次只能占用一头牛。 问最少需要多少个stall,并输出每头牛所在的stall。 e.g 样例: INPUT: 51 102 43 65 84 7 OUTPUT: 412324 HINT: Explanation of the s

poj 2976 分数规划二分贪心(部分对总体的贡献度) poj 3111

poj 2976: 题意: 在n场考试中,每场考试共有b题,答对的题目有a题。 允许去掉k场考试,求能达到的最高正确率是多少。 解析: 假设已知准确率为x,则每场考试对于准确率的贡献值为: a - b * x,将贡献值大的排序排在前面舍弃掉后k个。 然后二分x就行了。 代码: #include <iostream>#include <cstdio>#incl

POJ2010 贪心优先队列

c头牛,需要选n头(奇数);学校总共有f的资金, 每头牛分数score和学费cost,问合法招生方案中,中间分数(即排名第(n+1)/2)最高的是多少。 n头牛按照先score后cost从小到大排序; 枚举中间score的牛,  预处理左边与右边的最小花费和。 预处理直接优先队列贪心 public class Main {public static voi

ural 1820. Ural Steaks 贪心

1820. Ural Steaks Time limit: 0.5 second Memory limit: 64 MB After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered  n specialty steaks

ural 1014. Product of Digits贪心

1014. Product of Digits Time limit: 1.0 second Memory limit: 64 MB Your task is to find the minimal positive integer number  Q so that the product of digits of  Q is exactly equal to  N. Inpu

hdu 6198 dfs枚举找规律+矩阵乘法

number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description We define a sequence  F : ⋅   F0=0,F1=1 ; ⋅   Fn=Fn

fzu 2277 Change 线段树

Problem 2277 Change Time Limit: 2000 mSec    Memory Limit : 262144 KB  Problem Description There is a rooted tree with n nodes, number from 1-n. Root’s number is 1.Each node has a value ai.

fzu 2275 Game KMP

Problem 2275 Game Time Limit: 1000 mSec    Memory Limit : 262144 KB  Problem Description Alice and Bob is playing a game. Each of them has a number. Alice’s number is A, and Bob’s number i