Codeforces Round #485 (Div. 2) C题求三元组(思维)
1 second
256 megabytes
standard input
standard output
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are nn displays placed along a road, and the ii-th of them can display a text with font size sisi only. Maria Stepanovna wants to rent such three displays with indices i<j<ki<j<k that the font size increases if you move along the road in a particular direction. Namely, the condition si<sj<sksi<sj<sk should be held.
The rent cost is for the ii-th display is cici. Please determine the smallest cost Maria Stepanovna should pay.
The first line contains a single integer nn (3≤n≤30003≤n≤3000) — the number of displays.
The second line contains nn integers s1,s2,…,sns1,s2,…,sn (1≤si≤1091≤si≤109) — the font sizes on the displays in the order they stand along the road.
The third line contains nn integers c1,c2,…,cnc1,c2,…,cn (1≤ci≤1081≤ci≤108) — the rent costs for each display.
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i<j<ki<j<k such that si<sj<sksi<sj<sk.
5
2 4 5 4 10
40 30 20 10 40
90
3
100 101 100
2 4 5
-1
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
33
In the first example you can, for example, choose displays 11, 44 and 55, because s1<s4<s5s1<s4<s5 (2<4<102<4<10), and the rent cost is 40+10+40=9040+10+40=90.
In the second example you can't select a valid triple of indices, so the answer is -1.
题意:选三个数,要求:i<j<k 且a[i]<a[j]<a[k],要求选出来的三个数的权值最小
思路:开始总想的是贪心,二分啥啥啥的。。。结果仔细想了下,他的范围是3000, O(n^3)的时间复杂度肯定不行,O(n^2)就可以过
只要我预处理第三个数,在每个数这从后面找一个权值最小且大于它的数,以此来作为第三个数即可,后面只要枚举两个数即可
#include<cstdio>
#include<cmath>
#include<iostream>
#define ll long long
using namespace std;
ll a[],b[],dp[];
int main() {
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
for(int i=;i<n;i++)
scanf("%d",&b[i]);
for(int i=;i<n;i++)
{
ll mn=;
for(int j=i+;j<n;j++) {
if(a[i]<a[j]) {
mn=min(mn,b[j]);
}
}
dp[i]=mn;
}
ll ans=;
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
if(a[i]<a[j])
{
if(dp[j]!=)
ans=min(ans,b[i]+b[j]+dp[j]);
}
}
}
if(ans==) printf("-1\n");
else cout<<ans<<endl;
}
总结:总的来说这次cf div2的题目不是很难,只是自己刷提还是刷的太少了,没想到思路就卡到了,训练太少,刷题太慢,需要好好反省
规律题总结,看到那种遍历一遍就超时那就肯定是规律题,一 班自己先把公式推出来,然后写个小枚举,把答案输出出来,然后自己再把递推公式推出来,再求解即可
Codeforces Round #485 (Div. 2) C题求三元组(思维)的更多相关文章
- Codeforces Round #485 (Div. 2)
Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #485 (Div. 2) D. Fair
Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description ...
- Codeforces Round #485 (Div. 2) E. Petr and Permutations
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...
- Codeforces Round #485 (Div. 2) C. Three displays
Codeforces Round #485 (Div. 2) C. Three displays 题目连接: http://codeforces.com/contest/987/problem/C D ...
- Codeforces Round #485 (Div. 2) A. Infinity Gauntlet
Codeforces Round #485 (Div. 2) A. Infinity Gauntlet 题目连接: http://codeforces.com/contest/987/problem/ ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
随机推荐
- 20171114xlVba选定单行记录并打印
Public Sub PrintSelectRow() Dim Wb As Workbook Dim iSht As Worksheet Dim rSht As Worksheet Dim pSht ...
- Nginx安装与使用 及在redhat 中的简单安装方式
首先说下在redhat中的安装方法, 正常安装nginx 需要安装很多的依赖,最后再安装nginx,而且很容易出错. 在nginx官方上有这么一段描述: Pre-Built Packages for ...
- 微信小程序页面内转发 按钮 转发
通过给 button 组件设置属性 open-type="share",可以在用户点击按钮后触发 Page.onShareAppMessage() 事件,如果当前页面没有定义此事件 ...
- Fiddler抓包分析
在Fiddler的web session界面捕获到的HTTP请求如下图所示: 各字段的详细说明已经解释过,这里不再说明.需要注意的是#号列中的图标,每种图标代表不同的相应类型,具体的类型包括: ...
- numpy学习:数据预处理
待处理的数据:150*150的灰度图片,除分析目标外,背景已经抹0 需要实现的目标:背景数字0不变,对其余数字做一个归一化处理 对list处理可以用 a=list(set(a)) # 实现了去除重复元 ...
- php 常用函数总结
1. is_numeric() // 判断变量是不是数字或者数字字符串 2. array_column() // 获取某一列 3. array_search() // array_search(val ...
- 轻量级RPC
①自定义一个协议接口继承VersionedProtocol ②自定义协议类实现上面的接口,完善功能需求 ③服务端 ④客户端 二:模拟一个namenode
- js时间与时间戳互相转换
var _time1 = Date.parse(new Date(‘2017-05-02 00:00:00’))/1000; //将设定的日期转换为时间戳 _time1 = getLocalTime( ...
- css/html/Javascript/getUrlCode/各种前端小点汇总集合
js与原生进行数据交互,简单来说就是原生拦截js传到的数据 var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > ...
- .NET 高效开发之不可错过的实用工具(第一的当然是ReSharper插件)
工欲善其事,必先利其器,没有好的工具,怎么能高效的开发出高质量的代码呢?本文为 ASP.NET 开发者介绍一些高效实用的工具,包括 SQL 管理,VS插件,内存管理,诊断工具等,涉及开发过程的各个环节 ...