poj_2366_标准二分
来源:互联网 发布:js中创建数组 编辑:程序博客网 时间:2024/06/06 10:46
Sacrament of the sum— The Brother of mine, the Head of Monastic Order wants to know tomorrow about the results long-term researches. He wants to see neither more nor less than the Summering Machine! Even moreover, he wants our Machine — only a machine — to demonstrate its comprehension of the Sacrament of the Sum as deeply as it is possible. He wants our Machine to find two numbers that give the sum equal to the Sacred Number 10 000. — Tsh-sh-sh! This is madness that borders on blasphemy! How can the Machine calculate the Sacred Number? Twenty seven years we work on it, but we've could teach it to tell if the sum of two introduced numbers greater or lower than 10 000. Can an ordinary mortal find two numbers that there sum will be equal to 10 000? — But we'll have to do it with the help of our Machine, even if it is not capable. Otherwise we'll have... let's say, big problems, if it is possible to call boiling oil like this. However, I have an idea. Do you remember, last week we've entered two numbers -7 and 13 into the Machine, and it answered that their sum is lower than 10 000. I don't know how to check this, but nothing's left for us than to believe to the fruit of our work. Let's enter now a greater number than -7 and start up the Machine again. We'll do like this again and again until we find a number that being added to 13 will give us 10 000. The only thing we are to do is to prepare an ascending list of numbers. — I don't believe in this... Let's start with the sum that is obviously greater than the Sacred Number and we'll decrease one of the summand. So we have more chances to avoid boilin... big problems. Haven't come to an agreement, the Brothers went away to their cells. By next day everyone of them has prepared a list of numbers that, to his opinion, could save them... Can both of the lists save them together? Your program should decide, if it is possible to choose from two lists of integers such two numbers that their sum would be equal to 10 000.InputYou are given both of these lists one by one. Format of each of these lists is as follows: in the first line of the list the quantity of numbers Ni of the i-th list is written. Further there is an i-th list of numbers each number in its line (Ni lines).The following conditions are satisfied: 1 <= Ni <= 50 000, each element of the lists lays in the range from -32768 to 32767. The first list is ascending and the second one is descending.OutputYou should write "YES" to the standard output if it is possible to choose from the two lists of integers such two numbers that their sum would be equal to 10 000. Otherwise you should write "NO".Sample Input4-17519191042438951-424-788Sample OutputYESHintThis problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed. SourceUral State University Internal Contest October'2000 Junior Session
题意: 给你两组数让你判断是个否有 在两组分别取一个数相加为10000解: 直接而二分
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int num1[50005],num2[50005];int main(){ int n,m,i,j; while(cin>>n) { for(i=0;i<n;i++) scanf("%d",num1+i); cin>>m; for(i=0;i<m;i++) scanf("%d",num2+i); sort(num1,num1+n); int f=0; for(i=0;i<m;i++) { int x=10000-num2[i]; int low=0, high=n-1; while(low<=high) { int mid=(low+high)/2; if(num1[mid]>x) high=mid-1; else if(num1[mid]<x) low=mid+1; else { puts("YES"); f=1; break; } } if(f) break; } if(!f) puts("NO"); } return 0;}
阅读全文
0 0
- poj_2366_标准二分
- 标准二分查找代码
- HDU1528二分匹配标准代码~
- hdu2255二分最优匹配KM标准模板
- 标准库中二分查找算法
- 二分查找的实现和使用标准库函数实现二分查找
- 标准
- 标准
- 标准
- 标准
- 标准
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分。
- 二分
- 记录2017/9/7CVTE嵌入式软件笔试编程题
- freeCodeCamp-->js-->json嵌套数组
- first blood
- (Android网络3)okhttp
- java 判断方法调用是否超时 设置方法调用的超时时间
- poj_2366_标准二分
- eclipse常用快捷键
- oracle数据库调整字段顺序
- 阿里云迁移或者欠费重启后访问失败
- hive2.1.1安装部署
- selenium判断登录时候成功--例子
- 完美解决The 'ResourceManagerPackage' package did not load correctly
- php遇到的问题记录
- word文档上粘贴源代码