As we all know,the handsome boy, Zcat, has a fever of flat shoes. He sings it on the class, in the dormitory and the way he come back from the machinery room to his dorm.One day , he sing it on the way, just like

  "MY skating shoes are the most fashion one
  At the way back to home I couldn't stop
  rubbing rubbing
  rubbing at such smooth floor
  With the moonlight ,I was able to see my shadow was either very close or far
  I felt that my step was forced by a kind of strength
  With the skating shoes ,I will not afraid anything around the world
  One step two steps,every one was just like zhuaya
  The motion which was like a ghost was rubbing and rubbing
  I beat to beat for myself
  It's the best moment of my life
  I'd got to finish my favorite dancing
  At the terrfic street where moonlight fall
  I told myself that it really wasn't dream
  One step two steps ,every one was just like zhuaya
  The gost step was rubbing and rubbing
  rubbing at such smooth floor
  The motion which was like a ghost was rubbing and rubbing 
  One step two steps,every one was just like zhuaya
  One step two steps,every one was just like zhuaya
⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯“

On he sings this,he sees a pretty girl standing on by the roadside. Zcat wants to see the pretty girl's face. Zcat knows the distance between he and her is n(1≤n≤1000000) meters. Zcat also wants to see the girl's face clearly. So he must move forward exactly n meters.To show the girl his favourite dancing,he has to follow the lyric One step two stepsof flat shoes. When the lyric is one step, he will move exactly 1 meter. When the lyric is two steps, he will move exactly 2 meters. Now, Zcat knows the whole lyric. He wants to know is there a time he can start, then move forward following the lyric, and he will see the pretty girl clearly.

Input

The first line contains a single number n(1≤n≤1000000) denotes the length of the lyric of One step and Two steps.

The second line contains n numbers.Anyone of these is 1 or 2.

The third line contains a single number q(1≤q≤3000000) denotes the time of question.

The next line contains q numbers denote then distance between Zcat and the pretty girl.

Output

To every question, if Zcat can see the girl clearly, print Yes, else print No.

Sample input and output

Sample Input Sample Output
8
2 1 1 1 1 2 2 2
6
1 3 5 7 9 11
Yes
Yes
Yes
Yes
Yes
No

解题报告

令 L = min ( s1 , s2 )

s1 为从左边开始扫,连续2的个数

s2 为从右边开始扫,连续2的个数

那么无法到达的距离为:

Len = 所有数之和 - 1

for(int i = 0 ; i < L; ++ i)
{
arrive[Len-i*2] = false;
}
这样,对于所有询问,就可以在O(1)的时间内做出回答
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = + ;
int A[maxn];
bool arrive[*+]; int main(int argc,char *argv[])
{
int n;
scanf("%d",&n);
int sum = ;
memset(arrive,true,sizeof(arrive));
for(int i = ; i < n ; ++ i)
{
scanf("%d",&A[i]);
sum += A[i];
}
int q;
int host = sum-;
int q1 = , q2 = ;
for(int i = ; i < n ; ++ i)
if (A[i] == )
break;
else
q1++;
for(int i = n- ; i >= ; --i)
if (A[i] == )
break;
else
q2++;
int thisq = min(q1,q2);
for(int i = ; i < thisq; ++ i)
{
arrive[host-i*] = false;
}
scanf("%d",&q);
while(q--)
{
int a;
scanf("%d",&a);
if (a > sum)
{
printf("No\n");
continue;
}
if(!arrive[a])
printf("No\n");
else
printf("Yes\n");
}
return ;
}
 

