10-09訓練賽week3-C3

精神小夥mqpm發表於2020-10-09

A - Donut Shops CodeForces - 1373A

There are two rival donut shops.
The first shop sells donuts at retail: each donut costs a dollars.
The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.
You want to determine two positive integer values:
how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn’t exist then that value should be equal to −1. If there are multiple possible answers, then print any of them.
The printed values should be less or equal to 109. It can be shown that under the given constraints such values always exist if any values exist at all.
Input
The first line contains a single integer t (1≤t≤1000) — the number of testcases.
Each of the next t lines contains three integers a, b and c (1≤a≤109, 2≤b≤109, 1≤c≤109).
Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 109.
If there is no such x, then print −1. If there are multiple answers, then print any of them.

題意思路: 讀懂英語即可
程式碼:

#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<string>


#define LL long long
using namespace std;
#define MAXN 111
#define inf 100000001
#define sd1(i) scanf("%d", &i)
#define sl1(i) scanf("%lld", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
#define For(i, j, n) for(int i = j; i < n; i++)
#define For_(i, j, n) for(int i = j; i > n; i--)
#define inf 0x3f3f3f3f

int T;
LL a, b, c;

void solve(){
    sd3(a, b, c);
    if(a < c) cout << 1  << ' ';
    else cout << -1  << ' ';
    if(a*b > c) cout << b << endl;
    else cout << -1 << endl;
}
int main(){
    cin >> T;
    while(T--){
        solve();
    }
    //system("pause");
    return 0;
}

B - 01 Game CodeForces - 1373B

Alica and Bob are playing a game.
Initially they have a binary string s consisting of only characters 0 and 1.
Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent characters of string s and delete them. For example, if s=1011001 then the following moves are possible:
delete s1 and s2: 1011001→11001;
delete s2 and s3: 1011001→11001;
delete s4 and s5: 1011001→10101;
delete s6 and s7: 1011001→10110.
If a player can’t make any move, they lose. Both players play optimally. You have to determine if Alice can win.
Input
First line contains one integer t (1≤t≤1000) — the number of test cases.
Only line of each test case contains one string s (1≤|s|≤100), consisting of only characters 0 and 1.
Output
For each test case print answer in the single line.
If Alice can win print DA (YES in Russian) in any register. Otherwise print NET (NO in Russian) in any register.

題意 : 倆個人博弈,每次選字串中相鄰的不同的兩個字元刪除,到誰刪不了了他就輸了
思路: 判斷一下0和1的數目即可 取其中小的 判斷是否可以對二整除
程式碼:

#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<string>


#define LL long long
using namespace std;
#define MAXN 111
#define inf 100000001
#define sd1(i) scanf("%d", &i)
#define sl1(i) scanf("%lld", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
#define For(i, j, n) for(int i = j; i < n; i++)
#define For_(i, j, n) for(int i = j; i > n; i--)
#define inf 0x3f3f3f3f

int T;
string s;
int a, b;
void solve(){
    cin >> s;
    a = 0;
    b = 0;
    for(int i =0 ;i < s.size(); i++){
        if(s[i] == '1') b++;
        else a++;
    }
    int ans = min(a, b);
    if(ans % 2 == 0) cout << "NET" << endl;
    else cout << "DA" << endl;
}
int main(){
    cin >> T;
    while(T--){
        solve();
    }
    //system("pause");
    return 0;
}

C - Pluses and Minuses CodeForces - 1373C

You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode:

res = 0
for init = 0 to inf
    cur = init
    ok = true
    for i = 1 to |s|
        res = res + 1
        if s[i] == '+'
            cur = cur + 1
        else
            cur = cur - 1
        if cur < 0
            ok = false
            break
    if ok
        break

Note that the inf denotes infinity, and the characters of the string are numbered from 1 to |s|.
You have to calculate the value of the res after the process ends.
Input
The first line contains one integer t (1≤t≤1000) — the number of test cases.
The only lines of each test case contains string s (1≤|s|≤106) consisting only of characters + and -.
It’s guaranteed that sum of |s| over all test cases doesn’t exceed 106.
Output
For each test case print one integer — the value of the res after the process ends.

題意 : 按題中程式碼求值 若按題幹中程式碼求則一定會TLE
思路: 由程式碼可看出:就是判斷一下加上的init能不能中和‘-’,遍歷字串根據‘+’,‘-’更新最小值,若可以更新 sum加上i,最後加上字串長度
程式碼:

#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<string>


#define LL long long
using namespace std;
#define MAXN 111
#define inf 100000001
#define sd1(i) scanf("%d", &i)
#define sl1(i) scanf("%lld", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
#define For(i, j, n) for(int i = j; i < n; i++)
#define For_(i, j, n) for(int i = j; i > n; i--)
//#define inf 0x3f3f3f3f

int T;
string s;
void solve(){
    cin >> s;
    LL ans = 0;
    LL sum = 0;
    LL minn = 0;
    for(int i =0 ; i < s.size(); i++){
        if(s[i] == '+') {
            ans ++;
        }
        else {
            ans --;
        }
        //minn = min(minn, ans);
        if(minn > ans) {
            sum += (i+1);
            minn = min(ans, minn);
        }
        if(i == s.size() - 1) sum += s.size();
    }
    cout << sum << endl;
/
    /*LL res = 0;
    int cur;
    bool ok;
    for (int init = 0 ; init <= 10000; init++){
        //cout << "init" << init << endl;
        cur = init;
        ok = true;
        for (int i = 1 ;i <= s.size(); i++){
            res = res + 1;
            if (s[i-1] == '+')
                cur = cur + 1;
            else
                cur = cur - 1;
            if (cur < 0){
                ok = false;
                break;
            }
        }
        if (ok)
            break;
    }

    cout << res << endl;*/
}
int main(){
    cin >> T;
    while(T--){
        solve();
    }
    //system("pause");
    return 0;
}

相關文章