CodeForces 867C Ordering Pizza
来源:互联网 发布:软件模块接口参数 编辑:程序博客网 时间:2024/06/05 08:23
题目链接:http://codeforces.com/contest/867/problem/C
题意:有2种披萨,每次预定一份披萨,能把披萨分成S分,有n个人,第i个人要吃si块,吃第一种,每块披萨能增长ai的幸福值,吃第二种披萨,每块能增长bi的幸福值,现在问你能怎样预定披萨,能使得预定的披萨尽可能少,且还能满足所有人的胃口,还使得幸福值尽可能大
解析:首先贪心的来存答案,就是每个人都吃幸福值最高的披萨,这样预定的披萨可能不一定是最少的,但是可以通过一些转换,将一些人转为吃部分的另一种披萨,所以记录一下每种披萨,按贪心策略来说,会多买多少片披萨(c1,c2),如果c1+c2>S表示你就算不转换,也一定要多买一份披萨,如果小于,那么你就需要转换了,所以你可以把每个人两种披萨开心值的差值存下来,然后排个序,最后用之前记录的结果减去
#include <bits/stdc++.h>using namespace std;typedef long long ll;vector<pair<ll,ll> >t1;vector<pair<ll,ll> >t2;int main(void){ int n,s; scanf("%d %d",&n,&s); ll c1 = 0,c2 = 0,ans = 0; for(int i=0;i<n;i++) { ll c,a,b; scanf("%I64d %I64d %I64d",&c,&a,&b); if(a>b) { ans += c*a; c1 = (c1+c)%s; t1.push_back(make_pair(a-b,c)); } else { ans += c*b; c2 = (c2+c)%s; t2.push_back(make_pair(b-a,c)); } } if(c1+c2>s) { printf("%I64d\n",ans); return 0; } sort(t1.begin(),t1.end()); sort(t2.begin(),t2.end()); ll cc1 = 0,cc2 = 0; for(int i=0;i<(int)t1.size();i++) { //cout<<t1[i].first<<" "<<t1[i].second<<endl; if(c1>t1[i].second) { cc1 += t1[i].second*t1[i].first; c1 -= t1[i].second; } else { cc1 += c1*t1[i].first; break; } } for(int i=0;i<(int)t2.size();i++) { if(c2>t2[i].second) { cc2 += t2[i].second*t2[i].first; c2 -= t2[i].second; } else { cc2 += c2*t2[i].first; break; } } ans -= min(cc1,cc2); printf("%I64d\n",ans); return 0;}
阅读全文
0 0
- CodeForces 867C Ordering Pizza
- codeforces 867 C Ordering Pizza
- Codeforces Round #437-贪心-C. Ordering Pizza
- Codeforces Round #437 Div. 2 C. Ordering Pizza
- codeforces 865B. Ordering Pizza
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- Ordering Pizza(贪心)
- codeforces A. Pizza Separation
- Pizza Separation CodeForces
- PIZZA
- Codeforces 842B. Gleb And Pizza 模拟
- Codeforces 842 B Gleb And Pizza
- codeforces #448(div 2) A. Pizza Separation
- Codeforces Round #430 (Div. 2) B. Gleb And Pizza
- Codeforces Round #430 (Div. 2) B. Gleb And Pizza
- Codeforces Round #430 (Div. 2) B. Gleb And Pizza(数论)
- Codeforces Round #430 (Div. 2) B. Gleb And Pizza
- (几何题)Codeforces 430 B. Gleb And Pizza
- bootstrap学习笔记心得1
- 如何防止主机被ping
- GCC Command Options
- 单链表
- C语言分析——文件操作
- CodeForces 867C Ordering Pizza
- 搜集来的命令集合,挺好的
- 第三章 运算符 表达式
- UVA 536 Tree Recovery
- Django基础
- 171011 逆向-Reversing.kr(HateIntel)
- win7下U盘安装Ubuntu 双系统
- angularjs动画模块
- 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。