hdu 2141 (二分)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141
Can you find it?
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 11503 Accepted Submission(s): 3021
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm> using namespace std; long long sum[];
int str1[],str2[],str3[]; int Table(int l,int n,int m)
{ int cas=;
for(int i=; i<l ;i++)
{ for(int j=; j<n; j++)
{ sum[cas++]=str1[i]+str2[j];
}
}
return cas;
} bool BSearch(long long sum[],int k,int cas)
{ int left=,right=cas-;
while(left<=right)
{ int mid=(left+right)>>;
if(sum[mid] == k) return true;
else if(k < sum[mid]) right=mid-;
else left = mid+;
}
return false;
} int main()
{ int l,m,n,i,j;
int ss=;
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{ memset(str1,,sizeof(str1));
memset(str2,,sizeof(str2));
memset(str3,,sizeof(str3)); for(i=; i<l; i++)
scanf("%d",&str1[i]);
for(j=; j<n; j++)
scanf("%d",&str2[j]);
for(i=; i<m; i++)
scanf("%d",&str3[i]);
int k,tmp;
scanf("%d",&k);
int cas=Table(l,n,m);
sort(sum,sum+cas);
printf("Case %d:\n",ss++);
while(k--)
{
scanf("%d",&tmp);
for(i=; i<m; i++)
{ if(BSearch(sum,tmp-str3[i],cas))
{ printf("YES\n");
break;
}
}
if(i>=m)printf("NO\n");
} }
return ;
}
hdu 2141 (二分)的更多相关文章
- Can you find it?(hdu 2141 二分查找)
Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others ...
- hdu 4024 二分
转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html 一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...
- 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? (二分)
题目链接: Can you find it? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/ ...
- 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 ...
- 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 ...
- 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?【二分查找是否存在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 ...
随机推荐
- android 学习随笔七(网络:图片及文本传输及线程关系 )
主线程.子线程.UI的关系 简单的HTTP请求 -------------------------------------------------------- public class MainAc ...
- semantic-ui and IE only message
<![if !IE]> <div class="ui message red"> <i class="close icon"> ...
- 在Linux中打印函数调用堆栈【原创】
本人学习笔记,代码参考如下网址 参考http://www.cnblogs.com/dma1982/archive/2012/02/08/2342215.html zhangbh@prolin-srv: ...
- win8以上系统,设置英文为默认输入法
说明:这里将添加“简体中文(美式键盘)”,也就是英文输入法,并设置为默认输入法. 1.打开控制面板—时钟.语言和区域—语言,点击“添加语言”,选择“英语”—打开,选择“英语(美国)” —添加. 2.选 ...
- jQuery_Ajax_Json 异步接收PHP端传来的json数据
[json]{"user_id":"1172940","rmb_point":"0","weixin_id&q ...
- shell脚本中变量$$、$0等的含义
$0 这个程式的执行名字$n 这个程式的第n个参数值,n=1..9$* 这个程式的所有参数,此选项参数可超过9个.$# 这个程式的参数个数$$ 这个程式的PID(脚本运行的当前进程ID号)$! 执行上 ...
- java double类型保留两位小数4种方法【转】
4种方法,都是四舍五入,例: import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberF ...
- NotificationObject.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...
- 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏
May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...
- 越狱后如何添加cydia源及cydia源大全
http://jingyan.baidu.com/article/6c67b1d6cc53fe2787bb1e06.html 软件游戏能PJ,插件其实也一样,所以有些源里面就包含了大量的PJ插件~ a ...