CF987C Three displays 暴力
题意翻译
题目大意:
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 暴力的更多相关文章
- CF987C Three displays【一维DP/类似最大子序列和】
[链接]:CF987C [分析]:先求出每个s[i]后面比s[i]大的c[i]的最小值,然后枚举前两个数c(i),c(j)以及 j 后面递增且存在最小值的dp(j) [代码]: #include< ...
- CF987C Three displays 解题报告
题目传送门 题目大意 n个位置,每个位置有两个属性s,c,要求选择3个位置i,j,k,使得s_i<s_j<s_k,并使得c_i+c_j+c_k最小 方法1 n³枚举每一种情况(也许可以拿 ...
- CF 987C Three displays DP或暴力 第十一题
Three displays time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- [暴力搜索] POJ 3087 Shuffle'm Up
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10003 Accepted: 4631 Des ...
- 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 ...
- 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 ...
- UVA725 Division (暴力求解法入门)
uva 725 Division Write a program that finds and displays all pairs of 5-digit numbers that between t ...
- U - Three displays
Problem description It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk ( ...
- zone.js - 暴力之美
在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...
随机推荐
- hsv空间
hsv在不同的软件中,有不同的阈值, 在描述阈值之前,看一下它的定义,按照标准的定义,hsv应该是从0°到360°的一个环,加上一个表示亮度的轴,重点就是那个环. 这个环如图一,0°一般为红色120° ...
- 判断CPU是大端还是小端
#include "stdafx.h" #include <iostream> using namespace std; /* #大端模式(Big_endian):字数 ...
- CI中控制器名不能和本个 控制器中的方法名相同
控制器名称:application/controllers/tang.php 控制器中方法名称:application/controllers/role.php 中有方法 public funct ...
- Metasploit的使用下篇——漏洞攻击
一.上文总结 上篇当中主要通过开启的端口对目标主机进行攻击,最后成功做到了连接不过却不能查看到telnet的登陆用户名和密码,目前来看有两个原因:第一.我对于靶机telnet的设置有问题,没有设置相应 ...
- Oracle中spool命令实现的两种方法比较
---恢复内容开始--- 要输出符合要求格式的数据文件只需在select时用字符连接来规范格式.比如有如下表 SQL>; select id,username,password from myu ...
- Python 转义字符中没有这个 「\e」 !
问题来源于技术交流群里: 常见的转义字符 \n.\t 之类的我们都知道什么意思,但是这个 \e 是什么意思呢? 抱着一股钻研的精神,我搜了一把. 结果,所有的页面里都是只有一句简单的 \e 代表转义. ...
- Winform程序实现多显示屏、多屏幕显示的2种方法
这篇文章主要介绍了Winform窗口实现多显示屏显示的2种方法,本文直接给出了实现代码,并对其中的一些重要参数做了解释,需要的朋友可以参考下. 一台主机连接了2台显示器(2个显卡),要求一个程序的两个 ...
- 系列文章--AJAX技术系列总结
各种AJAX方法的使用比较 用ASP.NET写个SQLSERVER的小工具 写自己的ASP.NET MVC框架(下) 写自己的ASP.NET MVC框架(上) 用Asp.net写自己的服务框架 ...
- linux绑定多个ip(转载)
在Linux下有时候需要给一个网卡绑定多个IP,本文介绍在Redhat系列(redhat,Fedora Core,Centos)中的实现方法和一种在Gentoo等其他Linux中普遍适用的方法. 1. ...
- script加载之defer和async
详情请查看:http://www.heiboard.com/?p=2098