题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=2141

题目大意:

给ABC三个数组,给一个X,求是否存在Ai+Bj+Ck = X

思路:

等式转化成Ai+Bj = X-Ck

这样预处理出Ai+Bj的所有数字,然后循环k,二分查找X-Ck是否存在。

首先用set超内存,然后用数组结果一直WA,二分的时候少了个”=“

这真是醉了。

果然深夜不适合刷题

 #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
using namespace std;
typedef pair<int, int> Pair;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int T, n, m1, m2, m3, cases;
ll a[], b[], c[];
ll cnt[];
int tot;
bool Find(ll x)
{
int l = , r = tot-;
while(l <= r)
{
int mid = (l + r) / ;
if(cnt[mid] == x)return true;
else if(cnt[mid] < x)l = mid + ;
else r = mid - ;
}
return false;
}
int main()
{
while(scanf("%d%d%d", &m1, &m2, &m3) != EOF)
{
memset(cnt, , sizeof(cnt));
tot = ;
for(int i = ; i < m1; i++)cin >> a[i];
for(int i = ; i < m2; i++)cin >> b[i];
for(int i = ; i < m3; i++)cin >> c[i];
for(int i = ; i < m1; i++)
for(int j = ; j < m2; j++)cnt[tot++] = (a[i] + b[j]);
sort(cnt, cnt + tot);
sort(c, c + m3);
scanf("%d", &n);
printf("Case %d:\n", ++cases);
while(n--)
{
ll x;
cin >> x;
bool flag = ;
for(int i = ; i < m3; i++)
{
if(Find(x - c[i]))
{
flag = ;
break;
}
}
if(flag){printf("YES\n");continue;}
printf("NO\n");
}
}
}

最新文章

  1. [c++] constexpr and literal class
  2. mysql--sqlalchemy.exc.IntegrityError: (IntegrityError) (1215, &#39;Cannot add foreign key constraint&#39;
  3. nginx应用总结(1)--基础认识和应用配置
  4. ecshop换用redis做缓存
  5. 面向对象编程(七)——Static关键字
  6. sdut 2609 A-Number and B-Number
  7. 统计nginx日志里流量
  8. [置顶] 2014年八大最热门IT技能
  9. IO流(随机流,数组内存流
  10. C++ 中获取 可变形參函数中的參数
  11. JS函数参数
  12. OS模块的常用内置方法
  13. oracle权限列表
  14. 51 NOd 1459 迷宫游戏 (最短路径)
  15. zabbix链接规则
  16. [CF1082E] Increasing Frequency
  17. linux内核空间和用户空间详解
  18. Mac和iOS开发资源汇总—更新于2013-10-14
  19. Linux内核触摸屏驱动--多点触摸 【转】
  20. Python开发【模块】:Requests(一)

热门文章

  1. 学习JAVA的几大优处
  2. sh, 批量执行Linux命令
  3. Zabbix常用key和自定义key的讲解
  4. Lucene教程 -------(一、初始Lucene)
  5. jquery datatable ajax配置详解
  6. selenium2自动化测试学习笔记(三)
  7. node 基础精简
  8. 转发—Android开发常用的插件及工具
  9. Vim编辑器的注释,解注,删除与恢复
  10. Java基础学习笔记十八 异常处理