Arthur and Table CodeForces - 557C

首先,按长度排序。

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

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

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

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

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. struct Leg
  5. {
  6. int len,cost,len2;
  7. bool operator<(const Leg& b) const
  8. {
  9. return len<b.len||(len==b.len&&cost<b.cost);
  10. }
  11. }l[];
  12. int l2[];
  13. int sum1,n,ans=0x3f3f3f3f,now,now2,now3,sum2;
  14. int main()
  15. {
  16. int i,j;
  17. scanf("%d",&n);
  18. for(i=;i<=n;i++)
  19. scanf("%d",&l[i].len);
  20. for(i=;i<=n;i++)
  21. scanf("%d",&l[i].cost);
  22. sort(l+,l+n+);
  23. for(i=;i<=n;i++)
  24. if(l[i].len!=l[i-].len)
  25. l[i].len2=l[i-].len2+;
  26. else
  27. l[i].len2=l[i-].len2;
  28. for(i=;i<=n;i++)
  29. sum2+=l[i].cost;
  30. for(i=;i<=n;i++)
  31. {
  32. sum2-=l[i].cost;
  33. now++;
  34. if(l[i].len2==l[i+].len2) continue;
  35. now2=sum1-now+;
  36. if(now2<=)
  37. {
  38. ans=min(sum2,ans);
  39. }
  40. else
  41. {
  42. now3=;
  43. for(j=;j<=;j++)
  44. {
  45. if(l2[j]>=now2)
  46. {
  47. now3+=j*now2;
  48. break;
  49. }
  50. now2-=l2[j];
  51. now3+=j*l2[j];
  52. }
  53. ans=min(now3+sum2,ans);
  54. }
  55. for(j=i;l[j].len2==l[j-].len2;j--)
  56. l2[l[j].cost]++;
  57. l2[l[j].cost]++;
  58. sum1+=now;
  59. now=;
  60. }
  61. printf("%d",ans);
  62. return ;
  63. }

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. Android_Service详解及实例

    转自:http://blog.csdn.net/guolin_blog/article/details/11952435    http://blog.csdn.net/guolin_blog/art ...

  2. LWIP在STM32上的移植

    本文做记录摘抄,加上自己的体会: 文章标题:STM32使用LWIP实现DHCP客户端 http://www.cnblogs.com/dengxiaojun/p/4379545.html 该文章介绍了几 ...

  3. SQL JOIN连接分类[转]

    1.内联接(典型的联接运算,使用像 =  或 <> 之类的比较运算符):包括相等联接和自然联接: 内联接使用比较运算符根据每个表共有的列的值匹配两个表中的行:    2.外联接.外联接可以 ...

  4. java包和javax包的区别

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

  5. js中数组遍历的几种方法及其区别

    参考网站: http://www.cnblogs.com/lvmh/p/6104397.html 第一种最常用的:for循环 for(j = 0; j < arr.length; j++) { ...

  6. js中return的作用

    1.终止函数的继续运行. 当遇到if…… else是.若出现return,就会出现终止运行,不会继续做出判断 <html> <head> <title>return ...

  7. POJ1087 A Plug for UNIX —— 最大流

    题目链接:https://vjudge.net/problem/POJ-1087 A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K T ...

  8. POJ2976 Dropping tests —— 01分数规划 二分法

    题目链接:http://poj.org/problem?id=2976 Dropping tests Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  9. dedecms文章内页获取缩略图的调用标签

    点评:文章内容页缩略图的调用,图片集内容页缩略图的调用很容易混淆,内页想调用缩略图用[filed:picname/]来实现是错误的 文章内容页缩略图的调用,图片集内容页缩略图的调用,相信大家都想找这个 ...

  10. ES6 数组的解构赋值

    数组的解构赋值 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前,为变量赋值,只能直接指定值. let a = 1; let b = ...