upper_bound和lower_bound用法(STL)
2018-01-22 22:31
465 查看
ABCDEF - ABCDEF
#binary-searchYou are given a set S of integers between -30000 and 30000 (inclusive).
Find the total number of sextuples
that satisfy:
Input
The first line contains integer N (1 ≤ N ≤ 100), the size of a set S.Elements of S are given in the next N lines, one integer per line. Given numbers will be distinct.
Output
Output the total number of plausible sextuples.
Examples
Input: 1 1 Output: 1 | Input: 2 2 3 Output: 4 | Input: 2 -1 1 Output: 24 | Input: 3 5 7 10 Output: 10 |
#include <iostream> #include <vector> #include <algorithm> #include <sstream> #include <cstring> #include <cmath> using namespace std; #define MAX_N 101 int n,x[MAX_N],lo,hi; long long res=0LL; vector<int>s1,s2; int main() { scanf("%d",&n); for (int i=0;i<n;i++) { scanf("%d",&x[i]); } for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { for (int k=0;k<n;k++) { s1.push_back(x[i]*x[j]+x[k]); } } } for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { for (int k=0;k<n;k++) { if (x[k]==0) continue; s2.push_back((x[i]+x[j])*x[k]); } } } sort(s1.begin(),s1.end()); sort(s2.begin(),s2.end()); for (int i=0;i<s1.size();i++) { lo=lower_bound(s2.begin(),s2.end(),s1[i])-s2.begin(); hi=upper_bound(s2.begin(),s2.end(),s1[i])-s2.begin(); res+=(hi-lo); } printf("%lld\n",res); return 0; }
相关文章推荐
- STL中查找方法用法总结-adjacent_find, binary_search, includes, lower_bound, upper_bound, equal_range
- C/C++-STL中lower_bound与upper_bound的用法以及cmp函数
- STL: lower_bound, upper_bound用法(C++)
- STL里边二分的lower_bound函数与upper_bound函数的最常见的用法
- STL 二分查找 upper_bound和lower_bound用法
- STL_lower_bound&upper_bound用法
- /*****************c++ STL 里的upper_bound 和 lower_bound 的用法~~*********************/
- C/C++-STL中lower_bound与upper_bound的用法
- C++ STL 之 lower_bound and upper_bound
- STL源码学习----lower_bound和upper_bound算法
- upper_bound和lower_bound的用法
- STL————-lower_bound和upper_bound算法
- STL源码学习----lower_bound和upper_bound算法
- lower_bound 与 upper_bound 返回值及用法
- C++ STL 之 lower_bound and upper_bound
- C++ STL lower_bound upper_bound的用法以及cmp函数
- STL之lower_bound()、upper_bound()、binary_search
- STL之lower_bound和upper_bound
- STL源码学习----lower_bound和upper_bound算法
- Lower_bound与Upper_bound (STL)