题目链接: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. I/O Handler的管理(3)

    另外连接地址:http://blogs.readthedocs.org/zh_CN/latest/Handler_mgr.html 本章目录 I/O Handler的管理 IO句柄与Select_Re ...

  2. Qt 绘制汽车仪表 指针旋转锯齿问题

    在前面几篇中出现的问题 http://blog.csdn.net/z609932088/article/details/53946245 这个是在QWidget下绘制的,出现了指针有锯齿的问题 后面开 ...

  3. VMware快照

    越来越多的人喜欢使用虚拟机来做实验,但是实验过程并不总是顺利的,所以我们就需要掌握虚拟机快照的使用方法,个人建议的顺序为: 1 在虚拟机打开之前,点击“虚拟机”--"快照"--&q ...

  4. spring多个定时任务quartz配置

    spring多个定时任务quartz配置 <?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.spring ...

  5. eclipse 创建Makefile工程生成多个执行文件

    1.创建Makefile工程 2.创建inc src Debug 目录 用于存放头文件源文件 3.编写Makefile 需要在有源文件的目标天剑Makefile文件,如下给出一个生成两个target的 ...

  6. POJ 2082 Terrible Sets(栈)

    Description Let N be the set of all natural numbers {0 , 1 , 2 , . . . }, and R be the set of all re ...

  7. DP入门(4)——线性结构上的动态规划

    一.最长上升子序列(LIS) 给定n个整数A1,A2,…,An,按从左到右的顺序选出尽量多的整数,组成一个上升子序列(子序列可以理解为:删除0个或多个数,其他数的顺序不变).例如序列1,6,2,3,7 ...

  8. 【EasyNetQ】- 使用SSL连接

    EasyNetQ可以通过SSL连接.戈登·库尔特(Gordon Coulter)撰写的这本指南最初是针对一个提出的问题而写的. 首先,您必须仔细按照https://www.rabbitmq.com/s ...

  9. js+jquery 常用选择器函数

    一.获取当前标签 JS: this,如下: <button onclick="fun(this)"></button> Jquery,如下: $(" ...

  10. Github & DMCA Takedown Policy

    Github & DMCA Takedown Policy Digital Millennium Copyright Act 数字千年版权法案 https://help.github.com/ ...