Codeforces Round #342 (Div. 2) 总结

123 篇文章 0 订阅
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元

问你最多喝多少瓶

题解:

1.首先我们可以全部都用a买

2.全部都用b买,卖完再退回去,剩下的钱让a买

没了,就这两种情况,判断一下哪边大就好了

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL __int64
int main()
{
    LL n,a,b,c;
    while(scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c)!=EOF)
    {
        LL sum=0;
        if(n>=b&&a>=(b-c))
        {
            sum+=(n-b)/(b-c)+1;
            n-=sum*(b-c);
        }
        sum+=n/a;
        printf("%I64d\n",sum);
    }
    return 0;
}</span>

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".

题意

给你s1 s2,你每次操作可以使得s1串中某个字符变成#,然后问你最小修改多少次,就可以使得s1中不含有s2子串

题解:

贪心,我们每次修改最后一个字符就好了

这样相交的一定都被修改了

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    string s1,s2;
    while(cin>>s1>>s2)
    {
        int sum=0;
        for(int i=0;i<s1.size();i++)
        {
            int j;
            int ok=1;
            for(j=0;j<s2.size();j++)
            {
                if(s1[i+j]!=s2[j])
                {
                    ok=0;
                    break;
                }
            }
            if(ok)
            {
                s1[i+j-1]='#';
                sum++;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}</span>

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的矩阵,然后使得这个矩阵的第k列的和尽量大

并且这个矩阵每一行都是递增的

题解:

构造题,小于k列的,我们从小到大放就好了,大于等于k列的,我们倒着放,从最后一个位置,最后一个数开始放,然后放放放就好了

<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=5e2+10;
int a[maxm][maxm];
int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        int cnt=1;
        for(int i=n-1;i>=0;i--)
        {
            for(int j=0;j<k-1;j++)
            {
                a[i][j]=cnt++;
            }
        }
        int sum=0;
        for(int i=n-1;i>=0;i--)
        {
            for(int j=k-1;j<n;j++)
            {
                a[i][j]=cnt++;
                if(j==k-1)
                {
                    sum+=a[i][j];
                }
            }
        }
        printf("%d\n",sum);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(j==0)
                    printf("%d",a[i][j]);
                else
                    printf(" %d",a[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}</span>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值