Little Sub and Triples
生活随笔
收集整理的這篇文章主要介紹了
Little Sub and Triples
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
http://acm.hznu.edu.cn/OJ/problem.php?cid=1263&pid=1
http://acm.hznu.edu.cn/OJ/problem.php?id=2580
題意:問區(qū)間里有沒有三個(gè)數(shù)能組成三角形的邊長(zhǎng)
題解:
判定一個(gè)區(qū)間能否組成的方法是排序后判斷相鄰的三個(gè)數(shù)字是否能組成,直接暴力會(huì)超時(shí)。
然而,如果一直滿足a[i]+a[i+1]=a[i+2],就變成了斐波那契數(shù)列,而斐波那契數(shù)列的增長(zhǎng)速度不用多少項(xiàng)就會(huì)超過數(shù)字大小的上限,打個(gè)表實(shí)際上是第56項(xiàng)。
于是當(dāng)區(qū)間長(zhǎng)度大于60直接輸出YES,否則暴力判定即可,注意要使用long long。
珍愛頭發(fā)、遠(yuǎn)離endl;
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int using namespace std; typedef long long ll; //typedef __int128 lll; const int N=200000+10; const int M=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,q; int ans,cnt,flag,temp,sum; ll a[N]; ll b[N]; char str; struct node{}; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endifios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%lld",&a[i]);}int l,r;while(m--){scanf("%d%d",&l,&r);if(r-l+1<3){cout<<"NO"<<"\n";continue;}if(r-l+1>60){cout<<"YES"<<"\n";continue;}bool flag=1;for(int i=l;i<=r;i++){b[i]=a[i];}sort(b+l,b+r+1);for(int i=l;i<r-1;i++){if(b[i]+b[i+1]-b[i+2]>0){cout<<"YES"<<"\n";flag=0;break;}}if(flag){cout<<"NO"<<"\n";}}//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }?
總結(jié)
以上是生活随笔為你收集整理的Little Sub and Triples的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Little Sub and Apple
- 下一篇: Little Sub and Seque