546A. Soldier and Bananas

 

等差数列: 以k为首相,k为公差,w个数量的和与n的大小关系 输出max(sum-0,0)

Java程序

 

import java.util.Scanner;

public class A546 {

    static void run(){
        Scanner in = new Scanner(System.in);
        int k =in.nextInt();
        int n = in.nextInt();
        int w = in.nextInt();
        int count = 0;
        count = (1+w)*w*k/2;
//        System.out.println(count);
        if(count>n){
            System.out.println(count-n);
        }else
            System.out.println(0);
    }
    public static void main(String[] args){
        run();
    }
}

Python程序

def A546():
    k,n,w = map(int, raw_input().split())
    count = (1+w)*w*k*0.5
    if count > n :
        print int(count -n)
    else:
        print 0 

if __name__==‘__main__‘:
    A546()
时间: 2024-08-25 06:09:35

546A. Soldier and Bananas的相关文章

水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

题目传送门 1 /* 2 水题:ans = (1+2+3+...+n) * k - n,开long long 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 using namespace std; 9 10 typedef long long ll; 11 12 int main(void) //Codeforces Roun

CodeForces 546 A - Soldier and Bananas

题目链接:click here~~ [题目大意] 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 d

Codeforces546A:Soldier and Bananas

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 bo

Soldier and Bananas

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=173141 题意: 给出第一个香蕉的价钱k,后买的第i个香蕉所需要的价钱就是i*k: 给出手上所有的钱,求出如果要买w个香蕉还少多少钱. 代码: 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int k,w,n, sum=0; 6 cin>>k>>n>

codeforces水题100道 第五题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas (math)

题目链接:http://www.codeforces.com/problemset/problem/546/A题意:一个人现在有n元,它买第i根香蕉需要i*k元,问他要买w根香蕉的话,需要问他的朋友借多少钱?C++代码: #include <iostream> using namespace std; int n, k, w; int main() { cin >> k >> n >> w; cout << max(0, w*(w+1)/2*k-

Codeforces Round #304 (Div. 2) -----CF546

A. Soldier and Bananas 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 dol

【套题】Codeforces#304(div2)

A. Soldier and Bananas 题意:第一个香蕉要k刀,第二个2k刀,第i个要i?k刀.现有n刀,问可以买几个香蕉. 题解:等差数列求和,我们知道只需要找到p使得 ∑i=1pi?k≤n<∑i=1p+1i?k 即可,移项就可以得到公式,同时上述求和公式是单调递增的,因此也可以二分答案. 参考代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std;

CF#304Div2

A.Soldier and Bananas 题解:注意溢出以及不需要借钱的情况. 代码实现: #include <iostream> #include <bits/stdc++.h> using namespace std; int main() { long long Sum; long long K,N,W; cin>>K>>N>>W; Sum = (W+1)*W/2*K; if( Sum >= N ) Sum -= N; else S

网络流(最大流) CodeForces 546E:Soldier and Traveling

In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighb