hdoj 2141 Can you find it?【二分查找+暴力】
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 17036 Accepted Submission(s):
4337
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.
followed: In the first line there are three integers L, N, M, in the second line
there are L integers represent the sequence A, in the third line there are N
integers represent the sequences B, in the forth line there are M integers
represent the sequence C. In the fifth line there is an integer S represents
there are S integers X to be calculated. 1<=L, N, M<=500,
1<=S<=1000. all the integers are 32-integers.
number as the form "Case d:", then for the S queries, you calculate if the
formula can be satisfied or not. If satisfied, you print "YES", otherwise print
"NO".
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define MAX 1100
bool cmp(int a,int b)
{
return a<b;
}
int a[MAX];
int b[MAX];
int c[MAX];
int d,str[300000];
int main()
{
int n,m,j,i;
int k=1,l;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(i=0;i<l;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<m;i++)
scanf("%d",&c[i]);
int len=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
str[len++]=b[i]+c[j];
}
}
sort(str,str+len,cmp);
int ok;
printf("Case %d:\n",k++);
int s;
scanf("%d",&s);
for(i=0;i<s;i++)
{
scanf("%d",&d);
ok=0;
for(j=0;j<l;j++)
{
int left = 0,right = len,mid = 0;
int goal = d - a[j];
while(right >= left)
{
mid = (right + left) >> 1;
if(str[mid] < goal)
left = mid + 1;
else if(str[mid] > goal)
right = mid - 1;
else
{
ok=1;
break;
}
}
if(ok)
break;
}
if(ok)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
hdoj 2141 Can you find it?【二分查找+暴力】的更多相关文章
- 二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix
题目传送门 /* 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 */ #include <cstdio> #include < ...
- what the fuck!(二分查找 / 暴力模拟)
what the fuck! Description 现在有一家公司有nnn个员工(nnn为奇数),他们的工资发放是基本工资+提成,现在这家公司计划再招一批人.要写一篇招聘启事,但是对于这个招聘启事中 ...
- 二分查找 HDOJ 2141 Can you find it?
题目传送门 /* 题意:给出一个数,问是否有ai + bj + ck == x 二分查找:首先计算sum[l] = a[i] + b[j],对于q,枚举ck,查找是否有sum + ck == x */ ...
- hdu 2141 Can you find it?(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...
- 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 ...
- 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?【二分查找是否存在ai+bj+ck=x】
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...
- 二分查找+数学 HDOJ 4342 History repeat itself
题目传送门 题意:计算从1开始到第n个非完全平方数的开方和 分析:设第n个非完全平方数的值为a,x * x < a < (x+1) * (x+1),而且易得(tmp = sqrt (a) ...
随机推荐
- GCD的一点理解
大家都知道GCD 有两种队列:一种是串行队列,一种是并发队列.什么是串行队列?串行队列就是队列中的代码块一个一个按顺序执行,每当上一个代码块执行结束后下一个代码块才会执行.打个比方,如果队列是一些首尾 ...
- JS 同源策略
对于任何基于WEB的应用,最重要的就是安全性.JS中有各种安全检查以防止恶意脚本攻击你的机器,其中一些特定的安全手段在各种浏览器中都有采用.如:Mozilla有个完全独特的完全模型,涉及到了签署脚本和 ...
- 【转载】介绍“Razor”— ASP.NET的一个新视图引擎
最近在做一个项目,用的MVC razor 视图,因为之前没用这个视图做过,于是查阅文档资料,共享一下. https://msdn.microsoft.com/zh-cn/ff849693 内容主要是讲 ...
- python模块学习 logging
1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...
- JQuery.imgAreaSelect 参数说明
imgAreaSelect 参数说明: 参数 描述 aspectRatio 设定选取区域的显示比率,如:”4:3“ autoHide 如果设置为true,当选择区域选择结束时消失,默认值为:false ...
- 关于微软RDLC报表打印时文字拉伸问题(Windows server 2003 sp2)
最近我们开发的打印服务频频出现打印文字拉伸问题,客户意见络绎不绝,最为明显的是使用黑体加粗后 “2.0份” 打印出来后小数点几乎看不见了,用户很容易误认为 “ 20份” .所以问题达到了不得不停下手上 ...
- 简单学C——第六天
指针 指针是c语言中很灵活的一个内容,当然,灵活的都是较难掌握的.不过,只要理解其实质,学习,运用指针还是一件很轻松的事情的. 首先理解,1.什么是指针? 在c语言中,指针也同Int ,doub ...
- PHPStorm——配置修改
字体修改: FiraCode字体:https://github.com/tonsky/FiraCode 1.双击安装字体 2. 关闭错别字检测
- win7 进程kill
文章出处:http://www.cnblogs.com/winstic/,请保留此连接 在使用windows操作时,经常会遇到一些顽固进程大占CPU,很是苦恼:今天就遇到这样的问题,刚写的一个一个分布 ...
- 40个Android问题
1. Android的四大组件是哪些,它们的作用? 答:Activity:Activity是Android程序与用户交互的窗口,是Android构造块中最基本的一种,它需要为保持各界面的状态,做很多持 ...