HDOJ2141(map在二分搜索中的应用)
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std ;
#define M 500 + 10
int a[M] ;
int b[M] ;
int c[M] ;
int d[M] ;
int l ;
int n ;
int m ;
map <int , bool > Map ;
void Marge()
{
for(int i = ;i < l ; ++ i)
for(int j = ;j < n ; ++ j)
Map[a[i] + b[j]] = ;
}
bool Check(int x)
{
int tem ;
for(int i = ;i <l ; ++ i)
{
tem = x - c[i] ;
if(Map.count(tem)) return true ;
}
return false ;
}
int main()
{
int s ;
int x ;
int T = ;
while(scanf("%d%d%d",&l ,&n , &m) != EOF )
{
for(int i = ;i < l ; ++ i)
scanf("%d",a + i) ;
for(int i = ;i < n ; ++ i)
scanf("%d",b + i) ;
for(int i = ;i < m ; ++ i)
scanf("%d",c + i) ;
scanf("%d",&s) ;
printf("Case %d:\n",T ++) ;
Marge() ;
while(s --)
{
scanf("%d",&x) ;
if(Check(x)) puts("YES") ;
else puts("NO") ;
}
Map.clear() ;
}
return ;
}
标准二分搜索代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std ;
const int MAX_N=;
int a[MAX_N];
int b[MAX_N];
int c[MAX_N];
int d[MAX_N*MAX_N];
int l, n, m, s;
int main()
{
int t=;
while(scanf("%d %d %d",&l, &n, &m)!=EOF)
{
for(int i=; i<l; i++)
{
scanf("%d",&a[i]);
}
for(int i=; i<n; i++)
{
scanf("%d",&b[i]);
}
for(int i=; i<m; i++)
{
scanf("%d",&c[i]);
}
for(int i=; i<l; i++)
{
for(int j=; j<n; j++)
{
d[i*n+j]=a[i]+b[j];
}
}
sort(d,d+l*n);
scanf("%d",&s);
printf("Case %d:\n",++t);
while(s--)
{
int x;
scanf("%d",&x);
bool flag=false;
for(int i=; i<m; i++)
{
if(binary_search(d,d+l*n,x-c[i]))
{
flag=true;
break;
}
}
if(flag)
{
puts("YES");
}
else
{
puts("NO");
}
}
} return ;
}
HDOJ2141(map在二分搜索中的应用)的更多相关文章
- EL表达式获取Map和List中的值
EL表达式获取Map和List中的值 EL表达式取Map中的值: 当Map中是String,String时 后台servlet中: Map<String, String> map1 = ...
- 如何在WindowsPhone Bing Map控件中显示必应中国中文地图、谷歌中国中文地图。
原文:如何在WindowsPhone Bing Map控件中显示必应中国中文地图.谷歌中国中文地图. 最近正好有点业余时间,所以在做做各种地图.Bing Map控件本身就能显示必应地图,但是很遗憾微软 ...
- Map.containsKey方法——判断Map集合对象中是否包含指定的键名
该方法判断Map集合对象中是否包含指定的键名.如果Map集合中包含指定的键名,则返回true,否则返回false. public static void main(String[] args) { M ...
- 07 zabbix之map拓扑标签中macro应用
zabbix之map拓扑标签中macro应用 请先预习网地图map : 请点击 macro官方文档介绍 : 请点击 1. Map labels(拓扑图标签)主要注意以下Macros(宏): MAC ...
- 信1705-2 软工作业最大重复词查询思路: (1)将文章(一个字符串存储)按空格进行拆分(split)后,存储到一个字符串(单词)数组中。 (2)定义一个Map,key是字符串类型,保存单词;value是数字类型,保存该单词出现的次数。 (3)遍历(1)中得到的字符串数组,对于每一个单词,考察Map的key中是否出现过该单词,如果没出现过,map中增加一个元素,key为该单词,value为1(
通过学习学会了文本的访问,了解一点哈希表用途.经过网上查找做成了下面查询文章重复词的JAVA程序. 1 思 思路: (1)将文章(一个字符串存储)按空格进行拆分(split)后,存储到一个字符串(单词 ...
- mybatis中的map.xml文件中sql语句需要分号吗?
mybatis中的map.xml文件中sql语句需要分号吗? :你是说sql介绍的分号吗?不需要的
- STL源码中map和set中key值不能修改的实现
前言 最近正好刚刚看完,<stl源码剖析>这本书的map和set的源码部分.但是看完之后又突然发现,之前怎么没有注意到map和set容器中key不能修改是怎么实现的.故,特此整理如下. s ...
- Map Resource Definition 中type为 'ArcGIS Server Local'.
在使用 MapResourceManager, Map进行 地图显示 时, 在 Map Resource Definition 的 type 为 ArcGIS Server Local时概述. 1,打 ...
- arcgis api for flex 除去 esri map控件中的logo标志
在程序的applicationComplete方法中添加下列代码 private function reallyHideESRILogo(map : Map) : void { for(var i : ...
随机推荐
- iOS和Android后台机制对比
转自:http://blog.csdn.net/zsch591488385/article/details/27232881 一.iOS的“伪后台”程序 首先,先了解一下ios 中所谓的「后台进程」到 ...
- iOS 导航引发坐标高度问题
iOS7 后导航结构发生变化,有新的控制属性诞生,一下为两个属性引发的控制器视图高度问题 translucent = YES 导航透明 (默认) translucent = NO 导航 ...
- 2017-2018-1 20179209《Linux内核原理与分析》第十周作业
设备与模块 设备分类 块设备 块设备可以以块为单位寻址,块大小随设备不同而不同:设备通常支持重定位操作,也就是对数据的随机访问.块设备的例子有外存,光盘等. 字符设备 字符设备不可寻址,仅供数据的流式 ...
- matlab + c/c++ opencv 混合编程
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...
- 为什么下了android 4.1 的SDK后在本地用浏览器看api说明文档时,浏览器打开api的html文件很慢?试了好几款浏览器都一样。为什么?
http://www.oschina.net/question/436724_61401 http://www.google.com/jsapi 他惹的祸 注释掉就可以了- <!-- < ...
- Android电池驱动【转】
本文转载自:http://blog.sina.com.cn/s/blog_66a6a5ec0100n6ej.html Android的电池的管理分为三个部分:Java部分,JNI部分以及kenel部分 ...
- NLP-最小编辑距离
最小编辑距离 一 概念 编辑距离(Edit Distance),又称Levenshtein距离,是指两个字串之间,由一个转成另一个所需的编辑操作次数.最小编辑距离,是指所需最小的编辑操作次数. 编辑操 ...
- Spark- 常见问题
记录spark使用中常见问题 SparkSQL 日期解析时用到SimpleDateFormat, SimpleDateFormat是线程不安全的.可以使用 FastDateFormat 如: impo ...
- R Customizing graphics
Customizing graphics GraphicsLaTeXLattice (Treillis) plots In this chapter (it tends to be overly co ...
- Python中如何从数据库把数据导入excel中
import pymysql,xlwt #1.连接mysql #2.执行sql语句 #3.获取到sql执行结果 #4.写入excel def conn_mysql(sql): conn = pymys ...