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. android上部署tensorflow

    https://www.jianshu.com/p/ddeb0400452f 按照这个博客就可以 https://github.com/CrystalChen1017/TSFOnAndroid 这个博 ...

  2. 【0624课外作业】将一个double类型的小数,四舍五入保留两位小数

    package com.work0624; /** * 课外作业 *将一个double类型的小数,四舍五入保留两位小数 * @author L * */ import java.util.Scanne ...

  3. C#数组简介

    一.数组的定义 数组:是一种包含若干个变量的数据结构,这些变量可以通过索引进行访问. 数组的元素:数组中的变量就称为数组的元素. 元素类型:数组中的元素具有相同的数据类型,该数据类型就称为数组的元素类 ...

  4. .NET 中,编译器直接支持的数据类型称为基元类型(primitive type).基元类型和.NET框架类型(FCL)中的类型有直接的映射关系.

    .NET 中,编译器直接支持的数据类型称为基元类型(primitive type).基元类型和.NET框架类型(FCL)中的类型有直接的映射关系. The primitive types are Bo ...

  5. CPL学习笔记(二)

    数组 数组(array) 声明通用格式为: typeName arrayName[arraySize]. arrayName指定元素数目,必须为整型常量或const值.(不能是变量) int a[3] ...

  6. (70)zabbix telnet监控类型

    概述 zabbix监控的方式很多,例如前面讲到的agent.snmp以及后续后续要讲到ssh和今天要讲到的telnet.流程很简单,创建item-->配置ip.用户.密码.端口.脚本->z ...

  7. python爬虫基础09-selenium大全3/8-Remote Webdriver

    Selenium笔记(3)Remote Webdriver 本文集链接:https://www.jianshu.com/nb/25338984 简介 selenium.webdriver.remote ...

  8. 18/07/2017 R matrix

    矩阵:二维数组,元素拥有相同模式(数值型,字符型或者逻辑型) mymatrix <- matrix (vector, nrow_num_of_rows, ncol_num_of_columns, ...

  9. Linux之ssh服务介绍

    一.什么是SSH? 简单说,SSH(Secure Shell Protocol)是一种网络协议,用于计算机之间的加密登录.在默认状态下SSH服务提供俩个服务功能,一个是提供类似telnet远程联机服务 ...

  10. Linux学习-透过 systemctl 管理服务

    透过 systemctl 管理单一服务 (service unit) 的启动/开机启动与观察状态 一般来说,服务的启动有两个阶段,一 个是『开机的时候设定要不要启动这个服务』, 以及『你现在要不要启动 ...