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;elsecout<<"NO"<<endl;}return 0;
}

  

转载于:https://www.cnblogs.com/Blackops/p/5397080.html

LSU——1116 Necklace(尺取)相关推荐

  1. LSU——1116Necklace(尺取)

    1116 Necklace 通过率:5/23 难度系数:0 时间限制:1000ms 内存限制:32000KB java 两倍. 介绍 Little King has a beautiful pearl ...

  2. 洛谷 - P1381 - 单词背诵 - 哈希 - 尺取

    https://www.luogu.org/problemnew/show/P1381 字符串匹配,用哈希总没有错的. 然后就是尺取了,题目要求首先尽可能多覆盖,那么每次尾巴往后面长. 一开始先找到第 ...

  3. POJ 3320 Jessica's Reading Problem (尺取)

    Description 给出一段长度为\(n\)的整数序列,求包含所有出现过的数的连续区间的最小长度. Input 第一行给出序列长度\(n\),第二行给出\(n\)个整数,表示这个序列.\(n \l ...

  4. 部分和问题 (dfs搜索 尺取)

    部分和问题 给定整数a1, a2, a3, a4,  ..........   ,  an  ,判断是否可以从中取出若干个数,使得他们的和恰好为k  . 1  <= n <= 20 测试数 ...

  5. Innumerable Ancestors 尺取 dfs序 lca

    给一棵树,m次查询,每次查询给两个集合,从这两个集合中分别选一个结点,使得这两个结点的lca的深度最大 考虑dfs序为3, 4, 5的三个结点,3和4的lca深度一定大于等于3和5的lca深度 所以可 ...

  6. Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

  7. AtCoder - arc098_b Xor Sum 2(尺取+位运算)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,现在要求 AlxorAl+1xor...xorAr=Al+Al+1+...+ArA_l\ xor\ A_{l+1}\ xor\ ...\ ...

  8. 牛客 - Alice and Bob(尺取+二分)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的数列,和一个数字 kkk.现在给出 mmm 次询问,每次查询需要回答区间 [l,r][l,r][l,r] 内有多少个子区间,满足区间内不同的数字 ...

  9. 牛客多校9 - Groundhog Looking Dowdy(尺取)

    题目链接:点击查看 题目大意:给出 n 天,每天可以有数件衣服可以选择,但每天只能选择一件衣服穿,每件衣服都有权值,现在需要挑出 m 天的衣服,使得最大值与最小值之差最小 题目分析:比赛时为了恰烂分用 ...

最新文章

  1. 转载LINQ优点 自己学习用的
  2. 【极客blog图文讲解】Jekyll教程(针对mac linux)
  3. Python Importlib.import_module动态导入模块
  4. 使用 Java 配置进行 Spring bean 管理
  5. 【LeetCode笔记】146. LRU缓存机制(Java、双向链表、哈希表)
  6. Java LinkedList公共对象peek()方法(带示例)
  7. 自动化调参NNI学习(三):使用python启动NNI框架调整随机森林(RandomForest)模型
  8. 大佬分享:程序员必知的干货
  9. python2与python3在windows下共存
  10. Win2008使用无线网络
  11. C语言中数组和字符串长度以及输入输出详解
  12. Cython使用及pycharm
  13. python:使用 PythonMagick 生成 icon 图标
  14. 阿里云Centos7安装mysql5.7
  15. android ping网络连接服务器失败,Android 中网络连接检测和使用ping检测网络是否可访问...
  16. 百度APP视频播放中的解码优化
  17. mq常见学习问题总结笔记
  18. 【毕业设计项目】基于ESP32的家庭气象站系统 - stm32 物联网 嵌入式 单片机
  19. 操作系统之Windows
  20. java架构师视频,附源代码

热门文章

  1. 微信amr语音文件转文字功能实现
  2. 数据库系统概论 第七章课后习题(部分)
  3. 硬件设计——热阻参数介绍
  4. 搜狐新闻APP是如何使用HUAWEI DevEco IDE快速集成HUAWEI HiAI Engine
  5. Apache与Weblogic的整合
  6. Webapi添加token认证功能
  7. 全球及中国水性喷墨墨水行业行业运行态势及未来发展前景报告2022-2028年
  8. 良心到难以置信的网站推荐丨上网必备
  9. 1086 就不告诉你 (15 分)
  10. MySQL使用FROM_UNIXTIME将时间戳格式化输出显示