https://codeforces.com/contest/1530
AB题AC了
A - Binary Decimal
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int t, n; 
int a[N];
int main(){
    cin >> t;
    while(t--){
        cin >> n;
        if(n < 10){
            cout << n << endl;
            continue; 
        }
        int res = 0;
        while(n){
            res = max(res, n % 10);
            n /= 10;
        }
        printf("%d\n", res);
    }
    return 0;
}
B - Putting Plates
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 30;
int t, h, w; 
int a[N][N];
int main(){
    cin >> t;
    while(t--){
        cin >> h >> w;    
        memset(a, 0, sizeof(a));
        for(int i = 1; i <= h; i++){
            if(i == 1 || i == h){
                for(int j = 1; j <= w; j++){
                    if(j % 2 == 1) a[i][j] = 1;
                }
            }
            else if(i != h - 1 && i % 2 == 1){
                a[i][1] = 1;
                a[i][w] = 1;
            }
        }
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                printf("%d", a[i][j]);
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}C - Pursuit
有个地方没想清楚
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int t, n; 
int a[N], b[N];
bool cmp(int a, int b){
    return a > b;
}
int main(){
    cin >> t;
    while(t--){
        cin >> n;    
        int k = n - n / 4;
        memset(a, 0, sizeof(a));
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        for(int i = 0; i < n; i++){
            cin >> b[i];
        }
        sort(a, a + n, cmp);
        sort(b, b + n, cmp);
        int suma = 0, sumb = 0;
        for(int i = 0; i < k; i++){
            suma += a[i];
            sumb += b[i];
        }
        if(suma >= sumb){
            printf("%d\n", 0);
        }else if(n == 1){
            printf("%d\n", 1);
        }
        else{
            int x = 1;
            while(suma < sumb){
                //printf("orl suma = %d sumb = %d k = %d\n", suma, sumb, k);
                //int newk = (n + x) - (n + x) / 4;
                int detak = x - x / 4;
                suma += x * 100;
                //if(k < )
                //printf("suma = %d detak = %d tmp = %d\n", suma, detak, x - detak);
                int tmp = x - detak;
                while(tmp--){
                    suma -= a[k--];
                }
                //printf("new suma = %d\n", suma);
                x++;
            }
            printf("%d\n", x);
        }
    }
    return 0;
}
一个ac的代码
    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int t;
        cin>>t;
        while(t--){
            int n;cin>>n;
            int a[n],b[n];
            for(int i=0;i<n;i++)cin>>a[i];
            for(int i=0;i<n;i++)cin>>b[i];
            sort(a,a+n);
            sort(b,b+n);
            if(n>1)for(int i=n-2;i>=0;i--){a[i]+=a[i+1];b[i]+=b[i+1];}
            for(int k=0;k<1e7;k++){
                int z = 3*(n+k);
                z = (z%4==0) ? z/4 : (z/4 +1);
                int y = (z>n) ? b[0] : b[n-z];
                if(100*k + a[n-z+k] >= y){cout<<k<<"\n";break;}
            }
        }
        return 0;
    }
 京公网安备 11010502036488号
京公网安备 11010502036488号