UESTC_One Step Two Steps CDOJ 1027

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 = 1000000 + 50;
int A[maxn];
bool arrive[1000000*2+500];

int main(int argc,char *argv[])
{
  int n;
  scanf("%d",&n);
  int sum = 0;
  memset(arrive,true,sizeof(arrive));
  for(int i = 0 ; i < n ; ++ i)
   {
         scanf("%d",&A[i]);
         sum += A[i];
   }
  int q;
  int host = sum-1;
  int q1 = 0, q2 = 0;
  for(int i = 0 ; i < n ; ++ i)
   if (A[i] == 1)
    break;
   else
    q1++;
  for(int i = n-1 ; i >= 0 ; --i)
   if (A[i] == 1)
    break;
   else
    q2++;
  int thisq = min(q1,q2);
  for(int i = 0 ; i < thisq; ++ i)
   {
         arrive[host-i*2] = 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 0;
}
 
时间: 2024-10-11 17:19:45

UESTC_One Step Two Steps CDOJ 1027的相关文章

[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 time. Implement a method to count how many possible ways the child can run up the stairs. public static int getPossibleWays(final int n) { int[] memo =

python_装饰器_语法糖

什么是高阶函数? -- 把函数名当做参数传给另外一个函数,在另外一个函数中通过参数调用执行 #!/usr/bin/python3 __author__ = 'beimenchuixue' __blog__ = 'http://www.cnblogs.com/2bjiujiu/' def func_x(x): return x * 2 def func_y(y): return y * 3 def func_z(x, y): # 等价于 return func_x(5) + func_y(3) r

软件项目技术点(19)——文件的保存和打开(解压缩)

保存文件 保存内容有哪些? 我们需要保存的内容信息 1)context.json 存储画布状态信息和所有元素的配置信息(这个文件在过程中生成) 2)插入的图片.音频.视频等资源 3)所用到的字体文件 4)每一帧的缩略图 将这些文件压缩到一个zip包里,我们的作品保存后的文件是dbk后缀格式的,其实就是一个压缩zip文件. 保存过程步骤解析 1)获取要保存的对象信息dtoCore,后面将其转换成字符串string后存储到文件里. 2)将保存作品用到的资源整理到fileList中,fileList对

iOS离线缓存

为了节省流量和更好的用户体验,目前很多应用都使用本地缓存机制,不需要每次打开app的时候都加载数据,或者重新向服务器请求数据,因此可以把每次浏览的数据保存到沙盒中,当下次打开软件的时候,首先从沙盒加载缓存的数据,或者当app未联网的时候,从沙盒中加载之前缓存的旧数据. 离线数据的方法选择 plist文件 Document路径 数据库 由于保存的是大批量数据,且会不停的刷新新数据,因此应该选择数据库来存储.使用数据库可以快速地进行数据的读取操作. 1.设计思路 如下图,说明了离线缓存的流程: 离线

impress.js 源码解析系列(2)

1 /** 2 * [impress description] 定义 impress 函数 3 * @param {[type]} rootId [description] 4 * @return {[type]} [description] 5 */ 6 var impress = window.impress = function( rootId ) { 7 // 如果浏览器不支持,则退出 8 if ( !impressSupported ) { 9 return { 10 init: em

Android源码AOSP之设置Settings阅读记录

Android 4.4 系统的设置源码阅读记录 ----------2014-7-3------------------ AndroidManifest.xml launch的activity是 Settings,另外有40多个activity继承于它,比如设置的一级菜单: wifi,蓝牙,声音,显示,安全,应用程序,语言和时间,关于设备等等.实际上都是这一个acitivy. 这里从安全设置看起,SecuritySettings.java 以资源文件R.xml.security_settings

Extjs 4 chart自定义坐标轴刻度

Sencha出品的ExtJs是一个非常优秀的前端框架,尤其是具有里程碑意义的4.0的发布.4.0采用MVC架构和全新的class系统,并且提供了非常丰富的组件.但是,尽管ExtJS如此强大,仍有不尽人意的地方.比如,chart里坐标轴的刻度通常是均匀分布的,ExtJS的实现也是通过坐标轴的最大值和最小值以及其他参数配置均匀的计算刻度.但是,在工作过程中碰到需要自定义刻度的情况,如下图所示 水平轴的刻度是5,10,20这样的不均匀值,但是ExtJS不支持这样的功能(至少我翻遍了文档也没找到).最初

NeHe OpenGL教程 第二十五课:变形

转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线教程的编写,以及yarn的翻译整理表示感谢. NeHe OpenGL第二十五课:变形 变形和从文件中加载3D物体: 在这一课中,你将学会如何从文件加载3D模型,并且平滑的从一个模型变换为另一个模型. 欢迎来到这激动人心的一课,在这一课里,我们将介绍模型的变形.需要注意的是各个模型必须要有相同的顶点,

IOS-导航路线

1.可以将需要导航的位置丢给系统自带的APP进行导航 2.发送网络请求到公司服务器获取导航数据, 然后自己手动绘制导航 3.利用三方SDK实现导航(百度) >当点击开始导航时获取用户输入的起点和终点 >利用GEO对象进行地理编码获取到地标对象(CLPlacemark ) >再利用获取到的地标对象(CLPlacemark)创建MKPlacemark >利用MKPlacemark创建起点的item >终点和起点逻辑一样 1.发送请求到苹果的服务器获取导航路线信息 2.根据服务器返