国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

POJ - 2366 Sacrament of the sum 二分查找

2019-11-10 16:59:56
字體:
來源:轉載
供稿:網友

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.

Input

You 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.

Output

You 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 Input

4 -175 19 19 10424 3 8951 -424 -788

Sample Output

YES

Hint

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed.

兩個數列都有序,而且只有兩個數列,直接枚舉一個二分查找另一個就好。

代碼

#include <stdio.h>int A[50000],B[50000];int main(){ int i,j,n1,n2,mid,max,min; scanf("%d",&n1); for(i=0;i<n1;++i){ scanf("%d",&A[i]); } scanf("%d",&n2); for(i=0;i<n2;++i){ scanf("%d",&B[i]); } for(i=0;i<n1;++i){ for(min=0,max=n2-1,mid=(max+min)/2;min<=max;mid=(max+min)/2){ if(A[i]+B[mid]==10000){ printf("YES"); return 0; }else if(A[i]+B[mid]>10000){ min=mid+1; }else{ max=mid-1; } } } printf("NO"); return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彩票| 长垣县| 中江县| 建水县| 白山市| 浏阳市| 云林县| 邢台县| 台南县| 锦州市| 大方县| 罗平县| 海阳市| 鄂州市| 重庆市| 三门县| 南阳市| 林州市| 潍坊市| 长丰县| 清涧县| 邓州市| 六枝特区| 会同县| 健康| 邵东县| 永德县| 井陉县| 泗洪县| 随州市| 合江县| 华阴市| 新绛县| 大石桥市| 大田县| 平泉县| 鄱阳县| 民乐县| 大宁县| 武隆县| 兴业县|