码迷,mamicode.com
首页 > 其他好文 > 详细

今日竞赛——解题报告

时间:2015-07-14 22:33:39      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:

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, he has to pay i·k dollars for the i-th banana).

He has n dollars. How many dollars does he have 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 has and number of bananas he wants.

Output

Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn‘t have to borrow money, output 0.

Sample Input

Input

3 17 4

Output

13

思路:第一个K美元,第二个2K美元,第N个NK美元,。。。买N个要花费K+2K+.....+NK美元,即M美元,某人身上只有N美元,若M>N,则要向朋友借钱,否则不要

代码 :
#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 are given the ages (in years) of all people of a country with at least 1 year of age. You know that

no individual in that country lives for 100 or more years. Now, you are given a very simple task of

sorting all the ages in ascending order.

Input

There are 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 are

n

integers indicating the ages. Input is terminated

with a case where

n

= 0. This case should not be processed.

Output

For each case, print a line with

n

space separated integers. These integers are the ages of that country

sorted in ascending order.

Warning:

Input Data is pretty big (

 

25 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

 解题思路:n控制个数,用sort排序,输出格式需特别注意,最后一个元素后面应该接着输出一个回车,其它后面输出一个空格,当n为0时,结束

代码

#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 his friends very much, he decided to buy some chocolate for them, but as this fine chocolate is very expensive(You know Mohammad is a little BIT stingy!), he could only afford buying one chocolate, albeit a very big one (part of it can be seen in figure 1) for all of them as a souvenir. Now, he wants to give each of his friends exactly one part of this chocolate and as he believes all human beings are equal (!), he wants to split it into equal parts.

The chocolate is an rectangle constructed from  unit-sized squares. You can assume that Mohammad has 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 squares). Then, he should do 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 to 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 each line of input, there are two integers , the number of rows in the chocolate and , the number of columns in the chocolate. The input should be 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

 

 

解题思路:M*N面积的巧克力,M*N个朋友,经过分析,每个朋友有等面积的巧克力,则有要将一块大巧克力切M*N-1刀即可,但是需注意,当输入数据遇EOF时才结束,否则继续

代码

#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;
}

今日竞赛——解题报告

标签:

原文地址:http://www.cnblogs.com/www-cnxcy-com/p/4646695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!