2020-10-30 — 补题报告

 

https://codeforces.com/problemset/problem/743/A

题意:给一个01字符串,指定两个位置,如果这两个位置的字符相等,则输出0,不相等则输出1

#include <bits/stdc++.h>

using namespace std;
const int N = 100010;

template <typename T>
inline void read(T &s) {
    s = 0;
    T w = 1, ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); }
    while (isdigit(ch))  { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
    s *= w;
}
struct node{
    int x, y;
};

bool cmp(node a, node b){
    return a.x < b.x;
}
int n, a, b;
char str[N];
int main()
{
    cin >> n >> a >> b;
    scanf("%s", str + 1);
    
    if(str[a] == str[b])
        puts("0");
    else
        puts("1");
        
} 

https://codeforces.com/problemset/problem/743/B

题意:给出数字规模和规律,找出第k个数是多少。

可以递归着做,有点像是二分,比赛的时候忘记开long long 了...

#include <bits/stdc++.h>

using namespace std;
const int N = 100010;
typedef long long ll;
template <typename T>

inline void read(T &s) {
    s = 0;
    T w = 1, ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); }
    while (isdigit(ch))  { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
    s *= w;
}
struct node{
    int x, y;
};

bool cmp(node a, node b){
    return a.x < b.x;
}
ll n, k, sum = 0, res = 0;
ll f(int n){
    if(n == 0) return 2 * n + 1;
    return 2 * f(n - 1) + 1;
}

ll solve(ll k){
    
    if(k == (sum + 1) / 2){
        return n;
    }
    
    n --;
    sum /= 2;
    
    if(k > sum + 1){
        k -= (sum + 1);
    }
    
    return solve(k);
}

int main()
{
    cin >> n >> k;
    sum = f(n - 1);    
    res = solve(k);
    cout << res << endl;
}

https://codeforces.com/problemset/problem/743/C

题意 : 找出三个数 满足 2 / x = 1 / a   +  1 / b  +  1 / c;

构造 假设 x = n,  a = n + 1, b = n * (n + 1), c = n

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    n == 1 ? puts("-1") : printf("%d %d %d\n", n + 1, n * (n + 1), n);
    
}

 

posted @ 2020-11-08 13:32  IIlIlIlI  阅读(89)  评论(0编辑  收藏  举报