牛客网国庆集训派对Day3 D-Shopping(贪心水题)

思路来源

http://www.cnblogs.com/FlyerBird/archive/2018/08/06.html

题解

n个物品是都要买的,

所以把最贵的m个物品分别放在不同的购物车里,

记凳子数为q,把m中最贵的前q个物品打折了就好了,

也就是把凳子放在这些购物车里面。

因此,最后打折的数量是min(q,m)。

心得

题目是2018 Wannafly summer camp Day3的重现,

人家的签到题也不会没关系,及时补就好了

这世上原本有两种题,不会和会的,

现在有两种,能补的和不能补的,

多看看人家代码,该会的还是能会的

代码

#include <iostream>
#include <algorithm> 
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
const double INF=0x3f3f3f3f;
const int maxn=1e5+10; 
const int mod=1e9+7;
const int MOD=998244353;
const double eps=1e-7;
typedef long long ll;
#define vi vector<int> 
#define si set<int>
#define pii pair<double,int> 
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define lowbit(x) (x&(-x))
#define sci(x) scanf("%d",&(x))
#define scll(x) scanf("%lld",&(x))
#define sclf(x) scanf("%lf",&(x))
#define pri(x) printf("%d",(x))
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define mem(a,b) memset(a,b,sizeof(a)) 
using namespace std;
int a[1005],b[1005];
int main()
{ 
    int t;
    sci(t);
    while(t--)
    {
    	double ans=0;
    	int n,m,cnt=0;
    	sci(n),sci(m);
    	rep(i,0,n-1)
		{
			sci(a[i]),sci(b[i]);
			if(b[i]==1)cnt++;
		} 
		cnt=min(cnt,m);
		sort(a,a+n);
		int num=0;
		per(i,n-1,0)
		{
			num++;
			if(num<=cnt)ans+=a[i]*0.5;
			else ans+=a[i];
		}
		printf("%.1lf\n",ans);
    }
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Code92007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值