codeforces 416C C. Booking System(贪心)

本文讨论了使用贪心算法解决餐厅预订系统优化的问题,通过合理分配桌子和预订请求,最大化收入。具体实现包括对预订请求按价值排序,然后尝试为每个请求分配合适的桌子,确保满足最大桌容量限制,最终输出最优的接受请求数量和总收益。

1、http://codeforces.com/problemset/problem/416/C

2、思路:

贪心题目

按照钱数从大到小排序,钱数相同按照人数从小到大排序,然后看是否有合适的椅子分配给这个团队,如果可以,就记录下来,输出即可

3、题目:

C. Booking System
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!

A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.

There are n booking requests received by now. Each request is characterized by two numbers:ci andpi — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.

We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.

Unfortunately, there only are k tables in the restaurant. For each table, we knowri — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.

Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of requests from visitors. Thenn lines follow. Each line contains two integers:ci, pi(1 ≤ ci, pi ≤ 1000) — the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.

The next line contains integer k (1 ≤ k ≤ 1000) — the number of tables in the restaurant. The last line containsk space-separated integers: r1, r2, ..., rk(1 ≤ ri ≤ 1000) — the maximum number of people that can sit at each table.

Output

In the first line print two integers: m, s — the number of accepted requests and the total money you get from these requests, correspondingly.

Then print m lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input.

If there are multiple optimal answers, print any of them.

Sample test(s)
Input
3
10 50
2 100
5 30
3
4 6 9
Output
2 130
2 1
3 2

3、AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
    int w;
    int v;
    int id;
} a[1005];
int m;
struct node1
{
    int k;
    int id;
}b[1005];
int cmp(node b,node c)
{
    if(b.v==c.v)
        return b.w<c.w;
    return b.v>c.v;
}
int cmp1(node1 b,node1 c)
{
    return b.k<c.k;
}
int find(int p)
{
    for(int i=1;i<=m;i++)
    {
        if(b[i].k!=-1 && b[i].k>=p)
        {
            b[i].k=-1;
            return b[i].id;
        }
    }
    return 0;
}
int main()
{
    int n;
    memset(b,-1,sizeof(b));
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i].w,&a[i].v);
        a[i].id=i;
    }
    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&b[i].k);
        b[i].id=i;
    }
    sort(b+1,b+m+1,cmp1);
    sort(a+1,a+n+1,cmp);
    node1 c[1005];
    int j=1;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int tmp=find(a[i].w);
        if(tmp)
        {
            ans+=a[i].v;
            c[j].k=a[i].id;
            c[j].id=tmp;
            j++;
        }
    }
    printf("%d %d\n",j-1,ans);
    for(int i=1;i<j;i++)
    {
        printf("%d %d\n",c[i].k,c[i].id);
    }
    return 0;
}


 

内容概要:本文系统梳理了多个科研领域的前沿研究与技术实现,重点涵盖FDTD方法中的完美匹配层(PML)研究,以及Matlab/Simulink在电磁、电力、控制、通信、信号处理、图像处理、路径规划、能源系统优化等领域的仿真与算法实现。文中列举了大量基于Matlab和Python的科研案例,如风电功率预测、负荷预测、无人机三维路径规划、电池系统故障诊断、雷达模拟、通信编码、微电网优化调度等,并强调结合智能优化算法(如粒子群、遗传算法、深度学习等)提升系统性能。同时,提供了丰富的代码资源与仿真模型,涵盖永磁同步电机控制、逆变器设计、多智能体任务分配、虚拟电厂调度等复杂系统,助力科研人员快速开展复现实验与创新研究。; 适合人群:具备一定编程基础,熟悉Matlab/Python工具,从事电气工程、自动化、通信、人工智能、新能源、控制科学等相关领域研究的研发人员及研究生。; 使用场景及目标:① 学习并实现FDTD仿真中的PML边界条件以有效抑制数值反射;② 掌握Matlab/Simulink在多物理场建模、控制系统设计与优化算法中的综合应用;③ 借助提供的代码资源完成科研复现、课程设计、竞赛项目或工程原型开发; 阅读建议:此资源以科研实战为导向,不仅提供理论方法,更强调代码实现与仿真验证。建议读者结合自身研究方向,按目录顺序查阅相关模块,下载配套代码进行调试与二次开发,以达到学以致用、融会贯通的目的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值