HDU 2141 (二分法)
来源:互联网 发布:js中使用contextpath 编辑:程序博客网 时间:2024/06/03 10:16
Give you three sequences of numbers A, B, C, then we 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.
3 3 31 2 31 2 31 2 331410
Case 1:NOYESNO
先把a和b数组全部组合存起来,每次询问只需要对于c数组枚举,二分查找a和b数组的组合是否存在需要的数。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <queue>#define mem(p,k) memset(p,k,sizeof(p));#define rep(i,j,k) for(int i=j; i<k; i++)#define pb push_back#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define inf 0x6fffffff#define ll long longusing namespace std;const int mod=1e9+7;struct SD{ int x,y; bool operator <(const struct SD &a)const{ return x<a.x; }}num[1100];int bk[1100];int n,m,k,maxx,ans,cur,sum,x,y;int minn;int nex[4][2]={0,1,1,0,0,-1,-1,0};ll a[510],b[510],c[510];ll mm[300000];int main(){ int l; int cu=1; while(cin>>l>>n>>m){ rep(i,0,l)scanf("%lld",a+i); rep(i,0,n)scanf("%lld",b+i); rep(i,0,m)scanf("%lld",c+i); cin>>k; int le=0; for(int i=0;i<l;i++){ for(int j=0;j<n;j++){ mm[le++]=a[i]+b[j]; } } sort(mm,mm+le); cout<<"Case "<<cu++<<":"<<endl; ll ans; while(k--){ scanf("%lld",&ans); cur=0; for(int i=0;i<m;i++){ int l=0,r=le-1; while(l<=r){ int m=(l+r)>>1; if(mm[m]==ans-c[i]){cur=1;break;} if(mm[m]>ans-c[i])r=m-1; else l=m+1; } if(cur)break; } if(cur)cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0;}//freopen("C:\\Users\\LENOVO\\Desktop\\read.txt","r",stdin);
0 0
- HDU 2141 (二分法)
- hdu 4004 二分法
- HDU-2199 二分法
- hdu 2289 Cup (二分法)
- hdu 2199 二分法!!!
- hdu 2899 二分法+数学!!!
- HDU 1969:Pie【二分法】
- HDU 1597(二分法)
- hdu 2199 java 二分法
- HDU-1969 PIE 二分法
- hdu 2141 Can you find it?(二分法)
- hdu 3586 树形DP+二分法
- HDU 1025 (DP+二分法)
- HDU 2178 猜数字 【二分法】
- hdu 1025 二分法求LIS
- HDU 1677 二分法进行判断
- hdu 1969 二分法分蛋糕
- HDU 2141~ Can you find it? 还是二分法~~
- 电影售票系统(4)
- eclipse安装svn插件
- 汇编笔记大全
- GUI_模拟四则运算案例
- c++函数的高级特性
- HDU 2141 (二分法)
- TF package 介绍
- innodb事务的实现
- RGB与LAB优化互转
- Ubuntu 14.04 LTS 搭建 VPN 服务器
- linux下安装svn客户端
- 使用maven-shade-plugin插件打可执行jar包
- (转)为什么LISP语言如此先进?
- github添加多个账号