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 ...
随机推荐
- Linux硬件监控
https://blog.csdn.net/qq_30353203/article/details/62222882
- HDU 2059 【DP】
题意: 中文. 思路: 这题不是自己的思想. 当对第i个点的最优值进行求解的时候一定存在最后一个加油的点j.这里j直接枚举. 另外将0和n+1个加油站定义为起点和终点. dp需要加强训练. #incl ...
- hdu6110(线段树+lca)
题目 http://acm.hdu.edu.cn/showproblem.php?pid=6110 分析 注意到,若干条路径的交一定也是条路径 我们可以维护一个线段树,seg[l..r]存着第l条~第 ...
- jq自定义裁剪,代码超级简单,易修改
1.自定义宽高效果 1.html 代码 index.html <!DOCTYPE html> <html lang="en"> <head> ...
- window环境下搭建SVN服务器
<span style="font-family: Arial; rgb(255, 255, 255);">第一步:准备工具:</span> 1.SVN服务 ...
- Guava ---- Concurrent并发
Guava在JDK1.5的基础上, 对并发包进行扩展. 有一些是易用性的扩展(如Monitor). 有一些是功能的完好(如ListenableFuture). 再加上一些函数式编程的特性, 使并发包的 ...
- Mapreduce运行过程分析(基于Hadoop2.4)——(三)
4.4 Reduce类 4.4.1 Reduce介绍 整完了Map,接下来就是Reduce了.YarnChild.main()->ReduceTask.run().ReduceTask.run方 ...
- mysql字段A复制到字段B,并替换指定字符
',字段a); eg:update `hy_b_pro` set goldWeight=jinJinZhong;
- C++ std::tr1::shared_ptr使用说明
1. 介绍 shared_ptr 是通过指针保持某个对象的共享拥有权的智能指针. 若干个 shared_ptr 对象能够拥有同一个对象:最后一个指向该对象的 shared_ptr 被销毁或重置时.该对 ...
- NOI 2015 滞后赛解题报告
报同步赛的时候出了些意外.于是仅仅能做一做"滞后赛"了2333 DAY1 T1离线+离散化搞,对于相等的部分直接并查集,不等部分查看是否在同一并查集中就可以,code: #incl ...