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. IBM中国研究院、SAP、网易游戏、IBM2015应届生招聘笔试面试问题分享

    IBM中国研究院实习生 早在今年4月份.我面试的是IBM中国研究院的实习生岗位.主要是自然语言处理和语义网方向.那时我还在香港上学,两个考官对我进行的是电话面试,大概持续半个多小时,首先是我的自我介绍 ...

  2. 转载:用python爬虫抓站的一些技巧总结

    原文链接:http://www.pythonclub.org/python-network-application/observer-spider 原文的名称虽然用了<用python爬虫抓站的一 ...

  3. spring cloud 启动报错-must be declared as an @AliasFor [serviceId], not [name].

    项目加入FeignClient后再启动就报错,具体报错信息如下: org.springframework.core.annotation.AnnotationConfigurationExceptio ...

  4. java包和javax包的区别

    基本类库和扩展类库 一般的lang,util都放在java.包 servlet放在javax包 以前sun把java中的叫核心库,把javax中的叫扩展库.现在sun已经把java和javax中的都叫 ...

  5. HDU3294 Girls' research —— Manacher算法 输出解

    题目链接:https://vjudge.net/problem/HDU-3294 Girls' research Time Limit: 3000/1000 MS (Java/Others)    M ...

  6. UVA-10600(次小生成树)

    题意: 现在给一个图,问最小生成树和次小生成树的权值和是多少; 思路: 求最小生成树的两种方法,次小生成树是交换最小生成树的其中一条边得到的,现在得到了最小生成树,枚举不在次小生成树中的边,再求一边最 ...

  7. UVA-11549(floyd判圈算法)

    题意: 给一个整数k,每次平方后只能显示结果的前n位,问在这个过程中能得到的最大的数是多少; 思路: floyd判圈算法;它的正确性建立在这得到的这些数是有限的,所以一定是一个循环,在这个循环的圈里面 ...

  8. BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组

    BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组 Description        给定N个数对(xi, yi),求最长上升子 ...

  9. [POI 2007] 办公楼

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1098 [算法] 显然 , 答案为补图的连通分量个数 用链表优化BFS , 时间复杂度 ...

  10. [USACO11NOV]二进制数独Binary Sudoku

    传送门 这道题是很好的一道IDA*练习题. 首先我们先确定搜索的框架,我们要求的是用最少的修改次数使得所有的行,列,宫之内都有偶数个1,最直观的想法显然是先预处理出有奇数个1的行,列,宫,之后枚举每一 ...