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|$最小. 化简 ...
随机推荐
- Arcgis Engine(ae)接口详解(7):地图(map)操作
IMap map = null; //跟map同一层次的activeView对象,他们都是“地图”的对象,map管理地图内容,activeView管理显示内容 IActiveView activeVi ...
- C语言restrict关键字的使用----可以用来优化代码
C99中新增加了restrict修饰的指针:由restrict修饰的指针是最初唯一对指针所指向的对象进行存取的方法,仅当第二个指针基于第一个时,才能对对象进行存取.对对象的存取都限定于基于由restr ...
- Storm项目:流数据监控1《设计文档…
博客公告: (1)本博客全部博客文章搬迁至<博客虫>http://blogchong.com/ (2)文章相应的源代码下载链接參考博客虫站点首页的"代码GIT". (3 ...
- BZOJ 3992: [SDOI2015]序列统计 快速幂+NTT(离散对数下)
3992: [SDOI2015]序列统计 Description 小C有一个集合S,里面的元素都是小于M的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为N的数列,数列中的每个数都属于集合S ...
- ECMAScript 实现继承的几种方式
1. 原形链 function Father() { this.fatherName = "licus"; } function Children() { this.chidr ...
- Java programming language compiler
https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html\ javac - Java programming l ...
- android adapter公共写法
在开发过程中,会写很多的adapter类,其中很多公共的部分,不需要每次都去书写,可以为开发者省下很多时间 提取一个ListViewAdapter public abstract class List ...
- XMU C语言程序设计实践(3)
问题描述: 以一个n的长方阵表示迷宫,0和1分别表示迷宫中的通路和障碍,设计一个程序,对任意设定的迷宫,求出一条从入口到出口的通路,或得出没有通路的结论. 对于本问题需用栈实现“穷举求解”算法,即:从 ...
- IE9不能直接引用Console
问题: 公司有个项目,功能很简单,读取业务数据,展示在页面上. 一个很简单的问题,却因为目标浏览器是IE9,卡了三天. 前端给的反馈是: 在IE9下,程序一会儿对,一会儿不对--第一次刷不出来,多刷几 ...
- express 中文文档
express() 创建一个express应用程序 var express = require('express'); var app = express(); app.get('/', functi ...