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|$最小. 化简 ...
随机推荐
- appium部分api
转自:http://www.aichengxu.com/view/41510 使用的语言是java,appium的版本是1.3.4,java-client的版本是java-client-2.1.0,建 ...
- sanic官方文档解析之Response和Cookie
1,Sanic的返回的响应体 使用Sanic中的response模块去创建响应对象 返回文本response.text文本(直接字符串就ok) 返回html文件,直接response.html文件(类 ...
- JS简单正则得到字符串中特定的值
这里就直接看演示样例吧.演示样例的目的是为了获取 a 字符串中的 c02806015 <script language="javascript"> var a = '礼 ...
- 有奖试读&征文——我们在互联网上奋斗的故事 获奖名单发布
互联网是一个年轻的行业,同一时候也是一个推陈出新.不断进化的行业. 中国互联网行业在近期的十五年里.以如何的方式在"进化".我相信非常多奋斗在互联网战线上的你们最深有感触.读一读& ...
- 【独立开发人员er Cocos2d-x实战 007】使用Cocos2dx UserDefault.xml
这篇博客是因为下述问题产生的 -(代码1): std::string str = FileUtils::getInstance()->getWritablePath(); CCLOG(str.c ...
- SpringMVC 学习笔记(四) 处理模型数据
Spring MVC 提供了下面几种途径输出模型数据: – ModelAndView: 处理方法返回值类型为 ModelAndView时, 方法体就可以通过该对象加入模型数据 – Map及Model: ...
- git apply、git am打补丁.diff 和 .patch【转】
本文转载自:https://www.jianshu.com/p/e5d801b936b6 前提: 生成patch: git format-patch -M master 生成指定patch,0163b ...
- HDU2181 哈密顿绕行世界问题 —— DFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) ...
- SpringMVC配置环境
一,lib目录下加入spring一般所需的jar包 二,配置web.xml <?xml version="1.0" encoding="UTF-8"?&g ...
- Ubuntu安装mycli,让mysql命令行可以自动提示
安装mycli 1.确保有安装python 2.确保有安装pip 3.进入su模式,以管理员身份安装 4.安装 pip install -U mycli 5.登录 mycli -u root 很好很强 ...