1116 Necklace

通过率:5/23 难度系数:0
时间限制:1000ms 内存限制:32000KB java 两倍。

介绍

Little King has a beautiful pearl necklace, one day, he find that there is a number in each pearl, so he want to know whether he can find a continuous sequence that the sum of them is the number he give to you.

输入格式描述

The first line contains one integer T(T<=50),indicating the number of test cases.

For each test case ,the first line contains two integer N(5<=N<=100000),K(1<=K<=109)(within int),indicating there are N pearls in necklace and the number he give to you .The second line contains N integer Ai(1<=Ai<=10000),indicating the number in each pearl, pearls are sort by clockwise.

输出格式描述

For each test case, if he can find out print YES, otherwise print NO.

样例输入
样例输出
 
3
5 15
1 2 3 4 5
5 16
1 2 3 4 5
6 18
1 2 3 4 5 7

YES
NO
YES

突然想起来同学学校的题目我还没写。刚开始纠结于第三个例子,后来问了同学才想起来这是个项链,这坑会造成数组越界,稍微处理一下。怎么把cin同步关掉快scanf这么多,奇怪

代码:

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
int list[300010];
int main (void)
{
ios::sync_with_stdio(false);
int t,i,j,n,s;
cin>>t;
while (t--)
{
memset(list,0,sizeof(list));
cin>>n>>s;
for (i=1; i<=n; i++)
{
cin>>list[i];
list[n+i]=list[i];
}
bool flag=false;
int l=1,r=1,temp=0;
while (1)
{
while (temp<s&&r<=2*n)
{
temp+=list[r++];
}
if(temp<s)
break;
if(temp==s&&r-l<=n)
{
flag=true;
break;
}
temp-=list[l++];
if(temp==s&&r-l<=n)
{
flag=true;
break;
}
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}

  

LSU——1116 Necklace(尺取)的更多相关文章

  1. Gym 100703I---Endeavor for perfection(尺取)

    题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...

  2. NOJ 1072 The longest same color grid(尺取)

    Problem 1072: The longest same color grid Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit in ...

  3. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  4. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  5. poj2566尺取变形

    Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...

  6. poj2100还是尺取

    King George has recently decided that he would like to have a new design for the royal graveyard. Th ...

  7. hdu 6231 -- K-th Number(二分+尺取)

    题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...

  8. Codeforces 939E Maximize! (三分 || 尺取)

    <题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...

  9. cf1121d 尺取

    尺取,写起来有点麻烦 枚举左端点,然后找到右端点,,使得区间[l,r]里各种颜色花朵的数量满足b数组中各种花朵的数量,然后再judge区间[l,r]截取出后能否可以供剩下的n-1个人做花环 /* 给定 ...

随机推荐

  1. SQL Server将列以分隔符分割后存到临时表

    begin if object_id('tempdb..#t') is not null drop table #t; create table #t ( filepath ) ); declare ...

  2. iOS中的数据存储方式_Plist

    plist文件只能存储OC常用数据类型(NSString.NSDictionary.NSArray.NSData.NSNumber等类型)而不能直接存储自定义模型对象; 我们拿NSData举例: /* ...

  3. 【状态压缩dp】1195: [HNOI2006]最短母串

    一个清晰的思路就是状压dp:不过也有AC自动机+BFS的做法 Description 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串(S1,S2,„,Sn)都是T ...

  4. UVa 12171 题解

    英文题面不怎么友好,大家还是自行通过紫书了解题面吧... 解题思路: 1. 面对500 ^ 3的数据范围,我们需要先用离散化解决掉爆空间的问题. 2. 由于我们要求的总体积包括内空部分的体积,我们可以 ...

  5. 03大端和小端(Big endian and Little endian)

    1.大端和小端的问题 ​ 对于整型.长整型等数据类型,Big endian 认为第一个字节是最高位字节(按照从低地址到高地址的顺序存放数据的高位字节到低位字节),而 Little endian 则相反 ...

  6. Vim编辑器基础

    Vim编辑器基础 vi:Visual Interface vim:VI iMproved Vim模式 1.编辑模式(命令模式) 只能下达命令,不能键入字符 2.输入模式 键入字符 3.末行模式 左下角 ...

  7. VMware安装Ubuntu配置NAT模式下静态IP,解决访问外网问题

    安装好VMware后,打开网络连接可以看到有VMware Network Adapter VMnet1和VMware Network Adapter VMnet8两个网络适配器,VMnet1是针对桥接 ...

  8. MySQL查询时,查询结果如何按照where in数组排序

    MySQL查询时,查询结果如何按照where in数组排序 在查询中,MySQL默认是order by id asc排序的,但有时候需要按照where in 的数组顺序排序,比如where in的id ...

  9. Win2008 Server配置PHP环境

    Win2008 Server配置PHP环境   阅读目录 创建一个网站 配置PHP环境 配置iis的“处理应用程序映射” 在配置PHP环境之前要先配置好IIS. 传送门-> Win2008 Se ...

  10. 什么是python中的元类

    所属网站分类: python高级 > 面向对象 作者:goodbody 原文链接: http://www.pythonheidong.com/blog/article/11/ 来源:python ...