Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)

题目

A. Vicious Keyboard

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Tonio has a keyboard with only two letters, “V” and “K”.

One day, he has typed out a string s with only these two letters. He really likes it when the string “VK” appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times “VK” can appear as a substring (i. e. a letter “K” right after a letter “V”) in the resulting string.

Input
The first line will contain a string s consisting only of uppercase English letters “V” and “K” with length not less than 1 and not greater than 100.

Output
Output a single integer, the maximum number of times “VK” can appear as a substring of the given string after changing at most one character.

Examples
input
VK
output
1
input
VV
output
1
input
V
output
0
input
VKKKKKKKKKVVVVVVVVVK
output
3
input
KVKV
output
1

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    getline(cin,str);
    int len = str.length();
    if(len == 1)
    cout << "0" << endl;
    else
    if(len <= 3)
    {
        if(len == 2)
        {
            if(str[0] == 'K'&&str[1] == 'V')
            cout << "0" << endl;
            else
            cout << "1" << endl;
        }
        else
        cout << "1" << endl;
    }

    else
    {
        int k = 0;
        int v = 0;
        int temp = 0;
        int temp1 = 0;
        int flag = 0;
        int num = 0;
        for(int i = 0; i < len ;i++)
        {

            if(str[i] == 'V')
            {
                temp++;
                if(flag == 0)
                {
                    flag = 1;
                    temp = 0;
                }
                v = max(v,temp);

            }
            if(str[i] == 'K')
            {
                temp1++;
                if(flag == 1)
                {
                    flag = 2;
                    temp1 = 0;
                }

                k = max(k,temp1);
            }
            if(flag == 2)
            {
                num++;
                flag = 0; 
            }
        } 
        if(flag == 1)
        v++;
        if(v > 1||k > 1)
        num++;
        cout << num << endl;
    }
}

这个很可惜,没考虑到“KV”的情况,第二天fst了。
这个就是全部输入进去,判断有几个VK,一旦找到了V,如果后面不是K就计数有几个V,直到找到了K,之后再判断不是V的话有几个K,等’VK’找完了,如果重复的V或者K大于1,总数就加一。

B. Valued Keys

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.

The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1 and the i-th character of s2.

For example, f(“ab”, “ba”) = “aa”, and f(“nzwzl”, “zizez”) = “niwel”.

You found two strings x and y of the same length and consisting of only lowercase English letters. Find any string z such that f(x, z) = y, or print -1 if no such string z exists.

Input
The first line of input contains the string x.

The second line of input contains the string y.

Both x and y consist only of lowercase English letters, x and y have same length and this length is between 1 and 100.

Output
If there is no string z such that f(x, z) = y, print -1.

Otherwise, print a string z such that f(x, z) = y. If there are multiple possible answers, print any of them. The string z should be the same length as x and y and consist only of lowercase English letters.

Examples
input
ab
aa
output
ba
input
nzwzl
niwel
output
xiyez
input
ab
ba
output
-1

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    string str1;
    string str2;
    int flag = 0;
    cin >> str1 >> str2;
    int len = str1.length();
    for(int i = 0;i < len;i++)
    {
        if(str2[i] > str1[i])
        {
            cout << "-1" << endl;
            flag = 1;
            break;
        }
    }
    if(flag == 0)
    cout << str2 << endl;
}

这个只要判断第二串有没有大于第一串的字母,有的话就输出-1,没有直接输出第二串就可以。

C. Voltage Keepsake

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have n devices that you want to use simultaneously.

The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.

You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.

You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.

If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.

Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.

This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.

Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.

Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.

Namely, let’s assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .

Examples
input
2 1
2 2
2 1000
output
2.0000000000
input
1 100
1 1
output
-1
input
3 5
4 3
5 2
6 1
output
0.5000000000

#include<bits/stdc++.h>
using namespace std;
int _array[100005];
int _array1[100005];
double eps = 1e-6;
int main()
{
    double l = 0;
    double mid = 0;
    double r = 0;
    long long n = 0;
    long long Po = 0;
    cin >> n >> Po;
    for(int i = 0;i < n;i++)
    {
        cin >> _array[i] >> _array1[i];
    }
    r = 1e12;
    mid = (l+r)/2;
    while(fabs(r-l) > eps)          
    {
        double temp = 0;             
        double temp1 = 0;
        for(int i = 0;i < n;i++)     
        {
            temp = _array1[i]-mid*_array[i]; 
            if(temp < 0)              
            temp1+=temp;             
        }
        double temp2 = 0;
        temp2 = mid*Po;
        if(temp2 + temp1 >= 0)         
        {
            l = mid;
            mid = (l+r)/2;
        }
        else
        {
            r = mid;
            mid = (l+r)/2;
        }
    }
    if(mid > 1e11)
    cout << "-1" << endl;
    else
    cout << mid << endl;
}

这道题用二分时间的方法做,找到一个时间使得充电器可以支持所有设备的用电,再在这个基础上找到最大时间。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值