A. Soldier and Bananas
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
Input
3 17 4
Output
13

题意:第i个香蕉i*k元 买w个香蕉 现在有n元 问需要借多少钱?

题解:k*(1+w)*w/2-n
 //code by  drizzle
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int k,n,w;
int main()
{
scanf("%d %d %d",&k,&n,&w);
if(k*(+w)*w/-n<)
cout<<""<<endl;
else
cout<<k*(+w)*w/-n<<endl;
return ;
}
B. Soldier and Badges
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.

For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors.

Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

Input

First line of input consists of one integer n (1 ≤ n ≤ 3000).

Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.

Output

Output single integer — minimum amount of coins the colonel has to pay.

Examples
Input
4
1 3 1 4
Output
1
Input
5
1 2 3 2 5
Output
2
Note

In first sample test we can increase factor of first badge by 1.

In second sample test we can increase factors of the second and the third badge by 1.

题意:n个数  现在要求这n个数完全不同 并且对于单个数只能增加x或不变

问min(Σ x)

题解:标记每个数的个数  从i=1开始遍历 因为要求每个数只能出现一次所以  对于其余的数

全部加1继承到下一个数  并且更新ans   一直遍历到i=2*3000;  考虑3000个3000的特殊数据;

 //code by  drizzle
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int n;
int a[];
int mp[];
int main()
{
scanf("%d",&n);
memset(mp,,sizeof(mp));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
mp[a[i]]++;
}
int ans=;
for(int i=;i<=;i++)
{
if(mp[i]>)
{
ans+=(mp[i]-);
mp[i+]+=(mp[i]-);
}
}
cout<<ans<<endl;
return ;
}
C. Soldier and Cards
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.

The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.

You have to calculate how many fights will happen and who will win the game, or state that game won't end.

Input

First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.

Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack.

Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack.

All card values are different.

Output

If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.

If the game won't end and will continue forever output  - 1.

Examples
Input
4
2 1 3
2 4 2
Output
6 2
Input
3
1 2
2 1 3
Output
-1
Note

First sample:

Second sample

题意: 给你初始两个队列 q1 q2   两个队头元素出队x y   比较大小 x>y    y,x按照顺序入q1  反之亦然;

不存在x,y相等的情况

当某一个队列为空时 另一个队列获胜 输出游戏进行的回合数和获胜一方的编号1或2

若游戏一直进行无法结束输出-1;

题解:队列模拟整个过程  对于死循环的判断  设置一个回合进行的上限值 超过上限则break 输出-1;

 //code by  drizzle
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int n;
int k1,k2;
queue<int> q1;
queue<int> q2;
int exm;
int main()
{
scanf("%d",&n);
scanf("%d",&k1);
while(!q1.empty())
q1.pop();
while(!q2.empty())
q2.pop();
for(int i=;i<=k1;i++)
{
scanf("%d",&exm);
q1.push(exm);
}
scanf("%d",&k2);
for(int i=;i<=k2;i++)
{
scanf("%d",&exm);
q2.push(exm);
}
int ans=;
int out=;
int flag=;
while(flag)
{
if(ans>)
{
cout<<"-1"<<endl;
return ;
}
if(q1.empty())
{
flag=;
out=;
}
if(q2.empty())
{
flag=;
out=;
}
if(flag==)
break;
ans++;
int x=q1.front(),y=q2.front();
q1.pop();
q2.pop();
if(x<y)
{
q2.push(x);
q2.push(y);
}
else
{
q1.push(y);
q1.push(x);
}
}
printf("%d %d\n",ans,out);
return ;
}

Codeforces Round #304 (Div. 2) A B C 水的更多相关文章

  1. Codeforces Round #304 (Div. 2) Break the Chocolate 水题

    Break the Chocolate Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546/ ...

  2. DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...

  3. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

  4. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

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

    题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...

  6. 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game

    题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...

  7. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  8. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  9. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

随机推荐

  1. pymysql 简单操作数据库

    #!/usr/bin/env python #-*- coding:utf-8 -*- # author:leo # datetime:2019/4/24 15:22 # software: PyCh ...

  2. sublime package control以及常用插件

    一.package Control安装 1.sublime 3 import urllib.request,os; pf = 'Package Control.sublime-package'; ip ...

  3. 在主机端和设备端进行”incrementArray“并对结果进行比较

    实验思想: 在主机端将数据初始化后传输到设备端,设备端和主机端进行同样的操作对数据加1,然后将设备端的结果传输到主机,最后核对主机端的计算结果和设备端的计算结果是否一直. // incrementAr ...

  4. 开发监测keepalived裂脑的脚本

    检测思路:在备节点上执行脚本,如果可以ping通主节点并且备节点有VIP就报警,让人员介入检查是否裂脑. 在LB02备节点上开发脚本并执行: [root@lb02 ~]# cat /server/sc ...

  5. 10分钟了解 react 引入的 Hooks

    "大家好,我是谷阿莫,今天要将的是一个...",哈哈哈,看到这个题我就想到这个开头.最近react 官方在 2018 ReactConf 大会上宣布 React v16.7.0-a ...

  6. 科学计算库Numpy——运算

    np.multiply(array1,array2) 该函数用于数组中对应位置上的数相乘. 一维向量 二维数组 np.dot(array1,array2) 两个数组都是一维向量 数组中对应位置上的数相 ...

  7. day25-python之继承组合

    1.上节回顾 class School: x=1 def __init__(self,name,addr,type): self.Name=name self.Addr=addr self.Type= ...

  8. Base64及其Python实现

    1. 什么是Base64 Base64是一种基于64个可打印字符来表示二进制数据的表示方法 Base64是一种编码方式,提及编码方式,必然有其对应的字符集合.在Base64编码中,相互映射的两个集合是 ...

  9. 递推:Number Sequence(mod找规律)

    解题心得: 1.对于数据很大,很可怕,不可能用常规手段算出最后的值在进行mod的时候,可以思考找规律. 2.找规律时不必用手算(我傻,用手算了好久).直接先找前100项进行mod打一个表出来,直接看就 ...

  10. Java语言基础---逻辑运算(长路短路运算)

    长路短路运算的区别 长路与运算&:是指在两边都是整数时,是逐位与运算,在两边是关系运算时,是逻辑运算. 短路与运算&&:是指从左至右,遇到false,则停止后面的运算. 长路或 ...