Arthur and Table CodeForces - 557C

首先,按长度排序。

长度为p的桌腿有a[p]个。

要使得长度为p的桌腿为最长,那么要按照代价从小到大砍掉sum{长度不到p的腿的数量}-a[p]+1条腿。还需要将所有长于p的桌腿砍光。枚举p即可。

要点(看了题解才明白):可以通过精力最高只有200的条件,大大缩小时间/空间复杂度。

恩,所以...这是贪心吧?

 #include<cstdio>
#include<algorithm>
using namespace std;
struct Leg
{
int len,cost,len2;
bool operator<(const Leg& b) const
{
return len<b.len||(len==b.len&&cost<b.cost);
}
}l[];
int l2[];
int sum1,n,ans=0x3f3f3f3f,now,now2,now3,sum2;
int main()
{
int i,j;
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d",&l[i].len);
for(i=;i<=n;i++)
scanf("%d",&l[i].cost);
sort(l+,l+n+);
for(i=;i<=n;i++)
if(l[i].len!=l[i-].len)
l[i].len2=l[i-].len2+;
else
l[i].len2=l[i-].len2;
for(i=;i<=n;i++)
sum2+=l[i].cost;
for(i=;i<=n;i++)
{
sum2-=l[i].cost;
now++;
if(l[i].len2==l[i+].len2) continue;
now2=sum1-now+;
if(now2<=)
{
ans=min(sum2,ans);
}
else
{
now3=;
for(j=;j<=;j++)
{
if(l2[j]>=now2)
{
now3+=j*now2;
break;
}
now2-=l2[j];
now3+=j*l2[j];
}
ans=min(now3+sum2,ans);
}
for(j=i;l[j].len2==l[j-].len2;j--)
l2[l[j].cost]++;
l2[l[j].cost]++;
sum1+=now;
now=;
}
printf("%d",ans);
return ;
}

Arthur and Table CodeForces - 557C的更多相关文章

  1. Codeforces Round #311 (Div. 2) C. Arthur and Table Multiset

    C. Arthur and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/p ...

  2. Codeforces Round #311 (Div. 2)C. Arthur and Table

    C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. C. Arthur and Table(Codeforces Round #311 (Div. 2) 贪心)

    C. Arthur and Table time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. CF-557C Arthur and Table 权值线段树

    Arthur and Table 题意 一个桌子有n个腿,每个腿都有一个高度,当且仅当最高的腿的数量大于桌子腿数量的一半时,桌子才是稳定的.特殊的是当只有一个腿时,桌子是稳定的,当有两个腿时两个腿必须 ...

  5. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. CodeForces 557C Arthur and Table STL的使用

    题意:一个桌子有n条腿,每条腿有一定的长度l,和砍下的花费w,现在规定,桌子稳的条件是长度最长的腿(可多个)的数量大于长度小于它的桌子腿数量,且不存在比他还长的桌子腿,求让桌子腿稳定的最小的花费 #i ...

  7. Day8 - D - Multiplication Table CodeForces - 448D

    Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the mu ...

  8. Arthur and Walls CodeForces - 525D (bfs)

    大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...

  9. Arthur and Questions CodeForces - 518E (贪心模拟)

    大意: 给定序列$a$, 某些位置为'?', 求给'?'赋值使得序列$(a_1+a_2+...+a_k,a_2+a_3+...+a_{k+1},...)严格递增, 且$\sum|a_i|$最小. 化简 ...

随机推荐

  1. HDU 4085 Peach Blossom Spring 斯坦纳树 状态压缩DP+SPFA

    状态压缩dp+spfa解斯坦纳树 枚举子树的形态 dp[i][j] = min(dp[i][j], dp[i][k]+dp[i][l]) 当中k和l是对j的一个划分 依照边进行松弛 dp[i][j]  ...

  2. positive 相对其正常位置,那什么是正常位置: 请问调试,请问浏览器

    [问题代码 <!DOCTYPE html><html><head> <title></title> <meta charset=&qu ...

  3. Java programming language compiler

    https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html\ javac - Java programming l ...

  4. vscode部分文件夹无法打开

    vscode部分文件夹无法打开,无法正常显示 解决方案:关闭该IDE.找到C:\Users\XX\AppData\Roaming\Code,将Code文件夹删除.重新打开vsCode,即可恢复.但是以 ...

  5. opencv VS2010配置

    一.下载 opencv下载地址:http://www.opencv.org.cn/  点击下载栏 最新的可能有3.2了,但是支持的VS版本是VS2012等版本.这里只选用2.4.9版本 下载后就是安装 ...

  6. i MySQL 查看约束,添加约束,删除约束

    查看表的字段信息:desc 表名; 查看表的所有信息:show create table 表名; 添加主键约束:alter table 表名 add constraint 主键 (形如:PK_表名) ...

  7. gnss到底是什么呢

    GNSS Global Navigation Satellite System 全球卫星导航系统:提到这个很多人会不明白GNSS倒是是个啥东西呢,和北斗,GPS, GLONASS,Galileo系统有 ...

  8. POJ2516 Minimum Cost —— 最小费用最大流

    题目链接:https://vjudge.net/problem/POJ-2516 Minimum Cost Time Limit: 4000MS   Memory Limit: 65536K Tota ...

  9. Couldn't connect to host, port: smtp.163.com, 25; timeout -1;

    运行出现以下报错: Couldn't connect to host, port: smtp.163.com, 25; timeout -1; 也要设置端口 spring.mail.port=25

  10. 广大暑假训练1(poj 2488) A Knight's Journey 解题报告

    题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A   (A - Children of the Candy Corn) ht ...