POJ 3370 Halloween Treats

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=3370

Test instructions: Each group gives you a number C and a number of M, enter the number of M, let you output a number of subscript, these numbers together can be divided into C (c less than equals N), pigeon nest principle is also applicable,

Note that sum may overflow int, and read in with scanf to prevent timeouts.

Code:

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include < math.h> #include <iostream> #include <string> #include <queue> #include <stack> #include < vector> #include <algorithm> #define N 100000+100using namespace std;int a[n];long long int sum[n];int yu[n];    struct node{bool k; int POS;}    Q[n];int Main () {int N, C;    int I, J;    int left, right;        while (~SCANF ("%d%d", &c, &n)) {if (c==0 && n==0) break;        BOOL Flag1=false;        BOOL Flag2=false;            for (i=0; i<n; i++) {scanf ("%d", &a[i]);            if (i==0) sum[i]=a[i];        else Sum[i]=sum[i-1]+a[i];        } left=0;        memset (q, 0, sizeof (q));            for (i=0; i<n; i++) {yu[i]=sum[i]%c;            if (yu[i]==0) {flag1=true; right=i; break;             } else{if (Q[YU[I]].K) {flag2=true;       Left=q[yu[i]].pos; right=i;                Break                }else{q[yu[i]].k=true; q[yu[i]].pos=i;            }}} if (Flag1) {//printf ("%d\n", right+1);                for (i=0; i<=right; i++) {if (i==0) printf ("%d", i+1);            else printf ("%d", i+1);        } printf ("\ n");            } else if (Flag2) {//printf ("%d\n", right-left);                for (i=left+1; i<=right; i++) {if (i==left+1) printf ("%d", i+1);            else printf ("%d", i+1);        } printf ("\ n"); }} return 0;}

This is a person on the net to write code, relatively short: http://www.cnblogs.com/ACShiryu/archive/2011/08/09/poj3370.html for reference to learn.

POJ 3370 Halloween Treats

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.