Negative and Positive (NP) (hdu 5183 set+输入外挂)
来源:互联网 发布:巨邦国际 知乎 编辑:程序博客网 时间:2024/05/17 04:36
Negative and Positive (NP)
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2488 Accepted Submission(s): 618
Problem Description
When given an array (a0,a1,a2,⋯an−1) and an integer K , you are expected to judge whether there is a pair (i,j)(0≤i≤j<n) which makes that NP−sum(i,j) equals to K true. Here NP−sum(i,j)=ai−ai+1+ai+2+⋯+(−1)j−iaj
Input
Multi test cases. In the first line of the input file there is an integer T indicates the number of test cases.
In the next2∗T lines, it will list the data for each test case.
Each case occupies two lines, the first line contain two integersn and K which are mentioned above.
The second line contain(a0,a1,a2,⋯an−1) separated by exact one space.
[Technical Specification]
All input items are integers.
0<T≤25,1≤n≤1000000,−1000000000≤ai≤1000000000,−1000000000≤K≤1000000000
In the next
Each case occupies two lines, the first line contain two integers
The second line contain
[Technical Specification]
All input items are integers.
Output
For each case,the output should occupies exactly one line. The output format is Case #id: ans, here id is the data number starting from 1; ans is “Yes.” or “No.” (without quote) according to whether you can find (i,j) which makes PN−sum(i,j) equals to K .
See the sample for more details.
See the sample for more details.
Sample Input
21 112 1-1 0
Sample Output
Case #1: Yes.Case #2: No.HintIf input is huge, fast IO method is recommended.
Source
BestCoder Round #32
Recommend
hujie | We have carefully selected several similar problems for you: 5189 5188 5185 5184 5181
思路:先计算出前缀和sum,然后枚举起点,从后往前枚举起点i,若i为奇数,则看set里面有没有sum[i-1]+k;若i为偶数,则看set里面有没有sum[i-1]-k。要用到输入外挂,不知道为什么,我的代码用G++交有时能过,有时却TLE,难道还要看OJ的心情吗=。=
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <map>#include <stack>#include <vector>#include <set>#include <queue>#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 1005000#define MAXN 2005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6#define lson rt<<1,l,mid#define rson rt<<1|1,mid+1,r#define FRE(i,a,b) for(i = a; i <= b; i++)#define FRL(i,a,b) for(i = a; i < b; i++)#define mem(t, v) memset ((t) , v, sizeof(t))#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define DBG pf("Hi\n")typedef long long ll;using namespace std;ll sum[maxn];ll a[maxn];ll n,k;set<ll>s;inline bool scan_d(ll &ret) //输入外挂{ char c; ll sgn; if (c=getchar(),c==EOF) return false; while (c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while (c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return true;}int main(){ ll x; ll i,j,t,cas=1; scan_d(t); while (t--) { scan_d(n); scan_d(k); FRL(i,1,n+1) scan_d(a[i]); sum[0]=0; sum[1]=a[1]; FRL(i,2,n+1) //计算前缀和 { if (i%2) sum[i]=sum[i-1]+a[i]; else sum[i]=sum[i-1]-a[i]; } s.clear(); bool flag=false; for (i=n;i>0;i--) { s.insert(sum[i]); //现插入集合 if (i%2) { if (s.find(sum[i-1]+k)!=s.end()) { flag=true; break; } } else { if (s.find(sum[i-1]-k)!=s.end()) { flag=true; break; } } } if (flag) pf("Case #%lld: Yes.\n",cas++); else pf("Case #%lld: No.\n",cas++); } return 0;}
2 0
- Negative and Positive (NP) (hdu 5183 set+输入外挂)
- hdu 5183-Negative and Positive (NP) (hash+输入外挂)
- HDU 5183 Negative and Positive (NP) (set + 读入外挂 乱搞)
- hdu 5183 Negative and Positive (NP)
- HDU 5183 Negative and Positive (NP)
- HDU 5183 - Negative and Positive (NP)(Hash)
- hdu 5183 Negative and Positive (NP)
- HDU 5183 Negative and Positive (NP) (hash)
- hdu 5183-Negative and Positive (NP)
- hdu 5183 Negative and Positive (NP)
- hdu 5183 Negative and Positive (NP)(hash,思路)
- hdu 5183 Negative and Positive (NP) (hash大法)
- [HDU 5183][BestCoder #32]Negative and Positive (NP) (STL模板)
- hdu 5183 Negative and Positive (NP)【fast IO +哈希表】
- Negative and Positive (NP) ( Hash 维护 )
- 【HDU5183】Negative and Positive (NP)
- HDU 5183 Negative and Positive (NP)(哈希 hash)——BestCoder Round #32
- hdu5138 Negative and Positive (NP) 快速读入
- 流氓软件微信电话本案例研究
- iOS注销通知问题
- 解决JAVA创建好的数组里添加新数据(忽略数组长度)
- 2015元宵节礼物——《刀塔传奇》骨骼动画查看器,开源啦!
- 黑马程序员---oc 协议和代理
- Negative and Positive (NP) (hdu 5183 set+输入外挂)
- ListView更新后无法响应点击事件解决方法(失去焦点)
- jz2440平台nandflash驱动分析
- 新浪微博开发四(导航栏按钮的扩展和图片拉伸处理的扩展)
- IOS UITextView加上placeholder
- 利用 Profiler(性能分析器)查看游戏在移动真机上的性能消耗数据
- eclipse svn导出 web 项目 显示为java 项目的解决办法
- JavaScript常见字符串操作
- Android Studio 添加 Library Project (以Volley为例)