- 输出“Hello World!"
- 2021-12-18 17:06:40 @
讨论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 条评论
-
吴思褀 LV 6 @ 2022-06-08 17:23:43
xiexie谢谢
- 1