Today's contest--Problem solving report

Source: Internet
Author: User

MS Memory Limit:262144KB 64bit IO Format:%i64d &%i64u

Submit Status Practice Codeforces 546A

Description

A soldier wants to buy W bananas in the shop. He has to pay K dollars for the first banana, 2k dollars for the second one and so on (in other words, h e have to pay Ik dollars for the i-th banana).

He has n dollars. How many dollars does he has to borrow from his friend soldier to buy w bananas?

Input

The first line contains three positive integers k, n, w (1≤ k, w ≤ 1000, 0≤ n ≤109), the cost of the first banana, initial number of dollars the soldier have and number of bananas he w Ants.

Output

Output one integer-the amount of dollars, the soldier must borrow from his friend. If He doesn ' t has to borrow money, output 0.

Sample Input

Input

3 17 4

Output

13

Idea: The first k dollar, the second 2K dollars, the nth NK dollar, ... Buy N to spend k+2k+.....+nk dollars, that is, M dollars, someone has only N dollars, if m>n, you have to borrow money from friends, or do not

Code:
#include <iostream>
using namespace std;
int main ()
{
int k,n,w,m=0;
cin>>k>>n>>w;
For (; w>=1;w--)
M+=w*k;
if (m>n)
cout<<m-n<<endl;
else cout<< "0" <<endl;
return 0;
}


B-b

Time limit:5000MS Memory Limit:0KB 64bit IO Format:%lld &%llu

Submit Status Practice UVA 11462

Description

11462

Age Sort

You is given the ages (in years) of any people of a country with at least 1 You know that

No individual in, country lives for, or more years. Now, you is given a very simple task of

Sorting all the ages in ascending order.

Input

There is multiple test cases in the input
Le. Each case starts with an integer

N

(0

<n

2000000), the

Total number of people. In the next line, there is

N

Integers indicating the ages. Input is terminated

With a case where

N

= 0. This case is should not being processed.

Output

For each case, print a line with

N

Space separated integers. These integers is the ages ofthat country

Sorted in ascending order.

Warning:

Input Data is pretty big (

MB) so use faster IO.

Sample Input

5

3 4 2) 1 5

5

2 3 2) 3 1

0

Sample Output

1 2 3) 4 5

1 2 2) 3 3

Problem-Solving ideas: N control number, sorted by sort, output format should pay special attention, the last element should then output a carriage return, the other after the output of a space, when n is 0 o'clock, the end

Code

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int m=2000000+5;
int a[m], i,j,n,temp;
int main ()
{
While (cin>>n&&n!=0)
{
For (i=0;i<n;i++)
scanf ("%d", &a[i]);
sort (a,a+n);
For (i=0;i<n-1;i++)
printf ("%d", A[i]);
cout<<a[i]<<endl;
}
return 0;
}


D-d

Time limit:3000MS Memory Limit:0KB 64bit IO Format:%lld &%llu

Submit Status Practice UVA 10970

Description

Problem G

Big Chocolate

Mohammad has recently visited Switzerland. As he loves he friends very much, he decided to buy some chocolate for them, but as this fine chocolate is very expensive (You know Mohammad are a little BIT stingy!), he could only afford buying one chocolate, albeit a very big one (part of it Can is seen in Figure 1) for all of them as a souvenir. Now, he wants to give each of its friends exactly one part of this chocolate and as he believes all human beings is equal (!), he wants to split it into equal parts.

The chocolate is a rectangle constructed from unit-sized squares. You can assume that Mohammad have also friends waiting to receive their piece of chocolate.

To split the chocolate, Mohammad can cut it in vertical or horizontal direction (through the lines that separate the Squar ES). Then, he should does the same with each part separately until he reaches unit size pieces of chocolate. Unfortunately, because he is a little-lazy, he wants to use the minimum number of cuts required-accomplish this task.

Your goal is to tell him the minimum number of cuts needed to split all of the chocolate squares apart.

Figure 1. Mohammad ' s Chocolate

The Input

The input consists of several test cases. In all line of input, there is integers, the number of the rows in the chocolate and, the number of columns in the Cho Colate. The input should was processed until end of file is encountered.

The Output

For each line of input, your program should produce one line of output containing an integer indicating the minimum number Of cuts needed to split the entire chocolate into unit size pieces.

Sample Input

2 2

1 1

1 5

Sample Output

3

0

4

Problem-Solving ideas: m*n area of chocolate, m*n a friend, after analysis, each friend has an area of chocolate, there is to be a big chocolate cut m*n-1 knife can be, but note that when the input data met EOF to end, otherwise continue

Code

#include <iostream>
using namespace std;
int main ()
{
int m,n;
int n;
While (cin>>m>>n&& (m!=0&&n!=0))
 {
cout<<m*n-1<<endl;

 }
return 0;
}

Today's contest--Problem solving report

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.