【NOIP】Sequence——暴力
2015-10-20 17:07
369 查看
Problem
题目简述
Fiugou 想要在一个长度为 N 的序列 A 中找到不同位置的三个数,以这三个数为三边长来构成一个三角形。但是它希望在满足条件下,这三个数的位置尽量靠前。
1 x y:将 Ax 改为 y
2:查询最优的合法解,从小到大给出这三个数(而不是位置)。
输入格式
第一行一个整数 N,代表序列的长度。第二行有 N 个整数,代表初始序列。
第三行一个整数 M,代表操作的个数。
接下来 M 行操作,两种操作格式如上所述。
输出格式
共 M 行,每行三个数,从小到大给出。如果不存在,输出-1 -1 -1。样例输入
67 1 3 4 5 1
3
2
1 3 5
2
样例输出
3 5 74 5 7
数据范围
对于10%的数据, N<=10, M<=5对于30%的数据, N<=100, M<=25
对于50%的数据, N<=1000, M<=1000
对于100%的数据, N<=100000, M<=1000
对于100%的数据, 0<=Ai<=10^9, 1<=x<=N, 0<=y<=10^9
Solution
Fibonacci数列是满足前x项不存在三角形的最小情况然而当n=50的时候它也爆int了
所以503枚举
Code
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = (a); i <= (b); i++) #define red(i, a, b) for(int i = (a); i >= (b); i--) #define ll long long inline int read() { int x = 0; char c = getchar(); while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x; } const int N = 110000; int n, m; int a ; bool check(int x, int y, int z) { if (x > y) swap(x, y); if (x > z) swap(x, z); if (y > z) swap(y, z); if (x + y > z) { printf("%d %d %d\n", x, y, z); return 1; }else return 0; } void query() { int x, y, z; rep(i, 3, 46) { x = a[i]; rep(j, 2, i - 1) { y = a[j]; rep(k, 1, j - 1) { z = a[k]; if (check(x, y ,z)) return; } } } printf("-1 -1 -1\n"); } int main() { freopen("sequence.in", "r", stdin); freopen("sequence.out", "w", stdout); scanf("%d", &n); rep(i, 1, n) a[i] = read(); scanf("%d", &m); rep(i, 1, m) { int x = read(); if (x == 1) { int pos = read(), num = read(); a[pos] = num; }else query(); } return 0; }
End.
相关文章推荐
- iOS -iOS9中提示框(UIAlertController)的常见使用
- RequireJS入门(三)
- QSqlQuery QSqlQueryModel QSqlTableModel的区别
- ios UITextView bug 输入文字跳动bug问题 (・ˍ・*)
- UIAlertController的使用
- Caffe: Data layer prefetch queue empty
- 最长递增子序列(longest increasing subsequence)
- JAVA Eight Queens
- Android UI-去除SpannableString下划线
- WARN TaskSchedulerImpl: Initial job has not accepted any resources; check your cluster uito ensure
- mysql 如何设置自动增长序列 sequence(一)
- 关于Xilium.CefGlue(CEF3) 加载mp4格式失败
- NDK错误 org.gradle.process.internal.ExecException: Process 'command with non-zero exit value 2
- leetcode Permutation Sequence
- 详细整理:UITableView优化技巧
- wcf 远程服务器返回了意外响应: (413) Request Entity Too Large。
- NSURLRequest POST方式请求
- 获取<meta-data>元素的value属性的值
- StringBuilder和StringBuffer区别
- easyui datagrid 诡异的无法显示问题