Gym 100531B Buffcraft (贪心+暴力+前缀和)
题意:给定两个加血的方式,一个是直接加多少,另一种是加百分之几,然后你能够你选 k 种,问你选哪 k 种。
析:首先肯定要选加的多的,所以我们先排序,从大到小,然后用前缀和存储一下,再去枚举从第一种和从第二种选 i 个,从另一个中选 k-i的,
注意这个 k 可能大于 m+n,讨论一下。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define debug puts("+++++")
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 50000 + 5;
const LL mod = 1e3 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Node{
int num, id;
bool operator < (const Node &p) const{
return num > p.num;
}
};
Node a[maxn], b[maxn];
LL sum1[maxn], sum2[maxn]; void print(int n, Node *a){
for(int i = 1; i <= n; ++i)
if(1 == i) printf("%d", a[i].id);
else printf(" %d", a[i].id);
printf("\n");
} int main(){
freopen("buffcraft.in", "r", stdin);
freopen("buffcraft.out", "w", stdout);
int base, k;
while(scanf("%d %d %d %d", &base, &k, &n, &m) == 4){
for(int i = 1; i <= n; ++i){
scanf("%d", &a[i].num);
a[i].id = i;
}
for(int i = 1; i <= m; ++i){
scanf("%d", &b[i].num);
b[i].id = i;
}
if(k >= m + n){
printf("%d %d\n", n, m);
print(n, a);
print(m, b);
continue;
}
sort(a+1, a+n+1);
sort(b+1, b+m+1);
sum1[0] = sum2[0] = 0;
for(int i = 1; i <= n; ++i) sum1[i] = sum1[i-1] + a[i].num;
for(int i = 1; i <= m; ++i) sum2[i] = sum2[i-1] + b[i].num;
LL ans = 0;
int idx = 0;
for(int i = 0; i <= n && i <= k; ++i){
if(m < k - i) continue;
LL tmp = (base + sum1[i]) * (100 + sum2[k-i]);
if(tmp > ans){
ans = tmp;
idx = i;
}
}
for(int i = 0; i <= m && i <= k; ++i){
if(n < k - i) continue;
LL tmp = (base + sum1[k-i]) * (100 + sum2[i]);
if(tmp > ans){
ans = tmp;
idx = -i;
}
} if(idx < 0) idx += k;
printf("%d %d\n", idx, k - idx);
print(idx, a);
print(k - idx, b);
}
return 0;
}
Gym 100531B Buffcraft (贪心+暴力+前缀和)的更多相关文章
- Codeforces 990 调和级数路灯贪心暴力 DFS生成树两子树差调水 GCD树连通块暴力
A 水题 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace ...
- The 10th Shandong Provincial Collegiate Programming Contest H.Tokens on the Segments(贪心+优先级队列 or 贪心+暴力)
传送门 •题意 二维平面上有 n 条线段,每条线段坐标为 $(l_i,i),(r_i,i)$: 平面上的每个整点坐标上都可以放置一枚硬币,但是要求任意两枚硬币的横坐标不相同: 问最多有多少条线段可以放 ...
- Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理
A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...
- Codeforces Gym 100803C Shopping 贪心
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- Codeforces Gym 100637A A. Nano alarm-clocks 前缀和
A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...
- Gym 101775B - Scapegoat - [贪心+优先队列]
题目链接:http://codeforces.com/gym/101775/problem/B Aori is very careless so she is always making troubl ...
随机推荐
- [NOIP2000] 提高组 洛谷P1017 进制转换
题目描述 我们可以用这样的方式来表示一个十进制数: 将每个阿拉伯数字乘以一个以该数字所处位置的(值减1)为指数,以10为底数的幂之和的形式.例如:123可表示为 1*10^2+2*10^1+3*10^ ...
- ES6__函数的扩展
/** * 函数的扩展 * 1 为函数参数指定默认值 * 2 函数的 rest 参数 * 3 箭头函数 */ // ------------------------------------------ ...
- git修改commit message及vi编辑器的简单使用
1.修改commit信息 git commit --amend 2.进入vi编辑器修改 ‘i’进入insert模式,输入文字: ‘esc’回到命令模式,删除文字,移动光标: ‘:’进入底行模式,‘wq ...
- java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
新建Maven 项目的时候报错: java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet ...
- EF关联
public CustomerMap() { this.ToTable("Customer"); this.HasKey(c => c.Id); this.Property( ...
- eclipse设置每次提交代码忽略target、.settings、.svn、.project文件
- 【Todo】开个文章学VUE咯
2017年FE架构组制定的框架选型主导为VUE.看了一下VUE的介绍,很不错. 开学~ https://www.zhihu.com/question/38213423 这个里面有VUE应用和背景的一些 ...
- 猫猫学iOS 之微博项目实战(2)微博主框架-自己定义导航控制器NavigationController
猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243?viewmode=contents 一:加入导航控制器 上一篇博 ...
- Random Forest 与 GBDT 的异同
曾经在看用RF和GBDT的时候,以为是非常相似的两个算法,都是属于集成算法,可是细致研究之后,发现他们根本全然不同. 以下总结基本的一些不同点 Random Forest: bagging (你懂得. ...
- Deepin-添加path
以管理员权限添加path(Debian系列) sudo gedit /etc/profile 添加path路径格式是: export PATH=”$PATH:your path1:your path2 ...