Arthur and Table CodeForces - 557C
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- CF-557C Arthur and Table 权值线段树
Arthur and Table 题意 一个桌子有n个腿,每个腿都有一个高度,当且仅当最高的腿的数量大于桌子腿数量的一半时,桌子才是稳定的.特殊的是当只有一个腿时,桌子是稳定的,当有两个腿时两个腿必须 ...
- 【35.29%】【codeforces 557C】Arthur and Table
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- CodeForces 557C Arthur and Table STL的使用
题意:一个桌子有n条腿,每条腿有一定的长度l,和砍下的花费w,现在规定,桌子稳的条件是长度最长的腿(可多个)的数量大于长度小于它的桌子腿数量,且不存在比他还长的桌子腿,求让桌子腿稳定的最小的花费 #i ...
- 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 ...
- Arthur and Walls CodeForces - 525D (bfs)
大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...
- Arthur and Questions CodeForces - 518E (贪心模拟)
大意: 给定序列$a$, 某些位置为'?', 求给'?'赋值使得序列$(a_1+a_2+...+a_k,a_2+a_3+...+a_{k+1},...)严格递增, 且$\sum|a_i|$最小. 化简 ...
随机推荐
- Android_Service详解及实例
转自:http://blog.csdn.net/guolin_blog/article/details/11952435 http://blog.csdn.net/guolin_blog/art ...
- LWIP在STM32上的移植
本文做记录摘抄,加上自己的体会: 文章标题:STM32使用LWIP实现DHCP客户端 http://www.cnblogs.com/dengxiaojun/p/4379545.html 该文章介绍了几 ...
- SQL JOIN连接分类[转]
1.内联接(典型的联接运算,使用像 = 或 <> 之类的比较运算符):包括相等联接和自然联接: 内联接使用比较运算符根据每个表共有的列的值匹配两个表中的行: 2.外联接.外联接可以 ...
- java包和javax包的区别
基本类库和扩展类库 一般的lang,util都放在java.包 servlet放在javax包 以前sun把java中的叫核心库,把javax中的叫扩展库.现在sun已经把java和javax中的都叫 ...
- js中数组遍历的几种方法及其区别
参考网站: http://www.cnblogs.com/lvmh/p/6104397.html 第一种最常用的:for循环 for(j = 0; j < arr.length; j++) { ...
- js中return的作用
1.终止函数的继续运行. 当遇到if…… else是.若出现return,就会出现终止运行,不会继续做出判断 <html> <head> <title>return ...
- POJ1087 A Plug for UNIX —— 最大流
题目链接:https://vjudge.net/problem/POJ-1087 A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K T ...
- POJ2976 Dropping tests —— 01分数规划 二分法
题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS Memory Limit: 65536K Total S ...
- dedecms文章内页获取缩略图的调用标签
点评:文章内容页缩略图的调用,图片集内容页缩略图的调用很容易混淆,内页想调用缩略图用[filed:picname/]来实现是错误的 文章内容页缩略图的调用,图片集内容页缩略图的调用,相信大家都想找这个 ...
- ES6 数组的解构赋值
数组的解构赋值 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前,为变量赋值,只能直接指定值. let a = 1; let b = ...