LOADING

加载过慢请开启缓存 浏览器默认开启

牛客暑期多校训练营10

2023/8/19 思维 模拟

更新至K,M…
robocom只做了个签到,烂!开摆!

题K

题意:没看懂, 给定 $n, m(1\le n,m \le 20)$

解:直接求 $(2/n)^m$

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int main(){
    int n, m; cin >> n >> m;
    double x = 2.0 / n, ans = 1;
    if(n != 1) 
        for(int i = 1; i <= m; ++ i) ans *= x;

    printf("%.15lf", ans);
}

题M

题意:给定一个式子 $a+b=c$,不知道这个式子是否成立,问是否能插入一个 $digit$ 使得等式成立。

解:因为 $1\le a,b,c \le 1e6$, 每个数模拟插入 $0-9$。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int get(string s){
    int ans = 0;
    for(int i = 0; i < s.size(); ++ i){
        int x = s[i] - '0';
        ans = ans * 10 + x;
    }
    return ans;
}
int main(){
    string a, b, c, x1, x2; cin >> a >> x1 >> b >> x2 >> c;
    int aa = get(a), bb = get(b), cc = get(c);
    for(int i = 0; i <= a.size(); ++ i){
        for(char j = '0'; j <= '9'; ++ j){
            string s = a.substr(0, i) + j + a.substr(i);
            int k = get(s);
            if(k + bb == cc){
                cout << "Yes\n" << k << " + " << bb << " = " << cc << '\n';
                return 0;
            }
        }
    }
    for(int i = 0; i <= b.size(); ++ i){
        for(char j = '0'; j <= '9'; ++ j){
            string s = b.substr(0, i) + j + b.substr(i);
            int k = get(s);
            if(k + aa == cc){
                cout << "Yes\n" << aa << " + " << k << " = " << cc << '\n';
                return 0;
            }
        }
    }
    for(int i = 0; i <= c.size(); ++ i){
        for(char j = '0'; j <= '9'; ++ j){
            string s = c.substr(0, i) + j + c.substr(i);
            int k = get(s);
            if(aa + bb == k){
                cout << "Yes\n" << aa << " + " << bb << " = " << k << '\n';
                return 0;
            }
        }
    }
    cout << "No";
}