[河南省ACM省赛-第三届] BUYING FEED (nyoj 248)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 352
/*
重量*单价+重量*距离 = 重量*(距离+单价) 预处理单价
贪心:优先买价格低的
*/
struct Node {
int p;// p = (单价+距离)
int w;
}c[N];
bool cmp(Node a, Node b)
{
return a.p != b.p ? a.p < b.p : a.w > b.w;
}
int main()
{
freopen("d:\\in.txt", "r", stdin);
int t;
int K, E, n;
scanf("%d", &t);
while(t--) {
scanf("%d%d%d", &K, &E, &n);
int a, b;
; i<n; i++){
scanf("%d%d%d", &a, &c[i].w, &b);
c[i].p = E-a+b;
}
sort(c, c+n, cmp);
, totw = ;
; i<n; i++){
if(totw >= K) break;
if(totw+c[i].w > K)
res += c[i].p*(K-totw);
else
res += c[i].p*c[i].w;
totw += c[i].w;
}
printf("%d\n", res);
}
;
}
[河南省ACM省赛-第三届] BUYING FEED (nyoj 248)的更多相关文章
- [河南省ACM省赛-第三届] 素数 (nyoj 169)
#include <iostream> #include <cstdio> #include <queue> #include <cstring> #i ...
- [河南省ACM省赛-第三届] 房间安排 (nyoj 168)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...
- [河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标 ...
- [河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170 根据题意,需要找到度数为1的结点个数,如下图: #include<iostre ...
- [河南省ACM省赛-第三届] 聪明的kk (nyoj 171)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=171 动态规划: d(i,j) = max{d(i-1, j), d(i, j-1)}+m ...
- [河南省ACM省赛-第四届] 序号互换 (nyoj 303)
相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...
- [河南省ACM省赛-第四届] 表达式求值(nyoj 305)
栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...
- Mine Number(搜索,暴力) ACM省赛第三届 G
Mine Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Every one once played the gam ...
- ACM BUYING FEED
BUYING FEED 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 Farmer John needs to travel to town to pick up ...
随机推荐
- 读取xml并将节点保存到Excal
using NPOI.HPSF; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System; using System.Coll ...
- Linq 结果转成 json
public string BindGrid(string page,string rows) { int pageIndex = 0; if ...
- Python之路2Day(基础深入)
一,整数 1.int型 具有的功能: class int(object): (1).返回表示该数字的时占用的最少位数 def bit_length(self): 例: >>> bin ...
- aix上使用裸设备安装oracle10g数据库
一.检查系统信息 [root@aix222 /]# oslevel -r 5300-08 [root@aix222 /]# prtconf | grep -i mem Memory Size: 190 ...
- 利用jquery对ajax操作,详解原理(附代码)
1. jQuery load() 方法 jQuery load() 方法是简单但强大的 AJAX 方法. load() 方法从服务器加载数据,并把返回的数据放入被选元素中. 语法: $(selecto ...
- 用scikit-learn研究局部线性嵌入(LLE)
在局部线性嵌入(LLE)原理总结中,我们对流形学习中的局部线性嵌入(LLE)算法做了原理总结.这里我们就对scikit-learn中流形学习的一些算法做一个介绍,并着重对其中LLE算法的使用方法做一个 ...
- 约瑟夫问题的java实现
约瑟夫问题,又称丢手帕问题.试着实现了一下,实现逻辑简单,没有复杂的算法,适合新手参考. //参数step指步进值,步进到几则出列 //参数count指共有几个人 public static int ...
- 写给新手的WebAPI实践
此篇是写给新手的Demo,用于参考和借鉴,用于发散思路.老鸟可以忽略了. 自己经常有这种情况,遇到一个新东西或难题,在了解和解决之前总是说“等搞定了一定要写篇文章记录下来”,但是当掌握了之后,就感觉好 ...
- .Net程序员学用Oracle系列(7):视图、函数、过程、包
<.Net程序员学用Oracle系列:导航目录> 本文大纲 1.视图 1.1.创建视图 2.函数 2.1.创建函数 2.2.调用函数 3.过程 3.1.创建过程 3.2.调用过程 4.包 ...
- CI Weekly #11 | 微服务场景下的自动化测试与持续部署
又一周过去了,最近我们的工程师正在搞一个"大事情" --「[flow.ci](http://flow.ci/?utm_source=bokeyuan&utm_medium= ...