/* codevs 2765 很明显的二分 半年不写代码 超丑 怎么能忍, */ #include<cstdio> #include<algorithm> #define maxn 30010 using namespace std; const double Tar=0.6180339887498949; int n,m,a[maxn],x1,x2; double ans; double Min(double x,double y){ return x<y?x:y; } bool J(int x,int y){ double z=double(a[x])/double(a[y]); if(z<Tar){ if(ans>Tar-z){ ans=Tar-z;x1=a[x];x2=a[y]; } return 1; } if(z>Tar){ if(ans>z-Tar){ ans=z-Tar;x1=a[x];x2=a[y]; } return 0; } } int main(){ scanf("%d",&n);ans=66666666; for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); for(int i=1;i<=n;i++){ int l=i,r=n,mi; while(l<=r){ mi=(l+r)/2; if(J(i,mi))r=mi-1; else l=mi+1; } } printf("%d %d ",x1,x2); return 0; }
/* codevs 1312 这题数论吧 懒得想了 直接暴力二分 时间还可以 空间11M 有空再想想别的做法 */ #include<iostream> #define maxn 2000010 using namespace std; long long n,s[maxn]; int main(){ cin>>n; for(long long i=1;i<=n;i++) s[i]=s[i-1]+i; for(long long i=1;i<=n;i++){ long long l=i+1,r=n; while(l<=r){ long long mid=(l+r)/2; long long x=s[mid]-s[i-1]; if(x==n){ cout<<i<<" "<<mid<<endl; break; } else if(x>n)r=mid-1; else if(x<n)l=mid+1; } } return 0; }