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 ...
随机推荐
- 推荐10+必备的 WordPress 常用插件
众多的WordPress插件,使得WordPress的功能得到了较大的扩展,但是也正是由于过多的插件,导致我们很难选择所需的插件.今天,倡萌就根据自己的经验,给WordPress新手推荐一些常用的插件 ...
- Delphi控件大全
首先来大体上为控件分一下类,以方便我们后面的讨论. 但因为控件的种类太多,所以就粗略的分为如下几个类别∶ ---界面风格类 ---Shell外观类 ---Editor类 ---Gr ...
- 3469 [POI2008]BLO-Blockade
洛谷—— P3469 [POI2008]BLO-Blockade 题目描述 There are exactly towns in Byteotia. Some towns are connected ...
- 从 modCount 看 java集合 fail-fast 机制
一.背景 在常见的Java的非线程安全集合类中(如HashMap.ArrayList),经常可以在一些修改结构的操作(如Add)中看到实例变量 modCount++ ,来统计集合的修改次数. 从注释也 ...
- RESTful API设计规范收集
说明:其实没有绝对的规范,达到90%即可. 理解RESTful架构:http://www.ruanyifeng.com/blog/2011/09/restful.html RESTful API 设计 ...
- Building clang on RedHat
http://btorpey.github.io/blog/2015/01/02/building-clang/ clang is a great compiler, with a boatload ...
- Java实现拖拽上传
原文:http://www.open-open.com/code/view/1437358795584 在项目开发中由于实际需求,需要开发拖拽上传的功能,ok! 先看效果图: jsp上传前端代码: & ...
- topcoder srm 551
div1 250pt 题意:一个长度最多50的字符串,每次操作可以交换相邻的两个字符,问,经过最多MaxSwaps次交换之后,最多能让多少个相同的字符连起来 解法:对于每种字符,枚举一个“集结点”,让 ...
- 怎样使用SSH连接OpenStack上的云主机
转载请注明出处.否则将追究法律责任http://blog.csdn.net/xingjiarong/article/details/47021815 在上一篇博客中我介绍了怎样在OpenStack中创 ...
- Nerv --- React IE8 兼容方案
创建项目 创建一个目录,使用npm快速初始化 $ mkdir my-project && npm init -y 安装依赖 安装webpack以及babel $ npm install ...