题意:一个桌子有n条腿,每条腿有一定的长度l,和砍下的花费w,现在规定,桌子稳的条件是长度最长的腿(可多个)的数量大于长度小于它的桌子腿数量,且不存在比他还长的桌子腿,求让桌子腿稳定的最小的花费

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const double pi=acos(-);
const int mod=;
int max(int a,int b)
{return a>b?a:b;};
int min(int a,int b)
{return a<b?a:b;}; const int maxl=;
struct node{
int l,w;
}ne[]; bool cmp(node a,node b)
{
return a.l<b.l;
} vector<int> numw[];
int n,num[maxl+],total[maxl+]; void solve()
{
int ans=inf;
for(int i=;i<=maxl;i++)
if(num[i])
{
int temp=total[i+],k=num[i]-num[i+];
int cnt=num[]-num[i]-(k-);
if(cnt>)
{
for(int j=;j<=;j++)
if(numw[j].size())
{
//printf(":2\n");
if(cnt<=) break;
int p=lower_bound(numw[j].begin(),numw[j].end(),i)-numw[j].begin();//花费为j的桌子腿中长度>=i的个数
temp+=min(p,cnt)*j;
cnt-=p;
// printf(":3\n");
}
}
ans=min(ans,temp);
}
printf("%d\n",ans);
} void init()
{
memset(total,,sizeof(total));
memset(num,,sizeof(num));
for(int i=;i<=;i++)
numw[i].clear();
} void input()
{
init();
//printf("||5\n");
for(int i=;i<=n;i++)
{
scanf("%d",&ne[i].l);
num[ne[i].l]++;
}
for(int i=;i<=n;i++)
{
scanf("%d",&ne[i].w);
numw[ne[i].w].push_back(ne[i].l);
}
//printf("|||6\n");
sort(ne+,ne+n+,cmp);
for(int i=;i<=n;)
{
int p=i;
while(ne[p].l==ne[i].l&&i<=n)
{
total[ne[p].l]+=ne[i].w;
i++;
}
}
for(int i=maxl;i>=;i--)
{
total[i]+=total[i+];
num[i]+=num[i+];
}//total数组统计砍下长度>=i的所有桌子腿的总花费
//num数组记录长度>=i的桌子腿的个数
for(int i=;i<=;i++)
if(numw[i].size())
sort(numw[i].begin(),numw[i].end());
} int main()
{
while(~scanf("%d",&n))
{
input();
solve();
}
return ;
}

核心思路:先暴力枚举最长的桌子腿腿长(1e5),然后再按花费(<=200)进行从小到大的贪心选取

,每次在花费为w上进行贪心时,找出小于当前枚举的长度的桌子腿个数,本题的实现是个大难题

错因分析:本来想用优先队列来维护权花费为w的长度序列的,实现本代码中vector的操作,但是优先队列

没有迭代器,不支持begin()这个操作,也就是priority_queue<node> a[100],a[1]就是代表一个优先队列,没有a[1].begin()这个操作,事实上优先队列只有pop(),top(),和insert(),这三个操作,其实就是个堆。

CodeForces 557C Arthur and Table STL的使用的更多相关文章

  1. Arthur and Table CodeForces - 557C

    Arthur and Table CodeForces - 557C 首先,按长度排序. 长度为p的桌腿有a[p]个. 要使得长度为p的桌腿为最长,那么要按照代价从小到大砍掉sum{长度不到p的腿的数 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. CF-557C Arthur and Table 权值线段树

    Arthur and Table 题意 一个桌子有n个腿,每个腿都有一个高度,当且仅当最高的腿的数量大于桌子腿数量的一半时,桌子才是稳定的.特殊的是当只有一个腿时,桌子是稳定的,当有两个腿时两个腿必须 ...

  6. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. Codeforces 448 D. Multiplication Table

    二分法判断答案 D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes inp ...

  8. Codeforces 448 D. Multiplication Table 二分

    题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...

  9. Codeforces 40 E. Number Table

    题目链接:http://codeforces.com/problemset/problem/40/E 妙啊... 因为已经确定的格子数目严格小于了$max(n,m)$,所以至少有一行或者一列是空着的, ...

随机推荐

  1. Find Duplicate Subtrees

    Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only ne ...

  2. [转帖]全方位掌握OpenStack技术知识

    全方位掌握OpenStack技术知识 http://www.itpub.net/2019/06/17/2206/ 架构师技术联盟的文章 相当好呢. 大家好,我是小枣君.最近几年,OpenStack这个 ...

  3. 纯前端表格控件SpreadJS V12.1 隆重登场,专注易用性,提升用户体验

    ​ 一款优秀的开发工具,在更新迭代中,除了要满足不同场景的业务需求,也需不断优化已有功能,尤其是细节方面,要能为用户带来使用体验和开发效率的提升. 作为一款备受业界专家和开发者认可的纯前端类Excel ...

  4. delphi 连接各中数据库方法

    ---恢复内容开始--- 数据库连接字符串的拼写规则的决定条件: • 连接的数据库的类型:SQL Server,Oracle,MySQL,Acess,MogoDB,Visual FoxPro(dBAS ...

  5. mysql开启和关闭安全模式

    今天在进行数据库UPDATE的时候出了一个问题,我把非主键的字段当作UPDATE的条件(筛选条件)时,提示了如下的语句 Error Code: 1175. You are using safe upd ...

  6. 基于MatConvNet的CNN图像搜索引擎PicSearch

    简介 Picsearch是一种基于卷积神经网络特征的图像搜索引擎. Github:https://github.com/willard-yuan/CNN-for-Image-Retrieval Web ...

  7. [Next] next中文文档

    Next.js 是一个轻量级的 React 服务端渲染应用框架. 怎么使用 安装 在项目文件夹中运行: npm install --save next react react-dom 将下面脚本添加到 ...

  8. java中的重写总结

    这个理解了就挺容易的~~ 我就直接贴个程序啦 ,程序里有说明!! 父类: package ParentAndSon; public class Parent extends Object {//4:以 ...

  9. Docker搭建Gitlab服务器

    1.使用docker搜索gitlab镜像 docker search gitlab 2.下载镜像: docker pull docker.io/gitlab/gitlab-ce 3.查看docker镜 ...

  10. mybatis-generator的功能扩展

    项目代码地址:https://github.com/whaiming/java-generator 我在原有的基础上扩展了和修改了一些功能: 1.增加获取sqlServer数据库字段注释功能 2.Ma ...