计蒜客 11065 Candy

原题
#Descrition
n个数a[i]
再给这个 n个位置 一个数b[i]
如果 a[i] 比两边的大 那么b[i]也要比两边的大

Σb[i] 最小是多少
#Algorithm
从a[i]最小的开始放 1
再放a[i]第二小的 如果两边都没放 就是 0 那么也可以放1
反正就是放 两边的 之中 最大的 + 1
这样结果肯定最小
应该算贪心把
#Code

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 300 + 9;
int n;
int a[maxn];
struct V
{
  int x, i;
};
V b[maxn];
bool cmp(const V &x, const V &y)
{
  if (x.x < y.x) return true;
  return false;
}
int c[maxn];
void solve()
{
  memset(c, 0, sizeof(c));
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &a[i]);
    b[i].x = a[i];
    b[i].i = i;
  }
  sort(b, b + n, cmp);
  c[b[0].i] = 1;
  for (int i = 1; i < n; i++)
  {
    int s = -1;
    if (b[i].i - 1 >= 0) s = c[b[i].i - 1];
    if ((b[i].i + 1 < n) && c[b[i].i + 1] > s) s = c[b[i].i + 1];
    c[b[i].i] = s + 1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    ans += c[i];
  printf("%d\n", ans);
}
int main()
{
//  freopen("input.txt", "r", stdin);
  while (scanf("%d", &n) != EOF)
    solve();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值