数据加载中……

URAL 1021 Sacrament of the sum

水题,由于给出的已经是单调的序列,所以有o(N)的算法
 1 #include<iostream>
 2 using namespace std;
 3 const int MAXN=50005;
 4 
 5 
 6 int main()
 7 {
 8   freopen("data.in","r",stdin);
 9   freopen("data.out","w",stdout);
10   int c,cc,num[MAXN];
11   cin >> c;
12   for (int i=0;i<c;++i) cin >> num[i];
13   num[c]=31440461;
14   cin >> cc;
15   int p=0;
16   for (int i=0;i<cc;++i)
17     {
18       int x;
19       cin >> x;
20       while (x+num[p]<10000++p;
21       if (x+num[p]==10000) { cout << "YES\n"return 0; }
22     }
23   cout << "NO\n";
24   return 0;
25 }
26 


posted on 2009-07-21 17:12 Chen Jiecao 阅读(363) 评论(0)  编辑 收藏 引用 所属分类: URAL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理