UESTC_One Step Two Steps CDOJ 1027的更多相关文章

  1. [8.1] Triple Step

    A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a t ...

  2. animation中的steps()逐帧动画

    在我们平时做宽高确定,需要背景图片切换的效果时,我如果用的是一张大的png图片.而且恰好是所有小图都是从左向右排列的,那么 我们只需测量出某一个小图距左侧有多少像素(x),然后我们banckgroun ...

  3. AWS Step Function Serverless Applications

    Installing VS Components To follow along with this article, you must have an AWS account and install ...

  4. Steps 组件的设计与实现

    NutUI 组件源码揭秘 前言 本文的主题是 Steps 组件的设计与实现.Steps 组件是 Steps 步骤和 Timeline 组件结合的组件,在此之前他们是两个不同的组件,在 NutUI 最近 ...

  5. [LeetCode] Climbing Stairs 爬梯子问题

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  6. jquery——移动端滚动条插件iScroll.js

    官网:http://cubiq.org/iscroll-5 demo: 滚动刷新:http://cubiq.org/dropbox/iscroll4/examples/pull-to-refresh/ ...

  7. Model--汇总

    NSFileManager.NSURL.NSFileHandle.NSData.NSXMLParser.NSUserDefaults.NSKeyedArchiver.NSKeyedUnarchiver ...

  8. javascript实现汉诺塔动画效果

    javascript实现汉诺塔动画效果 当初以为不用html5也很简单,踩了javascript单线程的大坑后终于做出来了,没事可以研究下,对理解javascript的执行过程还是很有帮助的,代码很烂 ...

  9. Faster-rnnlm代码分析3 - EvaluateLM(前向计算ForwardPropagate)

    先采用一个简单的输入文本做测试 [root@cq01-forum-rstree01.cq01.baidu.com rnnlm]# pwd /home/users/chenghuige/rsc/app/ ...

随机推荐

  1. 链表的基本操作(Basic Operations on a Linked List)

    链表可以进行如下操作: 创建新链表 增加新元素 遍历链表 打印链表 下面定义了对应以上操作的基本函数. 创建新链表 新链表创建之后里面并没有任何元素,我们要为数据在内存中分配节点,再将节点插入链表.由 ...

  2. Java Fuck Bignumber

    为了熟悉java , 开一套poj大数处理的题来写. ------------------------------------------------------------------- A: (1 ...

  3. Linux内存点滴 用户进程内存空间

    Linux内存点滴 用户进程内存空间 经常使用top命令了解进程信息,其中包括内存方面的信息.命令top帮助文档是这么解释各个字段的. VIRT, Virtual Image (kb) RES, Re ...

  4. TCP和UDP的区别(转)

    TCP协议与UDP协议的区别    首先咱们弄清楚,TCP协议和UCP协议与TCP/IP协议的联系,很多人犯糊涂了,一直都是说TCP/IP协议与UDP协议的区别,我觉得这是没有从本质上弄清楚网络通信! ...

  5. 在eclipse中使用svn

    作为一名程序员,svn是比较常用也必然会使用到的一个工具,它的全拼为Subversion,是一个开源的版本控制系统,可以对每次修改的文件和目录进行准确记录,以便在使用的时候及时提取.本文主要介绍如何在 ...

  6. PC-常见问题-清除浮动

    常用:.clear{clear:both;height:0px;overflow:hidden;}>最优浮动闭合方案(这是我们推荐的): .clearfix:after{content:&quo ...

  7. 应对Deadline,时间怎么安排?

    问题定义 项目过程中,每项任务都是有时间要求的,一般体现为"截止时间".即Deadline. 怎样安排时间,才干在Deadline之前完毕任务呢? 有效实践 错误做法 在Deadl ...

  8. Qt导出Excel的简单实现

    QAxObject对COM对象进行了封装,QAxObject派生自QAxBase,而后者提供了一组API通过IUnknown(不清楚IUnknown的同学可以去看看COM对象模型)指针直接访问COM对 ...

  9. Android 打造自己的个性化应用(五):仿墨迹天气实现续--> 使用Ant实现zip/tar的压缩与解压

    上一篇中提到对于Zip包的解压和压缩需要借助Ant 实现,我经过参考了其他的资料,整理后并加上了一些自己的看法: 这里就具体地讲下如何使用Ant进行解压缩及其原因: java中实际是提供了对  zip ...

  10. JavaScript --------------继前面继承方式-------总结

    创建对象方式: 工厂模式:使用简单的函数创建对象,为对象添加属性和方法,然后返回对象: function createPerson(name,age,job){ var o = new Object( ...