Codeforces Round #304 (Div. 2) A B C 水
1 second
256 megabytes
standard input
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?
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 one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
3 17 4
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 ;
}
3 seconds
256 megabytes
standard input
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.
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 single integer — minimum amount of coins the colonel has to pay.
4
1 3 1 4
1
5
1 2 3 2 5
2
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 ;
}
2 seconds
256 megabytes
standard input
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.
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.
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.
4
2 1 3
2 4 2
6 2
3
1 2
2 1 3
-1
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 水的更多相关文章
- Codeforces Round #304 (Div. 2) Break the Chocolate 水题
Break the Chocolate Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546/ ...
- DP+埃氏筛法 Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:b+1,b+2,...,a 所有数的素数个数和 DP+埃氏筛法:dp[i] 记录i的素数个数和,若i是素数,则为1:否则它可以从一个数乘以素数递推过来 最后改为i之前所有素数个 ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
- 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...
- 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
- 数学+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;再来一个前缀和 */ /***************** ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- 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 ...
- 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 ...
随机推荐
- click
click简介 Click是一个Python包,用于以可组合的方式创建漂亮的命令行界面,只需要很少的代码.这是“命令行界面创建工具包”.它具有高度可配置性,但具有开箱即用的合理默认值. 点击三点: 任 ...
- 初尝微信小程序2-Swiper组件、导航栏标题配置
swiper 滑块视图容器. 很多网页的首页都会有一个滚动的图片模块,比如天猫超市首页,滚动着很多优惠活动的图片,用来介绍优惠内容,以及供用户点击快速跳转到相应页面. Swiper不仅可以滚动图片,也 ...
- wamp mysql服务意外停止
出现问题: MySQL启动一段时间之后,意外停止.可以再次启动,但是过不了多久又自动停止了. 发现问题: 查看错误日志,发现以下问题: 解决方案: 网上网友分享以下操作: 1.删除data文件夹里面的 ...
- k8s的pv和pvc简述
pvc:资源需要指定:1.accessMode:访问模型:对象列表: ReadWriteOnce – the volume can be mounted as read-write by a s ...
- 2D和3D效果
<style type="text/css"> #div1{ width: 200px; height: 200px; background-color:#aaa; c ...
- linux 编辑文档
本篇主要分享下vi 命令行的操作: vi /etc/sysconfig/iptabels 首先我们需要理解putty客户端的复制 粘贴 插入文档 退出等命令 复制:指在putty客户端中的选择复制 ...
- HTML5实现获取地理位置信息并定位功能
HTML5提供了地理位置定位功能(Geolocation API),能确定用户位置,我们可以借助HTML5的该特性开发基于地理位置信息的应用.本文结合实例给大家分享如何使用HTML5,借助百度.谷歌地 ...
- js控制台输出图案
控制台输出图案 console.log([ " _ooOoo_", " o8888888o", " 88\" . \"88&quo ...
- 科学计算库Numpy——文件读写
读文件 要读取的文件 有分隔符的文件 备注:delimiter分隔符. 有多余行的文件 备注:skiprows去掉几行. 指定列 备注:usecols指定使用哪几列. 写文件 保存后的文件 备注:fm ...
- 学习Spring框架系列(一):通过Demo阐述IoC和DI的优势所在
Spring框架最核心东西便是大名鼎鼎的IoC容器,主要通过DI技术实现.下面我通过Demo的演变过程,对比学习耦合性代码,以及解耦和的过程,并深入理解面向接口编程的真正内涵. 这个例子包括如下几个类 ...