hdu 2141 Can you find it?(二分查找)
题目链接: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?(二分查找)的更多相关文章
- C - 啥~ 渣渣也想找玩数字 HDU - 2141(有序序列枚举 + 二分优化查找)
题目描述 可爱的演演又来了,这次他想问渣渣一题... 如果给你三个数列 A[],B[],C[],请问对于给定的数字 X,能否从这三个数列中各选一个,使得A[i]+B[j]+C[k]=X? 输入 多组数 ...
- hdu 4190 Distributing Ballot Boxes(贪心+二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...
- 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 ...
- Holedox Eating HDU - 4302 2012多校C 二分查找+树状数组/线段树优化
题意 一个长度$n<=1e5$的数轴,$m<=1e5$个操作 有两种一些操作 $0$ $x$ 在$x$放一个食物 $1$ 一个虫子去吃最近的食物,如果有两个食物一样近,不转变方向的去吃 ...
- HDU 5265 pog loves szh II (二分查找)
[题目链接]click here~~ [题目大意]在给定 的数组里选两个数取模p的情况下和最大 [解题思路]: 思路见官方题解吧~~ 弱弱献上代码: Problem : 5265 ( pog love ...
- HDU 3280 Equal Sum Partitions(二分查找)
Equal Sum Partitions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2141:Can you find it?(数据结构,二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- 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 ...
- 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 ...
随机推荐
- 用起来超爽的Maven——入门篇
你还在为怎样寻找.导入SSH相关依赖包纠结吗? 你还在为没有安装IDE开发工具不能编译.部署.运行项目而纠结吗? 你还在为公司项目目录结构怎样规范而纠结吗? 亲爱的纠结哥,只要你使用了Maven,一切 ...
- Prolog奇怪奇妙的思考方式
今天在<七周七语言>中接触到了prolog,发现它的编程模式和思考方式的确比较奇怪,但同时也非常奇妙,值得学习一下. 1. prolog语言介绍 和SQL一样,Prolog基于数据 ...
- ardupilot_gazebo仿真(三)
ardupilot_gazebo仿真(三) 标签(空格分隔): 未分类 创建ROS node 实现对无人机的控制(软件在环) MAVROS MAVROS是ROS中的一个能够连接支持MAVLink地面站 ...
- 官方文档 恢复备份指南四 Starting and Interacting with the RMAN Client
本章讲: Starting and Exiting RMAN Specifying the Location of RMAN Output ...
- Week2 Teamework from Z.XML 软件分析与用户需求调查(五)从对比中看见必应助手发展空间
本文将主要探讨软件功能前景(浮动头像界面,升级式角色),找出与bing助手相类似功能的资深软件,分析这些软件的发展趋势和用户体验,从历史的角度来评测bing助手的某些功能的前景. 1.浮动头像界面-曲 ...
- 【Python】python中的__dict__,__getattr__,__setattr__
Python class 通过内置成员__dict__ 存储成员信息(字典) 首先用一个简单的例子看一下__dict__ 的用法 class A(): def __init__(self,ax,bx) ...
- [翻译] ASP.NET Core 简介
ASP.NET Core 简介 原文地址:Introduction to ASP.NET Core 译文地址:asp.net core 简介 翻译:ganqiyin ...
- Vue组件间通信:一个例子学会Vue组件-Vue.js学习总结)(转载)
详情请点击 http://www.jianshu.com/p/9ad1ba89a04b
- scrapy使用记录
1 进入pip安装目录 python -m pip install --upgrade pip pip install Scrapy 2. 创建一个项目 scrapy startproject tes ...
- Param指南
param name标签是在这个播放插件中嵌入的一些功能和播放参数: <param name="playcount" value="1"><! ...