除夕夜之有生之年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) 解题报告的更多相关文章

  1. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  2. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  3. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

  4. Codeforces Round #216 (Div. 2)解题报告

    又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<];    ,m2=;    ;i ...

  5. Codeforces Round #281 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...

  6. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  7. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  8. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  9. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

  10. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

随机推荐

  1. nginx 与 tomcat 集群 一二事 (0) - 简单介绍

    最近看了nginx以及tomcat的集群,通俗的做一下简单总结吧 nginx 是一个http服务器,是由俄罗斯人发明的,目前主流的服务器,作为负载均衡服务器,性能非常好,最高支持5万个并发连接数,在淘 ...

  2. 第11章 Windows线程池(3)_私有的线程池

    11.3 私有的线程池 11.3.1 创建和销毁私有的线程池 (1)进程默认线程池 当调用CreateThreadpoolwork.CreateThreadpoolTimer.CreateThread ...

  3. mac在xampp下使用yii2.0开发环境配置

    在mac上装环境,折腾了我好久.先用是mac自带的php,但自带的PHP很多扩展都需要自己安装.libevent,memcache等扩展都安装好了之后,发现pdo_mysql.dll扩展又没有,悲剧的 ...

  4. java 15-2 Collection的高级功能测试

    A:  boolean addAll(Collection c):添加一个集合的元素 ,所有的元素,无论是否重复 B:  boolean removeAll(Collection c):移除一个集合的 ...

  5. java13-5 JDK1.5以后的一个新特性和Integer的面试题

    1.JDK5的新特性 自动装箱:把基本类型转换为包装类类型 自动拆箱:把包装类类型转换为基本类型 注意一个小问题: 在使用时,Integer x = null;代码就会出现NullPointerExc ...

  6. 【ArcGIS二次开发】CreateFeature报错(HRESULT E_FAIL)

    在VS2010下基于ArcGIS 10.1做二次开发时遇到个奇怪的问题,对于MXD工程文档中已经存在的图层,获取其FeatureClass可以调用CreateFeature()函数生成要素,但是对于通 ...

  7. windows客户机连接gerrit的一个报错处理

    gerrit环境部署在linux服务器,windos客户机连接gerrit进行代码操作: 在windows客户机下载Git客户端 在“Git Bash”里使用 ”ssh-keygen -t rsa - ...

  8. 理解SQL Server中的权限体系(上)----主体

    原文:http://www.cnblogs.com/CareySon/archive/2012/04/10/mssql-security-principal.html 简介 权限两个字,一个权力,一个 ...

  9. 使用lftp传输文件的shell脚本

    学习参考用,需要服务器上安装lftp. #!/bin/bash #date filepath=/usr/hadoop/bigdata/filterurl filtercount=$(ls $filep ...

  10. Sql复习之安全性与权限管理+vmware增加硬盘容量

    参考资料: http://www.cnblogs.com/Jackeyzhang/archive/2011/05/18/2049621.html VmWare虚拟机增加硬盘容量的方法 http://b ...