题意:一个桌子有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. Microsoft SQL server 2012数据库学习总结(一)

    一.Microsoft SQL Server2012简介 1.基本概要 Microsoft SQL Server 2012是微软发布的新一代数据平台产品,全面支持云技术与平台,并且能够快速构建相应的解 ...

  2. java this的作用

    this: 区分成员变量和局部变量的重名问题,this.name指的是类中的成员变量,而不是方法内部的

  3. Coins —— POJ-1742

    Time limit 3000 ms Memory limit 30000 kB Description People in Silverland use coins.They have coins ...

  4. CentOS7 Python3安装redis

    CentOS7安装配置Redis 第一步:下载redis安装包 wget http://download.redis.io/releases/redis-4.0.9.tar.gz 想下载哪个版本可以复 ...

  5. idea 设置自动生成注释

    idea新建类注释规则 /** @ProjectName: ${PROJECT_NAME} @Package: ${PACKAGE_NAME} @ClassName: ${NAME} @Descrip ...

  6. Java new运算符解析

    1.创建数组时,不使用new操作符 Person [] a; a[0]=new Person(); //Error:variable a might not have been initialized ...

  7. WPF中Matrix介绍

    最近在做一些图形变换操作的功能,图形变换涉及大学中的矩阵运算部分的知识,又重新复习了一下矩阵.这里做一下记录.由于不知道矩阵如何输入,一个个截图又麻烦,所以这里就全部用截图了^-^.

  8. Webpack loaderUtils.parseQuery()

    https://blog.256pages.com/webpack-loaderutils-parsequery/

  9. 原生JS+CSS实现日期插件

    笔者最近在学习Element UI,觉得它提供的日期选择器既简单又美观,于是仿照着写了一个日期插件.笔者使用到的技术有ES5.CSS和HTML,控件兼容IE10+和谷歌浏览器.有一点需要注意,笔者使用 ...

  10. Jquery.serializeArray()可看表单提交内容