Codeforces Round #342 (Div 2) 解题报告
除夕夜之有生之年CF第一场
下午从奶奶家回到姥姥家,一看还有些时间,先吃点水果陪姥姥姥爷聊了会儿,再一看表,5:20。。。。woc已经开场20分钟了。。。于是抓紧时间乱搞。。
**A. Guest From the Past**
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles.
Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn’t know how to act optimally and asks for your help.
Input
First line of the input contains a single integer n (1 ≤ n ≤ 1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers a, b and c (1 ≤ a ≤ 1018, 1 ≤ c < b ≤ 1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.
Output
Print the only integer — maximum number of liters of kefir, that Kolya can drink.
Sample test(s)
Input
10
11
9
8
Output
2
Input
10
5
6
1
Output
2
Note
In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir.
题目大意:有个人想要买喝的,有塑料瓶装的和玻璃瓶装的,此人有n块钱,每瓶塑料瓶装的要a块钱,每瓶玻璃瓶装的要b块钱,但是每个玻璃瓶可以返还c块钱,为这个人最多能喝多少瓶
写在前面:一看这到题,打开翻译,翻译的什么东西,硬生生读了两遍好不容易读懂。。。有点像贪心啊,话不多说,写!写完之后,很好,轻松A,一会儿,被hack了。。。于是改之,不慌。。。
题解:
先判断塑料瓶的价钱和玻璃瓶的净价钱(一瓶玻璃瓶装-返还的玻璃瓶钱)大小关系,如果塑料瓶装便宜,全买塑料瓶不解释。
否则 先狂买玻璃瓶装的 买到买不起为止 剩下的全都买塑料瓶装的 (要是一开始就买不起 那就直接买塑料瓶喽,啥都买不起喝西北风去吧)
code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long mon;
long long pl,gl,glb;
long long ans=0;
long long read()
{
long long x=0,f=1;char ch=getchar();
while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int main()
{
mon=read();pl=read();gl=read();glb=read();
long long glm=gl-glb;
if (pl<=glm) printf("%I64d\n",mon/pl);
else
{
if (mon>=gl)
ans=1+(mon-gl)/glm,mon-=ans*glm;
ans+=mon/pl;
printf("%I64d\n",ans);
}
return 0;
}
**B. War of the Corporations**
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it’s new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol’s artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol’s director decided to replace some characters in AI name with “#”. As this operation is pretty expensive, you should find the minimum number of characters to replace with “#”, such that the name of AI doesn’t contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
Input
The first line of the input contains the name of AI designed by Gogol, its length doesn’t exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn’t exceed 30. Both string are non-empty and consist of only small English letters.
Output
Print the minimum number of characters that must be replaced with “#” in order to obtain that the name of the phone doesn’t occur in the name of AI as a substring.
Sample test(s)
Input
intellect
tell
Output
1
Input
google
apple
Output
0
Input
sirisiri
sir
Output
2
Note
In the first sample AI’s name may be replaced with “int#llect”.
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be “s#ris#ri”.
题目大意:说实话,翻译我也没看懂,不过看样例发现,似乎是字符串匹配啊。给出串1串2,求串2在串1中出现的次数
写在前面:读不懂翻译,有道就是蛋疼。。。KMP裸题啊,shabi题啊,于是秒出模版,哦呵呵。。提交WA?!。。不能理解,一看数据范围,傻逼范围,暴力艹标算,1分钟暴力打完,妥A。。。(原来KMP时串1串2输反了。。)
题解:
傻逼暴力,比较S1【i】和S2【j】,如果不相等i+=len2。。。找到一个ans+1。。。shabi题不解释
code:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s1[100010],s2[100010];
int ans=0;
int l1,l2;
int main()
{
gets(s1); gets(s2);
l1=strlen(s1); l2=strlen(s2);
for (int i=0; i<=l1-l2;)
{
bool f=true;
for (int j=0; j<=l2-1; j++)
if (s1[i+j]!=s2[j]) {f=false;break;}
if (f) ans++,i+=l2;
else i++;
}
printf("%d",ans);
return 0;
}
**C. K-special Tables**
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied:
• every integer from 1 to n2 appears in the table exactly once;
• in each row numbers are situated in increasing order;
• the sum of numbers in the k-th column is maximum possible.
Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right.
Input
The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum.
Output
First print the sum of the integers in the k-th column of the required table.
Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on.
If there are multiple suitable table, you are allowed to print any.
Sample test(s)
Input
4 1
Output
28
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Input
5 3
Output
85
5 6 17 18 19
9 10 23 24 25
7 8 20 21 22
3 4 14 15 16
1 2 11 12 13
题目大意:构造一个长宽为n的矩阵,使第k列之和最大,要求1到n*n所有数都出现,且每一行从左到右要求为递增
写在前面:一开始并不太会做,于是水了水codeVS群。。。里面一个神犇说,第三题shabi题,对着样例找规律,于是开搞,于是轻松A掉了(其实交的时候很虚。——)。。。
题解:
对着样例找规律喽,没什么好说的吧。。
code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int mat[1000][1000];
int n,k;
int main()
{
while (~scanf("%d%d",&n,&k))
{
int cnt=1,ans=0;
for (int i=1; i<=n; i++)
for (int j=1; j<=k-1; j++)
mat[i][j]=cnt++;
for (int i=1; i<=n; i++)
for (int j=k; j<=n; j++)
mat[i][j]=cnt++;
for (int i=1; i<=n; i++)
ans+=mat[i][k];
printf("%d\n",ans);
for (int i=1; i<=n; i++)
{
for (int j=1; j<=n-1; j++)
printf("%d ",mat[i][j]);
printf("%d\n",mat[i][n]);
}
}
return 0;
}
**D. Finals in arithmetic**
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder.
Let’s denote a flip operation of an integer as follows: number is considered in decimal notation and then reverted. If there are any leading zeroes afterwards, they are thrown away. For example, if we flip 123 the result is the integer 321, but flipping 130 we obtain 31, and by flipping 31 we come to 13.
Oksana Fillipovna picked some number a without leading zeroes, and flipped it to get number ar. Then she summed a and ar, and told Vitya the resulting value n. His goal is to find any valid a.
As Oksana Fillipovna picked some small integers as a and ar, Vitya managed to find the answer pretty fast and became interested in finding some general algorithm to deal with this problem. Now, he wants you to write the program that for given n finds any a without leading zeroes, such that a + ar = n or determine that such a doesn’t exist.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 10100 000).
Output
If there is no such positive integer a without leading zeroes that a + ar = n then print 0. Otherwise, print any valid a. If there are many possible answers, you are allowed to pick any.
Sample test(s)
Input
4
Output
2
Input
11
Output
10
Input
5
Output
0
Input
33
Output
21
Note
In the first sample 4 = 2 + 2, a = 2 is the only possibility.
In the second sample 11 = 10 + 1, a = 10 — the only valid solution. Note, that a = 01 is incorrect, because a can’t have leading zeroes.
It’s easy to check that there is no suitable a in the third sample.
In the fourth sample 33 = 30 + 3 = 12 + 21, so there are three possibilities for a: a = 30, a = 12, a = 21. Any of these is considered to be correct answer.
没来得及A,先留着,以后来挖坟。。
**E. Frog Fights**
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Ostap Bender recently visited frog farm and was inspired to create his own frog game.
Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board is cyclic, so cell number 1 goes right after the cell number m in the direction of movement. i-th frog during its turn can jump for ai cells.
Frogs move in turns, game starts with a move by frog 1. On its turn i-th frog moves ai cells forward, knocking out all the frogs on its way. If there is a frog in the last cell of the path of the i-th frog, that frog is also knocked out. After this the value ai is decreased by the number of frogs that were knocked out during this turn. If ai is zero or goes negative, than i-th frog doesn’t make moves anymore.
After frog number 1 finishes its turn, frog number 2 starts to move, than frog number 3 and so on. After the frog number n makes its move, frog 1 starts to move again, then frog 2 and so on this process goes forever. If some frog was already knocked out from the board, we consider that it skips all its moves.
Help Ostap to identify, what frogs will stay on the board at the end of a game?
Input
First line of the input contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 109, n ≤ m) — number of frogs and gameboard size, respectively.
Following n lines contains frogs descriptions — two integers pi and ai (1 ≤ pi, ai ≤ m) — the number of cell occupied by i-th frog initially and initial jump length. All pi are guaranteed to be distinct.
Output
In the first line output number of frogs on the final gameboard. In the second line output their numbers in any order.
Sample test(s)
Input
3 5
2 1
5 3
4 3
Output
1
3
Input
5 6
1 2
3 4
2 5
5 1
6 1
Output
2
1 4
Note
In the first sample first frog jumps 1 cell and finishes in cell number 3. Second frog jumps for 3 cells and finishes on cell number 3, knocking out frog number 1. Current jump length for frog number 2 is now 2. Third frog jumps to cell 2, then second frog jumps to cell 5. Third frog in turn finishes in cell 5 and removes frog 2 from the gameboard. Now, it’s the only remaining frog in the game.
In the second sample first frog jumps 2 cells and knocks out frogs in cells 2 and 3. Its value ai is now 0. Then fourth frog jumps and knocks out fifth frog and its ai is now 0 too. These two frogs will remains on the gameboard forever.
同上。。。。说实话我还不确定能不能做的出来呢。。。
Codeforces Round #342 (Div 2) 解题报告的更多相关文章
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- Codeforces Round #380 (Div. 2) 解题报告
第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...
- Codeforces Round #216 (Div. 2)解题报告
又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<]; ,m2=; ;i ...
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- Codeforces Round #277 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- Codeforces Round #350 (Div. 2)解题报告
codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...
- Codeforces Round #479 (Div. 3)解题报告
题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...
- Codeforces Round #515 (Div. 3) 解题报告(A~E)
题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...
随机推荐
- WPF数字输入框和IP地址输入框
数字输入框 简介 在业务中,我们经常需要限制用户的输入,比如限制输入长度,限制只能输入数字等等.限制输入长度WPF内置的TextBox已经帮我们解决了,但是限制输入数字却并未在WPF中内置解决方案.使 ...
- HTTPWatch使用
注意:现在httpwatch也可以集成到火狐浏览器中. 一.介绍 HttpWatch是强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理 ...
- Facebook或成云领域黑马 冲击亚马逊
[摘要]目前,云计算领域最大的服务是亚马逊AWS,据称此服务年度营收约为100亿美元. 转播到腾讯微博 BI中文站 3月22日报道 如今,多数人认为亚马逊在云计算领域的发展势头无人可档,不过,这个市场 ...
- mobileTech
A useful tools or tips list for mobile web application developing 这个项目收集移动端开发所需要的一些资源与小技巧 工具类网站 HTML ...
- 14Mybatis_输入映射(传递pojo的包装对象)——很重要
假设我们有这么一个需求:用户信息的综合查询,需要传入的查询条件很复杂(可能包括用户信息,其他的信息,比如商品,订单) 我们的思想是:传入到select中的parameterType是一个包装类,里面可 ...
- [转]iptables详解
FROM : http://blog.chinaunix.net/uid-26495963-id-3279216.html 一:前言 防火墙,其实说白了讲,就是用于实现Linux下访问控制的功能的 ...
- JAVA中获取当前系统时间
一. 获取当前系统时间和日期并格式化输出: import java.util.Date;import java.text.SimpleDateFormat; public class NowStrin ...
- IOS开发之——登录加密也许用到的,反转字符串
- (NSString *)stringByReversed{// NSMutableString *s = [NSMutableString string];// for (NSUInt ...
- php 利用socket发送GET,POST请求
作为php程序员一定会接触http协议,也只有深入了解http协议,编程水平才会更进一步.最近我一直在学习php的关于http的编程,许多东西恍然大悟,受益匪浅.希望分享给大家.本文需要有一定http ...
- EF实体框架之CodeFirst三
前两篇博客学习了数据库映射和表映射,今天学习下数据库初始化.种子数据.EF执行sql以及执行存储过程这几个知识. 一.数据库初始化策略 数据库初始化有4种策略 策略一:数据库不存在时重新创建数据库 D ...