题意翻译

题目大意:

nnn个位置,每个位置有两个属性s,cs,cs,c,要求选择3个位置i,j,ki,j,ki,j,k,使得si<sj<sks_i<s_j<s_ksi​<sj​<sk​,并使得ci+cj+ckc_i+c_j+c_kci​+cj​+ck​最小

输入格式:

一行一个整数,nnn,3<=n<=30003<=n<=30003<=n<=3000

一行nnn个整数,即sss

再一行nnn个整数,即ccc

输出格式:

输出一个整数,即最小的c_i+c_j+c_k

枚举 j ,分段暴力;

O(N^2);

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 900005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int n;
ll s[3006];
ll c[3006];
ll minn1[4000];
ll minn2[4000]; int main() {
//ios::sync_with_stdio(0);
rdint(n);
for (int i = 1; i <= n; i++)rdllt(s[i]);
for (int i = 1; i <= n; i++)rdllt(c[i]);
ll ans = inf;
c[0] = c[n + 1] = inf;
for (int i = 2; i < n; i++) {
int l = 0, r = n + 1;
for (int j = 1; j < i; j++) {
if (s[j] < s[i])
if (c[j] < c[l])l = j;
}
for (int j = i + 1; j <= n; j++) {
if (s[j] > s[i])
if (c[j] < c[r])r = j;
}
if (l != 0 && r != n + 1)ans = min(ans, c[i] + c[l] + c[r]);
}
if (ans == inf)cout << -1 << endl;
else cout << ans << endl;
return 0;
}

CF987C Three displays 暴力的更多相关文章

  1. CF987C Three displays【一维DP/类似最大子序列和】

    [链接]:CF987C [分析]:先求出每个s[i]后面比s[i]大的c[i]的最小值,然后枚举前两个数c(i),c(j)以及 j 后面递增且存在最小值的dp(j) [代码]: #include< ...

  2. CF987C Three displays 解题报告

    题目传送门 题目大意 n个位置,每个位置有两个属性s,c,要求选择3个位置i,j,k,使得s_i<s_j<s_k​,并使得c_i+c_j+c_k最小 方法1 n³枚举每一种情况(也许可以拿 ...

  3. CF 987C Three displays DP或暴力 第十一题

    Three displays time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. [暴力搜索] POJ 3087 Shuffle'm Up

    Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10003   Accepted: 4631 Des ...

  5. Codeforces Round #248 (Div. 1) B. Nanami's Digital Board 暴力 前缀和

    B. Nanami's Digital Board 题目连接: http://www.codeforces.com/contest/434/problem/B Description Nanami i ...

  6. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

  7. UVA725 Division (暴力求解法入门)

    uva 725 Division Write a program that finds and displays all pairs of 5-digit numbers that between t ...

  8. U - Three displays

    Problem description It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk ( ...

  9. zone.js - 暴力之美

    在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...

随机推荐

  1. cocos2d-x CSV文件读取 (Excel生成csv文件)

    实现类 CCSVParse.h #ifndef __C_CSV_PARSE__ #define __C_CSV_PARSE__ #include "cocos2d.h" #incl ...

  2. bzoj 4822~4824 CQOI2017题解

    老C的任务 题目大意: 维护一个二维平面,初始给出一些点及其权.多次询问某个矩形内的权和. n,m <= 100000 题解: 签到题. CDQ水一水. #include <cstdio& ...

  3. 洛谷 4149 [IOI2011]Race——点分治

    题目:https://www.luogu.org/problemnew/show/P4149 第一道点分治! 点分治大约是每次找重心,以重心为根做一遍树形dp:然后对于该根的每个孩子,递归下去.递归之 ...

  4. 【Android学习笔记】 点击穿透(Click Through)

    问题:开发一个App,主界面用了Activity,子页面用了Fragment.从Activity跳转到Fragment后Fragment透明,并且点击击穿到Axtivity. 分析:刚开始没有注意到点 ...

  5. virtual judge(专题一 简单搜索 E)

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...

  6. 【转】 Pro Android学习笔记(七七):服务(2):Local Service

    目录(?)[-] Local service代码 调用Local ServiceLocal Service client代码 AndroidManifestxml定义Serviceacitivty的l ...

  7. display与position之间的关系

    以防自己忘记写的 网上找的 positon 与 display 的相互关系 元素分为内联元素和区块元素两类(当然也有其它的),在内联元素中有个非常重要的常识,即内两元素是不可以设置区块元素所具有的样式 ...

  8. 朴素贝叶斯算法分析及java 实现

    1. 先引入一个简单的例子 出处:http://www.ruanyifeng.com/blog/2013/12/naive_bayes_classifier.html 一.病人分类的例子 让我从一个例 ...

  9. VS2010和VS2015的Dll项目

    最近在使用公司VS2010开发的老的项目时,发现一些问题 公司用VS2010开发了一个项目,生成 GUS_TestIdentity.dll, 放在 C:\Windows\assembly 中 当在另一 ...

  10. 《鸟哥的Linux私房菜》读书笔记1

    1.MBR 可以说是整个硬盘最重要的地方了,因为在 MBR 里面记录了两个重要的东西,分别是:开机管理程序,与磁盘分割表 ( partition table ).下次记得人家在谈磁盘分割的时候, 不要 ...