POJ 2366 (URAL 1021)Sacrament of the Sum
来源:互联网 发布:货源采集软件 编辑:程序博客网 时间:2024/06/09 20:45
题目链接:http://poj.org/problem?id=2366
#include<cstdio>#include<cstring>const int maxn=1e6+10;int a[maxn];int b[maxn];int m,n,x;int main(){memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));scanf("%d", &n);for(int i=1; i<=n; i++){scanf("%d", &x);if(x>=0) a[x]=1;else b[-x]=1;}scanf("%d", &m);int flag=0;while(m--){scanf("%d", &x);x=10000-x;if(x>=0 && a[x]) flag=1;if(x<0 && b[-x]) flag=1;if(flag==1) break;}if(flag==1)printf("YES\n");else printf("NO\n");return 0;}
题意:有两组数,一组有n个数,一组有m个数,从两组数中各找出一个数,使得两者之和为10000,若存在输出YES,若不存在,输出NO。
思路:一开始用二分法做,不知道为啥一直RE了,然后经队友提醒,把出现过的数字标记为1,没有出现过的数字标记为0就可以看,简直被自己蠢哭。要注意的一点就是数组 arr[i],其中的i不存在负数,所以当输入的数字为负数时,记得写成arr[-i].水水的题,代码如下:
0 0
- POJ 2366 (URAL 1021)Sacrament of the Sum
- poj 2366 Sacrament of the sum
- POJ - 2366 Sacrament of the sum
- poj 2366 Sacrament of the sum
- POJ 2366 Sacrament of the sum
- POJ 2366 Sacrament of the sum
- POJ 2366 Sacrament of the sum
- day2 POJ 2366 Sacrament of the sum
- poj 2366 Sacrament of the sum
- poj 2366 Sacrament of the sum
- POJ 2366 Sacrament of the sum(二分查找)
- acm解题报告 POJ 2366 Sacrament of the sum
- POJ - 2366 Sacrament of the sum 二分查找
- Sacrament of the sum
- 1021. Sacrament of the Sum
- C - Sacrament of the sum
- poj 2366 Sacrament of the sum 尺取法的灵活运用
- 【二分查找】[POJ2366]Sacrament of the sum
- GFlags 使用详解
- 基于索引和位图构建的高性能数据报匹配结构
- 去哪儿笔试题——排序数组循环移位后查找
- [leetcode]Sort List
- 输入4个整数,找出其中最大的数,用函数嵌套调用来处理
- POJ 2366 (URAL 1021)Sacrament of the Sum
- 关于 python ImportError: No module named 的问题
- Jq之sliderBar
- BC 34# 1001 Go to movies
- adb shell command -- dumpsys, am, start , stop, screenrecord, logcat ...
- c++primer练习10.14
- UVa 12504 Updating a Dictioinary
- 设计模式问答(一)
- java 图