2019 校内赛 RPG的天赋分支(贪心)
Problem Description
Luke最近沉迷一款RPG游戏,它的天赋树机制如下:

角色具有n个可选天赋,天赋之间不存在任何依赖,每个可选天赋有左右两条分支,对于任意天赋,只能选择某一条分支,左右分支所提升的属性值分别是ai和bi。现在角色需要决定每个天赋的选择,游戏要求选择A个左分支和 B个右分支(n=A+B),每个天赋只可以点一次。问如何分配天赋点数使得提升属性最大化。
Input
随后为t组输入,每组测试中,第一行为整数n A B分别表示总天赋数,左右分支的数目要求,随后n行每行两个正整数ai bi分别表示左、右分支的属性加成。
t<=300
n<=10^6
A+B=n
0<=ai,bi<=10^9
Output
Sample Input
1
3 1 2
6 1
3 1
7 4
Sample Output
11
思路:根据内部的差值从小到大排序 小的就选另一边(r个) 和自己这边l个 的和
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define ll long long int
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int n,l,r;
struct node{
int a,b;
};
node p[];
bool cmp(node a,node b){
return a.a-a.b<b.a-b.b;
}
int main(){
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
cin>>n>>l>>r;
for(int i=;i<=n;i++)
cin>>p[i].a>>p[i].b;
sort(p+,p+n+,cmp);
ll ans=;
for(int i=;i<=r;i++)
ans+=p[i].b;
for(int i=n;i>=n-l+;i--)
ans+=p[i].a;
cout<<ans<<endl;
}
return ;
}
2019 校内赛 RPG的天赋分支(贪心)的更多相关文章
- 2019 校内赛 RPG的地牢猎手(bfs+优先队列)
Problem Description Luke最近沉迷一款RPG游戏,游戏中角色可以进入地牢关卡,只要顺利走出地牢就可以获得奖励.地牢表示为n行m列的块矩阵,其中每个块只可以是障碍块.入口.出口或数 ...
- hdu6578 2019湖南省赛D题Modulo Nine 经典dp
目录 题目 解析 AC_Code @ 题目 第一题题意是一共有{0,1,2,3}四种数字供选择,问有多少个长度为n的序列满足所有m个条件,每个条件是说区间[L,R]内必须有恰好x个不同的数字. 第二题 ...
- 2019中国大学生程序设计竞赛-女生专场(重现赛)部分题解C-Function(贪心+优先队列) H-clock(模拟)
Function 题目链接 Problem Description wls 有 n 个二次函数 Fi(x) = aix2 + bix + ci (1 ≤ i ≤ n). 现在他想在∑ni=1xi = ...
- 计蒜客蓝桥杯模拟赛 后缀字符串:STL_map+贪心
问题描述 一天蒜头君得到 n 个字符串 si,每个字符串的长度都不超过 10. 蒜头君在想,在这 n 个字符串中,以 si 为后缀的字符串有多少个呢? 输入格式 第一行输入一个整数 n. 接下来 ...
- 2017.7.4 ACM校内赛 Round 2
这是一个向导 A - hdu 3652 B - bzoj 4152 C - bzoj 2429 D - bzoj 1087 E - bzoj 1566 F - bzoj 4043 G - bzoj 1 ...
- HDU 6438 网络赛 Buy and Resell(贪心 + 优先队列)题解
思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益 ...
- 2016 acm香港网络赛 C题. Classrooms(贪心)
原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...
- The 10th Shandong Provincial Collegiate Programming Contest 2019山东省赛游记+解题报告
比赛结束了几天...这篇博客其实比完就想写了...但是想等补完可做题顺便po上题解... 5.10晚的动车到了济南,没带外套有点凉.酒店还不错. 5.11早上去报道,济南大学好大啊...感觉走了一个世 ...
- HDU6438 Buy and Resell 2018CCPC网络赛 -低买高卖-贪心经典题
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. 出过很多次:5 ...
随机推荐
- MVC最全jar包
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> & ...
- python爬虫-1
import resquests #import urllib.request from bs4 import BeautifulSoup from collections import Ordere ...
- Chromecast
Chromecast chrome://cast/#offers https://chromecast.com/help https://www.pcmag.com/feature/326584/24 ...
- LOADING Redis is loading the dataset in memory Redis javaAPI实例
今天在实现Redis客户端API操作Jedis的八种调用方式详解中,遇到了LOADING Redis is loading the dataset in memory错误,经过多番查找资料,找到了解决 ...
- Windows Server 2012 添加角色时出现 failed to open runspace pool
先把所有的Windows Server 2012的更新更新了.再来添加服务器角色.就不会再出现 The Server Manager WinRM plug-in might be corrupted ...
- js定时函数,定时改变字体的大小
<html> <head> </head> <body> <div id="d"> js控制字体大小 </div& ...
- vue 使用技巧总结 19.01
组件中箭头函数的使用 不要使用箭头来定义任意生命周期钩子函数: 不要使用箭头来定义一个 methods 函数: 不要使用箭头来定义 computed 里的函数: 不要使用箭头定义 watch 里的函数 ...
- codeforces630C
Lucky Numbers CodeForces - 630C 小希称只含7和8的数是幸运数,那么不超过n位的幸运数有多少个? Input 一个整数 n (1 ≤ n ≤ 55) Output 输出幸 ...
- Spring 使用介绍(十)—— 单元测试
一.概述 Spring测试框架提供了对单元测试的支持,以便使用spring的依赖注入和事务管理功能 maven依赖: <dependency> <groupId>junit&l ...
- CentOS 部署.net core 2.0 项目
上传项目到服务器 安装Nginx(反向代理服务器),配置文件 https://www.cnblogs.com/xiaonangua/p/9176137.html 安装supervisor https: ...