「CF161B」Discounts
传送门
Luogu
解题思路
贪心地想一想,我们肯定要让凳子去给价格越高的商品打半价,那么我们就先按照价格排序,但是要优先把凳子排在前面。
然后我们发现一条凳子肯定只能给价格小于等于它本身的物品打半价,所以我们就尽量把所有凳子单独放一个购物车,但是要注意判断一下凳子数量和购物车数量的关系,这里不啰嗦了。
细节注意事项
- 分类讨论的过程不能少,但要是想做到码量少就要细心一点
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
}
const int _ = 1010;
int n, k; struct node { int c, p, id; }t[_];
inline bool cmp(const node& x, const node& y)
{ return x.p == y.p ? x.c > y.c : x.p < y.p; }
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(k);
int cnt = 0;
for (rg int i = 1; i <= n; ++i) {
read(t[i].c), read(t[i].p);
t[i].id = i, cnt += t[i].p == 1;
}
sort(t + 1, t + n + 1, cmp);
double ans = 0.0;
for (rg int i = 1; i <= min(cnt, k - 1); ++i)
ans += t[i].c * 0.5;
for (rg int i = min(cnt, k - 1) + 1; i <= n; ++i)
ans += t[i].c * 1.0;
if (cnt > k - 1) {
int mn = 2147483647;
for (rg int i = k; i <= n; ++i)
mn = min(mn, t[i].c);
ans -= mn * 0.5;
}
printf("%.1lf\n", ans);
for (rg int i = 1; i <= k - 1; ++i)
printf("1 %d\n", t[i].id);
printf("%d ", n - k + 1);
for (rg int i = k; i <= n; ++i)
printf("%d%c", t[i].id, " \n"[i == n]);
return 0;
}
完结撒花 \(qwq\)
「CF161B」Discounts的更多相关文章
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- 「译」JUnit 5 系列:扩展模型(Extension Model)
原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...
- JavaScript OOP 之「创建对象」
工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...
- 「C++」理解智能指针
维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...
- 「JavaScript」四种跨域方式详解
超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...
- 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management
写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...
- 「2014-3-18」multi-pattern string match using aho-corasick
我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...
- 「2014-3-17」C pointer again …
记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...
- 「2014-3-13」Javascript Engine, Java VM, Python interpreter, PyPy – a glance
提要: url anchor (ajax) => javascript engine (1~4 articles) => java VM vs. python interpreter =& ...
随机推荐
- 《Web安全攻防 渗透测试实战指南 》 学习笔记 (五)
Web安全攻防 渗透测试实战指南 学习笔记 (五) 第四章 Web安全原理解析 (一) (一)SQL注入的原理 1.web应用程序对用户输入数据的合法性没有判断. 2.参数用户可控:前端传给 ...
- java程序设计课期中考试——数据库的增删改查和简单的js界面
首先是设计思路,对于数据库的增删改查,我们借助Ecilipse来进行前端和后端的编写.Ecilipse是可以进行java web项目的操作的. 前端,我们选择用使用jsp,所谓的jsp就是可以嵌入其他 ...
- (转)Oracle数据库备份与恢复总结
http://blog.csdn.net/xyz846/article/details/6437963 http://blog.csdn.net/hollboy/article/details/867 ...
- 【原】从浏览器数据一个URL的全过程
1.根据域名到DNS找到IP 2.根据IP建立TCP三次握手连接 3.连接成功发出http请求 4.服务器响应http请求 5.浏览器解析html代码并请求html中的静态资源(js/css) 6.关 ...
- leetCode练题——9. Palindrome Number
1.题目 9. Palindrome Number Determine whether an integer is a palindrome. An integer is a palindrome ...
- 国外电商网站snapdeal爬取流程
首页爬取 1.首页获取各个目录的url 如所有优惠all_offers的其中urlhttps://www.snapdeal.com/products/men-apparel-shirts?sort=p ...
- 操作系统OS - fork bomb(Windows)
1. Type %0|%0 2. Save the file to your desktop as anything.bat
- 微信小程序 列表倒计时
最近要实现一个列表倒计时的功能,写了个demo 展示图 <view class="center colu"> <view class="time&quo ...
- 5-3 使用antDesign的form组件
import { Form, Icon, Input, Button, Checkbox } from 'antd'; class NormalLoginForm extends React.Comp ...
- 1003 Emergency (25分) 求最短路径的数量
1003 Emergency (25分) As an emergency rescue team leader of a city, you are given a special map of ...