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. dojo中类的继承

    类似于c# java等后台语言,在基于类的面向对象编程中,通常需要在子类中扩展某些父类的方法,这时可以在子类的方法中,先调用从父类继承的方法,然后再执行子类自定义的操作.凡是使用declare创建的类 ...

  2. CUDA并行存储模型

    CUDA将CPU作为主机(Host),GPU作为设备(Device).一个系统中可以有一个主机和多个设备.CPU负责逻辑性强的事务处理和串行计算,GPU专注于执行高度线程化的并行处理任务.它们拥有相互 ...

  3. 网络编程——UDP协议和通信

    第1章 UDP与TCP协议 在介绍TCP/IP结构时,提到传输层的两个重要的高级协议,分别是UDP和TCP,其中UDP是User Datagram Protocol的简称,称为用户数据报协议,TCP是 ...

  4. 利用原生JS实现类似浏览器查找高亮功能(转载)

    利用原生JS实现类似浏览器查找高亮功能 在完成 Navify 时,增加一个类似浏览器ctrl+f查找并该高亮的功能,在此进行一点总结: 需求 在.content中有许多.box,需要在.box中找出搜 ...

  5. SummerVocation_Learning--java的线程机制

    线程:是一个程序内部的执行路径.普通程序只有main()一条路径.如下列程序: import java.lang.Thread; //导入线程实现包 public class Test_Thread ...

  6. pycharm 语言配置

    在pycharm 安装所在位置找到 lib 文件夹 打开后找到 rescources_**.jar 文件 **为语言类型,英语为en 中文为cn, 用相应语言文件替换,便可变成相应语言 https:/ ...

  7. jquery/js/a标签实现当前页面跳转的两种方法

    在逛购物网站首页时经常看到侧边导航栏,当我们点击导航栏中某一项时会跳转到当前页面的某一处 有两种方法实现,一种是利用js计算好各位置的高度,通过绑定事件使页面跳转到指定位置,另一种是利用a标签进行当前 ...

  8. php五种常见的设计模式

    工厂模式 工厂模式是最常用的实例化对象的模式,是用工厂方法代替new操作的一种模式 使用工厂模式的好处是:如果想要更改实例化的类名,则只需要更改该工厂方法内容即可,不需逐一寻找代码中具体实例化的地方( ...

  9. B1023 组个最小数 (20分)

    B1023 组个最小数 (20分) 给定数字 0-9各若干个.你可以以任意顺序排列这些数字,但必须全部使用.目标是使得最后得到的数尽可能小(注意 0 不能做首位).例如:给定两个 0,两个 1,三个 ...

  10. 笔记-python-反射

    笔记-python-反射 1. 反射 在很多地方看到自省和反射,很晕菜,整理了一下相关文档,加深了理解. 自省和反射其实说的是一件事,核心操作是根据输入去对象(模块)中调用(查找/获取/删除/添加)成 ...