10-09训练赛week3-C3

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值