[河南省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 ...
随机推荐
- 揭开redis神秘面纱
一直听别人说NoSQL,以前一直不明白,这到底是什么东西,今天听过我们涛哥的讲解,略有小感,特此小记. NoSQL(NoSQL = Not Only SQL),意为反SQL运动,是一项全新的数据库革命 ...
- TPL相关
C#中的Timer System.Windows.Forms.TimerSystem.Threading.Timer System.Timers.Timer 1.System.Windows.Form ...
- jquery以及js实现option左移右移
<table cellspacing="1" width="350px" align="center"> <tr> ...
- excel==>csv==via phpmyadmin (edit php.ini & my.ini)==> MySQL Database
正如同标题, 标题的顺序是 先从Excel表单,保存为csv文档. 步骤: 1.这个可以用linux下的libra office打开 abc.xls 2.用libra office 将 abc.xls ...
- hdu 1213 How Many Tables(并查集练习)
题目链接:hdu1213 赤裸裸的并查集.....水题一个.... #include<stdio.h> #include<string.h> #include<algor ...
- Java基础知识拾遗(一)
Java Threads 1. 创建线程的三种方法? 继承Thread类: 实现Runnable接口: 使用Executor框架创建一个线程池. 每个线程都有优先级(Thread.MAX_PRIORI ...
- Laravel5.3 流程粗粒度分析之bootstrap
从laravel入口文件index里面外面不难定位到Illuminate\Foundation\Http\Kernel的handle方法,同样也不难发现handle方法的核心是 $response = ...
- eclipse安装svn插件的多种方式
方法一:在线安装 1.打开HELP->MyEclipse Configuration Center.切换到SoftWare标签页. 2.点击Add Site 打开对话框,在对话框Name输入Sv ...
- maven pom.xml详细介绍,必须留一份
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- MVC实现省级联动
前言 省级联动的效果,网上现成的都有很多,各种JS实现,Jquery实现等等,今天我们要讲的是在MVC里面,如何更方便.更轻量的实现省级联动呢? 实现效果如下: 具体实现 如图所示,在HTML页非常简 ...