CodeForce 589B Layer Cake

探讨如何通过切割多个蛋糕层来构造出体积最大的长方体蛋糕,介绍了一种优化后的枚举算法实现。
Layer Cake
 

Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n rectangular cake layers. The length and the width of the i-th cake layer were ai and bi respectively, while the height of each cake layer was equal to one.

From a cooking book Dasha learned that a cake must have a form of a rectangular parallelepiped constructed from cake layers of the same sizes.

Dasha decided to bake the biggest possible cake from the bought cake layers (possibly, using only some of them). It means that she wants the volume of the cake to be as big as possible. To reach this goal, Dasha can cut rectangular pieces out of the bought cake layers. She always cuts cake layers in such a way that cutting lines are parallel to the edges of that cake layer. Dasha isn't very good at geometry, so after cutting out a piece from the original cake layer, she throws away the remaining part of it. Also she can rotate a cake layer in the horizontal plane (swap its width and length).

Dasha wants her cake to be constructed as a stack of cake layers of the same sizes. Each layer of the resulting cake should be made out of only one cake layer (the original one or cut out from the original cake layer).

Help Dasha to calculate the maximum possible volume of the cake she can bake using given cake layers.

Input
 

The first line contains an integer n (1 ≤ n ≤ 4000) — the number of cake layers that Dasha can use.

Each of the following n lines contains two integer numbers ai and bi(1 ≤ ai, bi ≤ 106) — the length and the width of i-th cake layer respectively.

Output

The first line of the output should contain the maximum volume of cake that can be baked using given layers.

The second line of the output should contain the length and the width of the resulting cake. If there are many solutions with maximum possible volume, print any of them.

Examples
Input
5
5 12
1 1
4 6
6 4
4 6
Output
96
6 4
Input
2
100001 900000
900001 100000
Output
180000000000
900000 100000
Note

In the first example Dasha doesn't use the second cake layer. She cuts 4 × 6 rectangle from the first cake layer and she uses other cake layers as is.

In the second example Dasha cuts off slightly from the both cake layers.

题意:

  有 n个蛋糕,给出长和宽,他们的高度都是1, 把这些蛋糕切成一个大的长方体,求最大的面积:

思路:

  一开始想到了暴力枚举,但是超时,后来用复制函数小小的优化了一下,就OK了,具体看代码

  AC代码:

 1 # include <iostream>
 2 # include <cstring>
 3 # include <cstdio>
 4 # include <vector>
 5 # include <map>
 6 using namespace std;
 7 
 8 const int MAX = 2* 1e4 + 1;
 9  
10 char s[MAX][105];
11 char s2[MAX][105];
12 map <string, int> mp;
13 vector <int> v[MAX];
14 int num = 0;
15  
16 void init(int k)
17 {
18     // 转换大小写
19     for(int i = 1; s[k][i] != '\0'; i++)
20         if(s[k][i] >= 'A' && s[k][i] <= 'Z') 
21             s2[k][i] = tolower(s[k][i]);
22         else 
23             s2[k][i]=s[k][i];
24  
25     int p = 1;
26     for(; s[k][p] != '@'; p++); // 找@
27     
28     //  判段字符串相同吗
29     if(strcmp(s2[k] + p + 1, "bmail.com") == 0)
30     {
31         int flag = 0, cnt = 0;
32         for(int i = 1; s[k][i] != '\0'; i++)
33         {
34             if((s[k][i] == '.' || flag) && i < p)
35                 continue;
36             else if(s[k][i] == '+') 
37                 flag = 1;
38             else 
39                 s2[k][++cnt] = tolower(s[k][i]);
40         }
41             s2[k][cnt+1] = '\0';
42     }
43     if(!mp[s2[k] + 1])
44     {
45         num++;
46         mp[s2[k] + 1] = num;
47         v[num].push_back(k);
48     }
49     else
50         v[mp[s2[k]+1]].push_back(k);
51 }
52  
53 int main()
54 {
55     int n;
56     scanf("%d", &n);
57 
58 
59     for(int i = 1; i <= n; i++)
60     {
61         scanf("%s", s[i] + 1);
62         init(i);
63     }
64     printf("%d\n", num);
65     
66     for(int i = 1; i <= num; i++)
67     {
68         printf("%d ", v[i].size());
69         for(int j = 0; j < v[i].size(); j++)
70             printf("%s ",s[v[i][j]] + 1);
71         
72         printf("\n");
73     }
74     for(int i = 1; i <= num; i++) 
75         v[i].clear();
76    
77    return 0;
78 }
View Code

 

转载于:https://www.cnblogs.com/lyf-acm/p/5791483.html

多角色体系 支持管理员、商家、消费者三种角色,权限分级管控: 管理员:负责平台整体配置、用户审核、数据监控等全局操作。 商家:管理店铺信息、发布商品、处理订单、回复评价等。 消费者:浏览商品、加入购物车、下单支付、评价商品等。 实现用户注册(手机号 / 邮箱验证)、登录(支持密码 / 验证码 / 第三方登录)、个人信息管理(头像、收货地址、密码修改)。 权限精细化控制 商家仅能管理自家店铺及商品,消费者仅能查看和购买商品,管理员拥有全平台数据访问权限。 二、商品管理功能 商品信息维护 商家可发布商品:填写名称、分类(如服饰、电子产品)、子类别(如手机、笔记本)、规格(尺寸、颜色、型号)、价格、库存、详情描述(图文)、物流信息(运费、发货地)等。 支持商品上下架、库存调整、信息编辑,系统自动记录商品状态变更日志。 商品分类与搜索 按多级分类展示商品(如 “数码产品→手机→智能手机”),支持自定义分类体系。 提供智能搜索功能:按关键词(名称、品牌)搜索,支持模糊匹配和搜索联想;结合用户浏览历史对搜索结果排序(优先展示高相关度商品)。 商品推荐 基于用户浏览、收藏、购买记录,推荐相似商品(如 “浏览过该商品的用户还买了…”)。 首页展示热门商品(销量 TOP10)、新品上架、限时折扣等推荐列表。 三、订单与交易管理 购物车与下单 消费者可将商品加入购物车,支持修改数量、选择规格、移除商品,系统自动计算总价(含运费、折扣)。 下单流程:确认收货地址→选择支付方式(在线支付、货到付款)→提交订单→系统生成唯一订单号。 订单处理流程 订单状态跟踪:待支付→已支付→商家发货→物流运输→消费者收货→订单完成,各状态变更实时通知用户。 商家端功能:查看新订单提醒、确认发货(填写物流单号)、处理退款申请(需审核理由)。 消费者端功能:查看订单详情、追踪物流、申请退款 / 退货、确认收货。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值