讨论12/18

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int main()
{
    int a[100],n,to=0,w,c,h,s;
    cin>>n;
    
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cin>>h;
    s=0;
    w=n-1;
    while(to<=w)
    {
        s++;
        if(to==w)
        {
            c=to;
        }
        else    
        {
            c=(h-a[to])*(w-to)/(a[w]-a[to]);
        }   
        if(c<0||c>n-1)
        {
            break;
        }
        if(a[c]<h)
        {
            to=c+1;
        }
        else if(a[c]>h)
        {
            w=c-1;
        }
        else
        {
            cout<<s<<endl;
            cout<<c;
            break;
        }
    }
    if(to>w)
    {
        cout<<s<<endl;
        cout<<"No";
    }
    return 0;
 } 

1 条评论

  • 1

信息

ID
1028
难度
9
分类
其他 点击显示
标签
递交数
9
已通过
6
通过率
67%
上传者