题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141

题目大意:查找是否又满足条件的x值。

这里简单介绍一个小算法,二分查找。

 /*

  x^2+6*x-7==y
输入y 求x 精确度为10^-5
0=<x<=10000 */
#include <iostream>
#include <cstdio>
using namespace std;
int main (void)
{
double y;
while(cin>>y)
{
double l,r,x;
l=;
r=;//在所给的区间定义边界,一左一右
while(r-l>0.00001)//精确度的问题
{
x=(l+r)/;//二分来节省计算的次数和时间
double yy;
yy=x*x+*x-;
if(yy<y)
l=x+0.00001;//选取右半部分区间
else
r=x;
}
cout<<l<<endl;
}
return ;
}

以下是对hdu2141的解法;

先把原式化为Ai+Bj = X-Ck.然后在对Ai+Bj 进行二分。

 #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; __int64 s[]; int main ()
{
int l,n,m,T=;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
int num=;
__int64 a[],b[],c[];
for (int i=; i<l; i++)
scanf("%I64d",&a[i]);
for (int j=; j<n; j++)
scanf("%I64d",&b[j]);
for (int k=; k<m; k++)
scanf("%I64d",&c[k]);
int t;
scanf("%d",&t);
printf("Case %d:\n", T++);
for (int i=; i<l; i++)
for (int j=; j<n; j++)
s[num++]=a[i]+b[j];
sort(s,s+num);
//sort(a,a+l);
//sort(b,b+n);
sort(c,c+m);
while (t--)
{
__int64 x;
scanf("%I64d",&x);
if(x>s[num-]+c[m-]||x<s[]+c[])
{
printf("NO\n");
continue;
}
int flag=;
__int64 p;
for (int k=; k<m; k++)
{
p=x-c[k];
int cc;
int lz=,r=num-;//cout<<r<<endl;
while(r>lz)
{
cc=(r+lz)/;
if (s[cc]<p)
lz=cc+;
else if(s[cc]==p)
{
flag=;
printf ("YES\n");
break;
}
else
r=cc-;
}
if(flag==)
break;//cout<<k<<endl;
if (p==s[r])
{ flag=;
printf("YES\n");
break;
} }
if(flag==)
printf ("NO\n"); }
}
}

hdu 2141 Can you find it?(二分查找)的更多相关文章

  1. C - 啥~ 渣渣也想找玩数字 HDU - 2141(有序序列枚举 + 二分优化查找)

    题目描述 可爱的演演又来了,这次他想问渣渣一题... 如果给你三个数列 A[],B[],C[],请问对于给定的数字 X,能否从这三个数列中各选一个,使得A[i]+B[j]+C[k]=X? 输入 多组数 ...

  2. hdu 4190 Distributing Ballot Boxes(贪心+二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...

  3. HDU 2141 Can you find it? [二分]

    Can you find it? Give you three sequences of numbers A, B, C, then we give you a number X. Now you n ...

  4. Holedox Eating HDU - 4302 2012多校C 二分查找+树状数组/线段树优化

    题意 一个长度$n<=1e5$的数轴,$m<=1e5$个操作 有两种一些操作 $0$  $x$ 在$x$放一个食物 $1$ 一个虫子去吃最近的食物,如果有两个食物一样近,不转变方向的去吃 ...

  5. HDU 5265 pog loves szh II (二分查找)

    [题目链接]click here~~ [题目大意]在给定 的数组里选两个数取模p的情况下和最大 [解题思路]: 思路见官方题解吧~~ 弱弱献上代码: Problem : 5265 ( pog love ...

  6. HDU 3280 Equal Sum Partitions(二分查找)

    Equal Sum Partitions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. hdu 2141:Can you find it?(数据结构,二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  8. hdu 2141 Can you find it?(二分查找变例)

    Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...

  9. Can you find it? HDU - 2141 (二分查找)

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

随机推荐

  1. Django笔记 —— 高级视图和URL配置

    最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...

  2. Hadoop入门案列,初学者Coder

    1.WordCount Job类: package com.simope.mr.wcFor; import org.apache.hadoop.conf.Configuration; import o ...

  3. Accept 惊群现象测试perl脚本

    $uname -a Linux debian-11-34 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) x86_64 G ...

  4. %matplotlib inline

    整理摘自 https://zhidao.baidu.com/question/1387744870700677180.html %matplotlib inline是jupyter notebook里 ...

  5. octomap建立

    1.安装ros的octomap  ---已完成 2.阅读相关论文,了解其机理,并编写程序实现. 参考网页:https://www.cnblogs.com/gaoxiang12/p/5041142.ht ...

  6. EM算法浅析(二)-算法初探

    EM算法浅析,我准备写一个系列的文章: EM算法浅析(一)-问题引出 EM算法浅析(二)-算法初探 一.EM算法简介 在EM算法之一--问题引出中我们介绍了硬币的问题,给出了模型的目标函数,提到了这种 ...

  7. JQuery Ajax执行过程AOP拦截

    JQuery Ajax过程AOP:用于在Ajax请求发送过程中执行必备操作,比如加载数据访问令牌. $.ajaxSetup({ type: "POST", error: funct ...

  8. MongoDB复制二:复制集的管理

    1.修改oplog的大小  需要在每个机器上都配置.先在secondary上操作,最后在primary上操作. 1)以单机的方式重启复制集的实例 db.shutdownServer() 在新的端口中启 ...

  9. yii视频地址哦

    https://www.yiichina.com/video  

  10. ArcGis融合小多边形到相邻多边形

     在有的时候,我们的数据中可能会有许多细小的图斑,这些并不是我们想要的,需要将它们合并到周围的图斑中,如果一个一个手动合并,那工作量之大简直不敢想象.现在借助ArcGIS的Eliminate工具可 ...