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. 多媒体开发之---h264快速运动估计算法

    #include "stdio.h"#include "stdlib.h"#include "malloc.h"#include " ...

  2. cat /proc/cpuinfo | awk -F: '/name/{print $2}' | uniq -c

    cat /proc/cpuinfo | awk -F: '/name/{print $2}' | uniq -c

  3. 如何解决Windows的端口占用问题?

    已知某应用在启动时会创建服务套接字,并将其绑定至端口8888,然而端口8888已被占用,如何解除占用? 以下为解决方案: 在cmd中运行netstat -ano|findstr 8888,其中的参数8 ...

  4. C++,Base64编解码字符串或文件

    参考链接:在C语言中使用libb64进行Base64编解码 GitHub地址:https://github.com/BuYishi/cpp_base64_demo base64_demo.cpp #i ...

  5. ubuntu12.04配置NFS服务详解

    1:安装nfs sudo apt-get install nfs-kernel-server 2:配置服务 sudo vim /etc/exports 在末尾添加 /home/jyg *(rw,syn ...

  6. bzoj3137: [Baltic2013]tracks

    炸一看好像很神仙的样子,其实就是个sb题 万年不见的1A 但是我们可以反过来想,先选一个起点到终点的联通块,然后这联通块后面相当于就能够走了,继续找联通块 然后就能发现直接相邻的脚步相同的边权为0,否 ...

  7. Javascript中两种最通用的定义类的方法

    在Javascript中,一切都是对象,包括函数.在Javascript中并没有真正的类,不能像C#,PHP等语言中用 class xxx来定义.但Javascript中提供了一种折中的方案:把对象定 ...

  8. 使用gcc找出头文件的路径

    参考 http://stackoverflow.com/questions/13079650/how-can-i-find-the-header-files-of-the-c-programming- ...

  9. 使用cocoaPods加载框架的具体步骤:

    注意事项: 1.使用之前备份一下代码.因为pod更新很快,如果某个文件名有中文,pod install 一下.整个项目可能就要废掉了. 2.如果不把pod文件推动到远程服务器. 每一次用的时候在本地p ...

  10. 安装YCM出现:YouCompleteMe unavailable no module named frozendict或者 YouCompleteMe unavailable no module named future

    参考博文:http://blog.sina.com.cn/s/blog_8f70642d0102wo57.html 原因就是你或者没用Vundle安装,或者Vundle由于网速太慢下载到一半不能把安装 ...