URAL 1796. Amusement Park (Math)

Source: Internet
Author: User

1796. Amusement Park
Time limit:1.0 Second
Memory limit:64 MB
On a sunny Sunday, a group of children headed by their teacher came to an amusement park. Aunt frosya,who is a very kind and quiet person, worked at the ticket window on the. The teacher gave herthe money but didn ' t say what many tickets she wanted to buy. Could Aunt Frosya determine it knowing onlythe numbers of different notes the teacher gave? It is assumed, the teacher didn ' t give extra notes,which means that there would isn't being enough money for the tickets if Any of the notes is taken away. Inputthe first line contains six nonnegative integers separated with a space; These is the numbers of ten, 100,500, +, and rouble notes the teacher gave to Aunt Frosya. The second line is given the priceof one ticket; It is a positive integer. All the integers in the input data does not exceed 1000.OutputFind the number of tickets the teacher wanted to buy. Output the number of possible answers in the first line. The variants in ascending order separated with a space muSt be given on the second line. It is guaranteed thatthere are at least one variant of the answer. Samples
input Output
0 2 0 0 0 010
56 7 8) 9 10
1 2 0 0 0 010
111
problem Author:Eugene Kurpilyansky, prepared by Egor shchelkonogov
problem Source:Ural Regional School Programming Contest 2010




Resolution: The teacher didn ' t give extra notes,which means that there would not being enough money for the tickets if any of the note S was taken away this sentence is the key, according to this principle, we determine the minimum and maximum amount of money to buy tickets. Then in order to find out the number of votes that can be bought.




AC Code:

#include <bits/stdc++.h>using namespace Std;int b[6] = {Ten, A, +, +, +, 5000};set<int> ans;int main () {    #ifdef sxk        freopen ("In.txt", "R", stdin);    #endif//sxk    int a[6], k, sum = 0;    int t = 0;    for (int i=0; i<6; i++) {        scanf ("%d", &a[i]);        Sum + = a[i] * B[i];        if (!t && a[i]) t = b[i];    }    scanf ("%d", &k);    for (int i=sum-t + 1; I <= sum; i++) {        if (i-k = = 0) ans.insert (i/k);    }    int n = ans.size ();    printf ("%d\n", n);    for (Set<int>::iterator it = Ans.begin (); It! = Ans.end (); it + +) printf ("%s%d", it! = Ans.begin ()? "": "", *it);    return 0;}


URAL 1796. Amusement Park (Math)

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.