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 dollars does he have to borrow from his friend soldier to buy w bananas?

【解题思路】

公式:判断(((w+1)*(w)/2)*k-n)是否大于零

代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,n,w;
    scanf("%d%d%d",&k,&n,&w);
    printf("%d\n",(((w+1)*(w)/2)*k-n)>0?(((w+1)*(w)/2)*k-n):0);
    return 0;
}
时间: 2024-10-11 16:09:15

CodeForces 546 A - Soldier and Bananas的相关文章

codeforces 546 E Soldier and Traveling

传送门 题意:给你初始状态和目标状态,再给你m条路,士兵只能通过路走到相邻城市去,一个士兵只能移动一次.问你能否到达该状态,如果能输出转移的矩阵 题解:很显然的网络流,将一个点拆成三个,一个初始状态与s连,一个目标状态与t连,容量b[i],在建立一个中间点,连接初始状态容量INF和目标状态容量a[i]:记录下每个中间点和相邻点的边,再跑完网络流后,原容量减去残余流量就能得到转移的士兵个数 #include <iostream> #include <cstdio> #include

水题 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水题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 D546:Soldier and Number Game

题目链接:http://codeforces.com/problemset/problem/546/D 输入t对数 a, b 求(b,a]内的每个数拆成素因子的个数和 这里每个数都可以写成素数的乘积,可以写成几个素数的和就有几个素因子,这里求的是(b,a]内的素因子和 思路: 素数的素因子个数是1 对于非素数A的素因子个数 = A/k  + 1 其中k是素数,也是第一个素数,或者K是比A小的数,并且A%k==0 下面是利用K是比A小的数,并且A%k==0 1 void solve(){ 2 Sc

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

网络流(最大流) 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

【CodeForces - 546C】Soldier and Cards (vector或队列)

Soldier and Cards 老样子,直接上国语吧  Descriptions: 两个人打牌,从自己的手牌中抽出最上面的一张比较大小,大的一方可以拿对方的手牌以及自己打掉的手牌重新作为自己的牌,放在自己手牌的最下方,而且对方输掉的那张手牌需要放在上面,自己赢的手牌放在下面. Input 第一行的数n代表一共有几张牌 第二行第一个数x代表第一个人有x张牌 第三行第一个数y代表第二个人有y张牌 Output 第一个数代表进行了几轮,第二个数代表谁赢 Examples Input 42 1 32

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>

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+