Nine degrees OJ 1554: Interval problem (set + prefix +map)

Source: Internet
Author: User

time limit:1 seconds

Memory limit:128 MB

Special question: No

submitted:3468

Resolution:291

Title Description:

Given an array, determine if there is a continuous interval within the array so that it is exactly equal to the given integer k.

Input:

The input contains multiple sets of test cases, each set of test cases starting with an integer n (1<=n<=10000), which represents the size of the array.
Next Act n An integer that describes the array, and the absolute value of the integer is not greater than 100.
The last behavior is an integer k (size within the int range).

Output:

For each set of test cases, if there is a continuous interval, the position of the start and end of the output, s,e (S <= e).
If there are more than one eligible output, then the output s smaller one, if there are still multiple, output e the smaller one.
If not present, direct output "no".

Sample input:
5-1 2 3-4 953-1 2-372-1 10
Sample output:
2 3no1 2
Source:
2014 King Forum Computer Postgraduate examination of the full true mock test





#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <set> #include <map > #define L (x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define EPS 1e-8//typedef __ Int64 ll; #define FRE (i,a,b) for (i = A; I < b; i++) #define FREE (i,a,b) for (i = A; I >= b;i--) #define MEM (T, v) mem Set ((t), V, sizeof (t)) #define SSF (n) scanf ("%s", N) #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 bu G PF ("hi\n") using namespace std, #define INF 0x3f3f3f3f#define n 100005int n;int sum[n],k;int A[n];set<int>le    ; Map<int, int>mp;void Solve () {int i,j;    Le.clear ();    Mp.clear ();    BOOL Flag=false;   int S,e;free (i,n,1) {Le.insert (sum[i]);   Mp[sum[i]]=i; if (Le.find (sum[i-1]+k)! =Le.end ()) {s=i;     E=MP[SUM[I-1]+K];   Flag=true;    }} if (flag) PF ("%d%d\n", s,e); Else PF ("no\n");}   int main () {int i,j,t,ca=0;   while (~SCANF ("%d", &n)) {fre (i,1,n+1) {SF (a[i]); sum[i]=sum[i-1]+a[i];}       SF (k);   Solve (); } return 0;}


Nine degrees OJ 1554: Interval problem (set + prefix +map)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.