题目链接: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. 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 ...

  2. POJ 3076 / ZOJ 3122 Sudoku(DLX)

    Description A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells ...

  3. POJ 3177 Redundant Paths & POJ 3352 Road Construction(双连通分量)

    Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numb ...

  4. 第18讲——string类

    关键字:string类  字符串  C-风格字符串  C库字符串函数 字符串:存储在内存的连续字节中的一系列字符. C++处理字符串的方式有两种: 来自C语言,常被称为C-风格字符串: 基于strin ...

  5. rcnn spp_net

    在http://www.cnblogs.com/jianyingzhou/p/4086578.html中 提到 rcnn开创性工作,但是计算时间太长,重复计算太大. spp_net将重复计算避免了 我 ...

  6. c#和html方法互调

    具体见连接:https://www.cnblogs.com/zeroLove/p/3912460.html

  7. servletContext的定义

  8. BZOJ4584 APIO2016赛艇(动态规划+组合数学)

    如果值域不大,容易想到设f[i][j]为第i个学校选了j的方案数,枚举上一个学校是哪个选了啥即可,可以前缀和优化.于是考虑离散化,由于离散化后相同的数可能可以取不同的值,所以枚举第一个和其所选数(离散 ...

  9. POJ——2449 Remmarguts' Date

    Description "Good man never makes girls wait or breaks an appointment!" said the mandarin ...

  10. [洛谷P3743]kotori的设备

    题目大意:ことり有$n$个设备,每个设备每秒共减少$a_i$能量(也就是说每一瞬间都在减少,而不是在一个时刻突然减少),开始前有$b_i$能量,ことり还有一个充电宝,无限能量,每秒共可以提供$p$的能 ...