Codeforces Round #311 (Div. 2) C. Arthur and Table
来源:互联网 发布:淘宝客服是什么工作 编辑:程序博客网 时间:2024/06/06 09:03
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has n legs, the length of thei-th leg isli.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined numberdi — the amount of energy that he spends to remove thei-th leg.
A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.
Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.
The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of n integersli (1 ≤ li ≤ 105), whereli is equal to the length of thei-th leg of the table.
The third line of the input contains a sequence of n integersdi (1 ≤ di ≤ 200), wheredi is the number of energy units that Arthur spends on removing thei-th leg off the table.
Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.
21 53 2
2
32 4 41 1 1
0
62 2 1 1 3 34 3 5 5 2 1
8
题意:给你一张桌子,有n条腿,告诉每条腿的长度(l)以及砍掉这条腿的花费(d),当最长腿的数量超过总数量的1/2,那么合法。问如何使得花费最小达到合法情况。
分析:暴力枚举。假设以腿长为a作为最长腿且腿a共有y条,计算花费cost需分两步:
(1)、腿长大于a的,都要砍掉,则cost+=bigger[a];(bigger[a]可预处理得到)
(2)、腿长小于a的,假设有x条,则需要从小到大依次减去x-y+1条。由于花费d的范围只有1~200,所以可以利用花费来计算。
题目链接:http://codeforces.com/contest/557/problem/C
代码清单:
#include<queue>#include<stack>#include<cstdio>#include<iostream>#include<algorithm>using namespace std;typedef long long ll;const int maxn = 1e5 + 5;const ll maxv = 1e10 + 5;int n;struct Edge{int l,d;}leg[maxn];int cost[maxn]; ll Back[maxn];int num[maxn]; bool cmp(Edge a,Edge b){ return a.l<b.l;}int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&leg[i].l); num[leg[i].l]++; } for(int i=0;i<n;i++) scanf("%d",&leg[i].d); sort(leg,leg+n,cmp); ll sum=0; for(int i=n-1;i>0;i--){ //计算腿长比leg[i-1].l大的总花费 sum+=(ll)leg[i].d; if(leg[i].l!=leg[i-1].l){ Back[leg[i-1].l]=sum; } } ll ans=Back[leg[0].l]; cost[leg[0].d]++; for(int i=1;i<n;i++){ if(leg[i].l!=leg[i-1].l){ int an=i-num[leg[i].l]+1; sum=Back[leg[i].l]; if(an>0){ for(int j=1;j<=200;j++){ //从小到大依次减去an数量的腿 if(cost[j]){ if(cost[j]>=an){ sum+=(an*j); an=0; break; } else{ sum+=(cost[j]*j); an-=cost[j]; } } } } ans=min(ans,sum); } cost[leg[i].d]++; } printf("%I64d\n",ans); return 0;}
- Codeforces Round #311 (Div. 2) C. Arthur and Table
- Codeforces Round #311 (Div. 2) C. Arthur and Table
- Codeforces Round #311 (Div. 2)-C. Arthur and Table
- C. Arthur and Table(Codeforces Round #311 (Div. 2) 贪心)
- CodeForces#311 C. Arthur and Table
- Codeforces Round #288 (Div. 2)E. Arthur and Brackets
- Codeforces Round #293 (Div. 2) E - Arthur and Questions
- Codeforces Round #297 (Div. 2) D. Arthur and Walls
- Codeforces Round #297 (Div. 2) D - Arthur and Walls
- Codeforces Round #297 (Div. 2) D Arthur and Walls
- codeforces #311 C 557C. Arthur and Table(枚举+贪心)
- codeforces 311(div2)C-Arthur and Table
- Codeforces 557C Arthur and Table 砍桌腿
- codeforces 557c Arthur and Table
- Codeforces 557C Arthur and Table
- 【codeforces 557C Arthur and Table】+ 思维
- 【35.29%】【codeforces 557C】Arthur and Table
- Codeforces 557C Arthur and Table【思维】
- ArtTemplate的简单介绍
- iOS设计模式之单例
- Stringbuffer 关于逗号的使用
- chromium:LoadUrl之后会发生那些事情之GraphicsLayer创建
- sphinx 增量索引
- Codeforces Round #311 (Div. 2) C. Arthur and Table
- Sqlserver导入数据
- Java多线程(二)、线程的生命周期和状态控制
- Product of Array Except Self
- Leetcode: Product of Array Except Self
- 关于OPENCV中链接库容易加载错误的解决方案
- c# 多线程 调用带参数函数
- struts2之如何向服务器上传文件
- Spring AOP 实现原理