HDU 2141 Can you find it?(二分)

网友投稿 490 2022-11-12

HDU 2141 Can you find it?(二分)

HDU 2141  Can you find it?(二分)

题目链接:​​clicl here~~​​

【题目大意】:

Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X.

Sample Input

3 3 3 1 2 3 1 2 3 1 2 3 3 1 4 10

Sample Output

Case 1: NO YES NO

【解题思路】将前两个数组元素合并为一个,在和最后一个进行选择,二分合并后的数组,如果

if(sort[mid]ans) right=mid-1;    else {flag=true;break;}

代码

#include using namespace std;const int N=505;int A[N],B[N],C[N],D[N*N];bool get(int sort[],int k,int ans)//合并后的数组/数组元素个数/和减去第三个数组元素剩下的值{ bool flag=false; int left=0,right=k,mid; while(left<=right) { mid=(left+right)>>1; if(sort[mid]ans) right=mid-1; else {flag=true;break;} } return flag;}int main(){ //freopen("1.txt","r",stdin); int l,n,z,m,S,tot=1; bool ok; while(scanf("%d%d%d",&l,&n,&m)!=EOF) { for(int i=0;i

​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:[数学]高等数学复习总结
下一篇:你没有变强,是因为你一直很舒服
相关文章

 发表评论

暂时没有评论,来抢沙发吧~