LSU——1116 Necklace(尺取)
1116 Necklace
时间限制: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.
5 15
1 2 3 4 5
5 16
1 2 3 4 5
6 18
1 2 3 4 5 7
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(尺取)的更多相关文章
- Gym 100703I---Endeavor for perfection(尺取)
题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...
- 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 ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- poj2566尺取变形
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- poj2100还是尺取
King George has recently decided that he would like to have a new design for the royal graveyard. Th ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
- cf1121d 尺取
尺取,写起来有点麻烦 枚举左端点,然后找到右端点,,使得区间[l,r]里各种颜色花朵的数量满足b数组中各种花朵的数量,然后再judge区间[l,r]截取出后能否可以供剩下的n-1个人做花环 /* 给定 ...
随机推荐
- vue 文件流下载xlsx 功能实现
downLoadFile (url, name) { this.xhr = new XMLHttpRequest() this.xhr.open('GET', url, true) this.xhr. ...
- k8s1.13.0二进制部署-master节点(三)
部署apiserver 创建生成CSR的JSON配置文件 [root@k8s-master1 ssl]# vim kubernetes-csr.json { "CN": " ...
- java 自定义容器,实现foreach
import java.util.Arrays; import java.util.Iterator; public class ArrayList implements Iterable<In ...
- ctDNA|endosymbiosis
5.10叶绿体基因组编码多种蛋白质和RNA 叶绿体和线粒体的共同点:叶绿体和线粒体的大小,功能(编码区)大体一致,但叶绿体拥有更多基因,所以在编码tRNA时,也有内含子作为被剪切片段. 因为在原核生物 ...
- 伪基站SSRP
伪基站的基本构成包括一台发射主机.一台笔记本电脑.一根天线.一部手机和电源.其中,手机用来测得频点,即某个区域运营商正规基站的频点,然后再把频点和短信内容输入到电脑安装好的程序,通过发射主机和天线进行 ...
- 【转】LDA-linear discriminant analysis
分类问题也可以用降维来理解,比如一个D维的数据点x,我们可以采用下面的映射进行线性的降维, y=θTx 在计算出y后,就可以选择一个阈值h,来进行分类.正如我们在前面的PCA模型中看到的,降维会有信息 ...
- tensorflow目标检测API之训练自己的数据集
1.训练文件的配置 将生成的csv和record文件都放在新建的mydata文件夹下,并打开object_detection文件夹下的data文件夹,复制一个后缀为.pbtxt的文件到mtdata文件 ...
- MySQL_8.0.15_Windows10_X64 安装教程
最近学习的内容涉及到MySQL的知识,所以安装一个MySQL非常有必要,参考别人的教程安装过程还算顺利,其中遇到了一些问题查了一些也解决了,这里把整个安装过程梳理一遍,给大家一个参考. 我手里的电脑是 ...
- python numpy模块
目录 numpy模块 一维数组 二维数组(用的最多的) 获取多维数组的行和列 多维数组的索引 高级功能 多维数组的元素的替换 通过函数方法创建多维数组 矩阵的运算 点乘和转置(了解) 点乘必须 m*n ...
- python 中 * 与**的使用
1.参数中使用如果是函数定义中参数前的*表示的是将调用时的多个参数放入元组中,**则表示将调用函数时的关键字参数放入一个字典中 如定义以下函数 def func(*args): print(args) ...