Codeforces Round #437 C. Ordering Pizza
题意: n个人吃披萨,总共有两种披萨,每种披萨都是有S块,给出每个人要吃的块数,吃第一种披萨能获得的happy值,吃第二种披萨能获得的happy值,问你,在购买的披萨数最少的情况下能获得的最大的总的happy值是多少(披萨可以买任意多个,吃不完也行 2333333)
3 12
3 5 7
4 6 7
5 9 5
84
6 10
7 4 7
5 8 8
12 5 8
6 11 6
3 3 7
5 9 6
314 思路:首先肯定是每个人都吃happy值更大的那一种披萨最优,但是有一个问题,可能会多出一点零头,那么我们记为sum1和sum2。
如果sum1+sum2>S,那么这些零头肯定是要买两个披萨的,不如就各买各的,那么答案就是ans;
但是如果sum1+sum2<=S,那么就要一起买一个披萨了,这样的话就用ans-min(让买第一种披萨的去买第二种的差值,
让买第二种披萨的去买第一种的差值),
这样算出来的结果就是答案了。
(用结构体保存一下a,b,差值,然后按差值从小到大来排序,肯定是让差值小的最后买这样才最划算,因为如果要买另外一
个这样损失最小)
for(int i=0;i<n1;i++){
ans1+=min(sum1,t1[i].s)*t1[i].c;
sum1-=min(sum1,t1[i].s);
}
for(int i=0;i<n2;i++){
ans2+=min(sum2,t2[i].s)*t2[i].c;
sum2-=min(sum2,t2[i].s);
}
这两句话很关键是从一个帖子看到的23333。 代码: #include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e5+5; struct node{
long long s,a,b,c;
}t1[maxn],t2[maxn];
bool cmp(node x,node y){
return x.c<y.c;
} int main(){
long long n,S,n1=0,n2=0,sum1=0,sum2=0,ans=0,ans1=0,ans2=0,x,y,z;
cin>>n>>S;
for(int i=0;i<n;i++){
cin>>x>>y>>z;
if(y>z){
t1[n1].s=x;
t1[n1].a=y;
t1[n1].b=z;
t1[n1].c=y-z;
ans+=t1[n1].a*t1[n1].s;
sum1=(sum1+t1[n1].s)%S;
n1++;
}
else {
t2[n2].s=x;
t2[n2].a=y;
t2[n2].b=z;
t2[n2].c=z-y;
ans+=t2[n2].b*t2[n2].s;
sum2=(sum2+t2[n2].s)%S;
n2++;
}
}
if(sum1+sum2>S){
cout<<ans<<endl;
}
else {
sort(t1,t1+n1,cmp);
for(int i=0;i<n1;i++){
ans1+=min(sum1,t1[i].s)*t1[i].c;
sum1-=min(sum1,t1[i].s);
}
sort(t2,t2+n2,cmp);
for(int i=0;i<n2;i++){
ans2+=min(sum2,t2[i].s)*t2[i].c;
sum2-=min(sum2,t2[i].s);
}
if(ans1<ans2)ans-=ans1;
else ans-=ans2;
cout<<ans<<endl;
}
return 0;
}
Codeforces Round #437 C. Ordering Pizza的更多相关文章
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)
Problem A Between the Offices 水题,水一水. #include<bits/stdc++.h> using namespace std; int n; ]; i ...
- 【Codeforces Round #437 (Div. 2) C】 Ordering Pizza
[链接]h在这里写链接 [题意] 给你参赛者的数量以及一个整数S表示每块披萨的片数. 每个参数者有3个参数,si,ai,bi; 表示第i个参赛者它要吃的披萨的片数,以及吃一片第 ...
- Codeforces Round #437 Div. 1
A:显然构造一组只包含1和2面值的数据即可. #include<iostream> #include<cstdio> #include<cmath> #includ ...
- Codeforces Round #437 E. Buy Low Sell High
题意:买卖股票,给你n个数,你可以选择买进或者卖出或者什么都不做,问你最后获得的最大收益是多少. Examples Input 910 5 4 7 9 12 6 2 10 Output 20 Inpu ...
- Codeforces Round #437 B. Save the problem!
题意: 给你一个方案数,要求你输出满足该条件的总金额,面值数,和各个面值是多少,答案有多个,随便输出一个即可. Examples Input 18 Output 30 41 5 10 25 Input ...
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E
题意:减前面的数,加后面的数,保证最后不剩下数,加减次数要相同: 题解:emmmmm,看出是个贪心,先对价值排序,相同就对下标排序,规律是每次找第一个,然后从后往前找没有使用过的下表比他大的第一个,相 ...
- 【Codeforces Round #437 (Div. 2) A】Between the Offices
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...
- 【Codeforces Round #437 (Div. 2) B】Save the problem!
[链接]h在这里写链接 [题意] 给你一个金额N,和硬币的类型总数M; (完全背包),然后问你组成N的方案数. 使得,用这些硬币组成价值为N的金额的方案数为A; 现在A ...
随机推荐
- Apache Hive处理数据示例
继上一篇文章介绍如何使用Pig处理HDFS上的数据,本文将介绍使用Apache Hive进行数据查询和处理. Apache Hive简介 首先Hive是一款数据仓库软件 使用HiveQL来结构化和查询 ...
- [LeetCode&Python] Problem 458. Poor Pigs
There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. Th ...
- 公众号及H5支付
本篇主要记录微信支付中公众号及H5支付全过程. 1|1准备篇 公众号或者服务号(并开通微信支付功能).商户平台中开通JSAPI支付.H5支付. 1|2配置篇 公众号或者服务号中 -------开发-- ...
- ESP8266EX资料
https://github.com/esp8266/Arduino http://espressif.com/zh-hans/support/explore/faq 电路资料图如下: 介绍功能: 参 ...
- springMVC---业务处理流程图和最简单的springMvc搭建截图说明
一.springMVC业务处理流程图: 二.如何搭建springMvc框架 1.建立web工程 2.引入jar包 3.创建web.xml文件 4.创建springMvc-servlet.xml文件 5 ...
- CVE-2017-11882 POC 全版本通杀
POC https://github.com/embedi/CVE-2017-11882
- immutable.js使用总结
1. immutable相当于 JSON.parse 和 JSON.stringify: 2.引入redux中,除了 在最外层 reducer中 import { combineReducers } ...
- systemd service 设置limit,不生效问题
参考博文: http://smilejay.com/2016/06/centos-7-systemd-conf-limits/(解决方法参考此博文) 问题简述:Centos7下修改系统的最大文件打 ...
- Day 08 文件操作模式,文件复制,游标
with open:将文件的释放交给with管理 with open('文件', '模式', encoding='utf-8') as f: # 操作 pass a模式:追加写入 # t ...
- Java面试题 OOAD & UML+XML+SQL+JDBC & Hibernate
二.OOA/D 与UML 部分:(共6 题:基础2 道,中等难度4 道) 96.UML 是什么?常用的几种图?[基础] 答:UML 是标准建模语言:常用图包括:用例图,静态图(包括类图.对象图和包图) ...