Codeforces Round #342 (Div. 2) [Codeforces625]

此处有目录↑

Codeforces Round #342 (Div. 2):http://codeforces.com/contest/625

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 ab and c (1 ≤ a ≤ 10181 ≤ 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<=b-c,则全部买塑料瓶装;

②若n<b,则只能买塑料瓶装;

③若b>n&&a>b-c,则剩余钱>=b时,买玻璃瓶装,并卖出,最后剩余钱买塑料瓶装

刚开始没判断n<b,找了半天错,不过这个pretest还挺强

#include <cstdio>

using namespace std;

long long n,a,b,c;

int main() {
    scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
    if(a<=b-c||n<b)
        printf("%I64d\n",n/a);
    else
        printf("%I64d\n",(n-b)/(b-c)+1+((n-b)%(b-c)+c)/a);
    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不是串1的子串,求替换字符的最少数目

大致思路:一个匹配成功的子串要替换一个字符,贪心将这个子串的最后一个字符替换,其影响的范围最大

#include <cstdio>
#include <cstring>

using namespace std;

char a[100005],b[35];

int solve() {
    int ans=0,i,j,al=strlen(a),bl=strlen(b);
    for(int sta=0;sta<al;) {
        for(i=sta,j=0;j<bl&&i<al;++j,++i) {
            if(a[i]!=b[j])
                break;
        }
        if(j==bl) {
            ++ans;
            sta=i;
        }
        else
            ++sta;
    }
    return ans;
}

int main() {
    scanf("%s%s",a,b);
    printf("%d\n",solve());
    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*n的表中填入1~n^2,求满足①1~n^2出现且仅出现一次;②每行数字递增;③第k列的和最大。输出第k列的和以及这个表

大致思路:贪心。前n*(k-1)个数只能填在第k列左边,否则第k列的某一行一定为1~n*(k-1)其中一个。

k~n列开始填入n*(k-1)+1~n^2。最大能填在第k列的是n^2-n+1,其后的数按大小填入该行,剩余行同理

#include <cstdio>
#include <cstring>

using namespace std;

int n,k,num[505][505],i,j;

int solve() {
    int cur=0,i,j,sum=0;
    for(i=1;i<=n;++i)
        for(j=1;j<k;++j)
            num[i][j]=++cur;
    for(i=1;i<=n;++i) {
        for(j=k;j<=n;++j)
            num[i][j]=++cur;
        sum+=num[i][k];
    }
    return sum;
}

int main() {
    scanf("%d%d",&n,&k);
    printf("%d\n",solve());
    for(i=1;i<=n;++i) {
        for(j=1;j<n;++j)
            printf("%d ",num[i][j]);
        printf("%d\n",num[i][j]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值