[河南省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 ...
随机推荐
- 自用类库整理之SqlHelper和MySqlHelper
自用类库整理之SqlHelper和MySqlHelper 自用的SQLHelper和MySqlHelper,除一些通用方法外,封装了一些很实用的批量操作方法,简单介绍下 SqlHelper Execu ...
- 博客已迁移到lizhug.com
新的博客地址 http://lizhug.com
- Python闭包详解
Python闭包详解 1 快速预览 以下是一段简单的闭包代码示例: def foo(): m=3 n=5 def bar(): a=4 return m+n+a return bar >> ...
- 解决URL中文乱码问题--对中文进行加密、解密处理
解决URL中文乱码问题--对中文进行加密.解密处理 情景:在资源调度中,首先用户需要选择工作目标,然后跟据选择的工作目标不同而选择不同的账号和代理ip.处理过程如下:点击选择账号,在js中获取工作目标 ...
- TOGAF架构开发方法(ADM)之架构变更管理阶段
TOGAF架构开发方法(ADM)之架构变更管理阶段 1.10 架构变更管理(Architecture Change Management) 企业架构开发方法各阶段——架构变更管理 1.10.1 目标 ...
- gearman with postgresql as persistent Queuing
gearman is a good thing gearman client --------------> gearman server <----------------------- ...
- Servlet部署描述文件(web.xml)
最近看了下配置文件(Deployment Descriptor:简称DD),又称部署描述文件,下面详细介绍下该文件的组成和作用: 一.<web-app>有四个属性: 1.xmlns:申明了 ...
- 如何制作一个类似Tiny Wings的游戏 Cocos2d-x 2.1.4
在第一篇<如何使用CCRenderTexture创建动态纹理>基础上,增加创建动态山丘,原文<How To Create A Game Like Tiny Wings with Co ...
- iOS上线项目源码分享
最强UINavigationController和TabBar结合(会员satian ) 最强UINavigationController和TabBar结合的Demo,这里取用了明星衣橱app里的 ...
- 黑马程序员:Java基础总结----GUI&网络&IO综合开发
黑马程序员:Java基础总结 GUI&网络&IO综合开发 ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 网络架构 C/S:Client/Server ...