Baskets of Gold Coins

Source: Internet
Author: User

Baskets of Gold Coins

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1862 Accepted Submission (s): 1108


Problem descriptionyou is given N baskets of gold coins. The baskets is numbered from 1 to N. In any except one of the baskets, each gold coin weighs w grams. In the one exceptional basket, each gold coin weighs w-d grams. A Wizard appears on the scene and takes 1 coin from basket 1, 2 coins from basket 2, and so on, up to and including N-1 Co INS from basket N-1. He does not take any coins from basket N. He weighs the selected coins and concludes which of the N baskets contains the lighter coins. Your mission is to emulate the wizard ' s computation.

Inputthe input file would consist of one or more lines; Each line would contain data for one instance of the problem. More specifically, each line would contain four positive integers, separated by one blank space. The first three integers is, respectively, the numbers N, W, and D, as described above. The fourth integer is the result of weighing the selected coins.

N would be is at least 2 and isn't more than 8000. The value of W is is at most 30. The value of D would be is less than W.


Outputfor Each instance of the problem, your program would produce one line of output, consisting of one positive integer: The number of the basket that contains lighter coins than the other baskets.

Sample Input10 25 8 110910 25 8 10458000 30 12 959879400

Sample Output21050: This problem means there are n baskets, from 1 to N-1 each basket to take the number of coins is 1 .... N-1; which has a basket of each coin value of w-d, the remaining baskets each coin value is w; ask this special basket to get the number of coins; the idea is whether sum equals (n-1+1) * (n-1)/2 *w; equals to prove that this particular basket is not taken; code:
#include <stdio.h>#include<string.h>intMain () {intn,w,d,sum;  while(~SCANF ("%d%d%d%d",&n,&w,&d,&sum)) {        intX=w* ((n1+1) * (n1)/2)-sum; if(x==0) printf ("%d\n", N); Elseprintf"%d\n", x/d); }    return 0;}

Baskets of Gold Coins

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.