day2 POJ 2366 Sacrament of the sum
来源:互联网 发布:淘宝店铺每日工作流程 编辑:程序博客网 时间:2024/06/10 03:05
#include"stdio.h"#include"iostream"using namespace std;int a[50005],b[50005];int i,n,m,k;int flag=0;void find(int x){ int l,r,mid; l=0; r=n-1; while(l<=r) { mid=(l+r)/2; if(a[mid]==x) {flag=1; return;} else if(a[mid]<x) l=mid+1; else r=mid-1; }}int main(){ scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); scanf("%d",&m); while(m--) { scanf("%d",&k); find(10000-k); } if(flag==1) printf("YES\n"); else printf("NO\n"); return 0;}两个有序序列,枚举一个序列在另一个序列中二分找答案即可,之前写的代码交上去总会WA,参考他人博客后,发现问题在读入过程中进行判断并中断循环会造成WA,一个比较奇怪的点,以后写题目要多注意一下,将结果判断移出循环后就可以AC了
0 0
- 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
- 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(二分查找)
- POJ 2366 (URAL 1021)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
- 易语言特征码定位工具源码
- Mybatis DataSource Connection 相关源码
- 大数相乘
- Java Bean
- Spring总结—— IOC 和 Bean 的总结
- day2 POJ 2366 Sacrament of the sum
- [李景山php]thinkphp核心源码注释|Memcached.class.php
- JVM内存结构
- Docker学习总结(10)——10分钟玩转Docker
- MINIX - 磁盘块和缓冲块
- source insight 添加ns2源码
- ios runtime objc_getAssociatedObject&objc_setAssociatedObject用法
- jquery获取触发事件相关的id
- HDU 1075 What Are You Talking About