2021寒假训练(二)

题号 A B C D E F G H
AC          

 

 

 

A.Two Arrays And Swaps

#include <string.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ll long long
#define int long long
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const int Base = 131;
const ll INF = 1ll << 62;
// const double PI = acos(-1);
const double eps = 1e-7;
const int mod = 1e9 + 7;
#define PI acos(-1)
#define mem(a, b) memset(a, b, sizeof(a))
#define speed                        \
    {                                \
        ios::sync_with_stdio(false); \
        cin.tie(0);                  \
        cout.tie(0);                 \
    }
#define wait  \
    while (1) \
    {         \
    }
#define debug cout << "********" << endl;

// inline int gcd(int a, int b) {
//     while (b ^= a ^= b ^= a %= b);
//     return a;
// }

inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

long long fastPower(long long base, long long power)
{
    long long result = 1;
    while (power > 0)
    {
        if (power & 1)
            result = result * base % mod;
        power >>= 1;
        base = (base * base) % mod;
    }
    return result;
}

inline ll rd()
{
    ll s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

// freopen("C:/Users/ASUS/Desktop/Struct/in.txt", "r", stdin);
// //输入重定向,输入数据将从in.txt文件中读取
// freopen("C:/Users/ASUS/Desktop/Struct/out.txt", "w", stdout);
// //输出重定向,输出数据将保存out.txt文件中 fclose(stdin);//关闭重定向输入
// fclose(stdout);//关闭重定向输出

signed main(){

    int T = rd();
    while(T--){
        int n = rd();
        int k = rd();
        int a[50],b[50];
        for(int i=0;i<n;i++)a[i]=rd();
        for(int i=0;i<n;i++)b[i]=rd();
        sort(a,a+n);
        sort(b,b+n,greater<int>());
        for(int i=0;i<n && i<k;i++){
            if(b[i]>=a[i])a[i]=b[i];
            else break;
        }
        int sum=0;
        for(int i=0;i<n;i++)
            sum+=a[i];
        printf("%lld\n",sum);
    }

    //system("pause");
    return 0;
}
View Code

B.Array Cancellation

#include <string.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ll long long
#define int long long
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const int Base = 131;
const ll INF = 1ll << 62;
// const double PI = acos(-1);
const double eps = 1e-7;
const int mod = 1e9 + 7;
#define PI acos(-1)
#define mem(a, b) memset(a, b, sizeof(a))
#define speed                        \
    {                                \
        ios::sync_with_stdio(false); \
        cin.tie(0);                  \
        cout.tie(0);                 \
    }
#define wait  \
    while (1) \
    {         \
    }
#define debug cout << "********" << endl;

// inline int gcd(int a, int b) {
//     while (b ^= a ^= b ^= a %= b);
//     return a;
// }

inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

long long fastPower(long long base, long long power)
{
    long long result = 1;
    while (power > 0)
    {
        if (power & 1)
            result = result * base % mod;
        power >>= 1;
        base = (base * base) % mod;
    }
    return result;
}

inline ll rd()
{
    ll s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

// freopen("C:/Users/ASUS/Desktop/Struct/in.txt", "r", stdin);
// //输入重定向,输入数据将从in.txt文件中读取
// freopen("C:/Users/ASUS/Desktop/Struct/out.txt", "w", stdout);
// //输出重定向,输出数据将保存out.txt文件中 fclose(stdin);//关闭重定向输入
// fclose(stdout);//关闭重定向输出

signed main(){

    int T = rd();
    while(T--){
        int n = rd();
        int res = 0;
        for(int i=0;i<n;i++){
            int m = rd();
            if(m>=0)res+=m;
            else{
                if(res>=abs(m)){
                    res+=m;
                }else{
                    res=0;
                }
            }
        }
        printf("%lld\n",res);
    }

    //system("pause");
    return 0;
}
View Code

E.Gifts Fixing

#include <string.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ll long long
#define int long long
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const int Base = 131;
const ll INF = 1ll << 62;
// const double PI = acos(-1);
const double eps = 1e-7;
const int mod = 1e9 + 7;
#define PI acos(-1)
#define mem(a, b) memset(a, b, sizeof(a))
#define speed                        \
    {                                \
        ios::sync_with_stdio(false); \
        cin.tie(0);                  \
        cout.tie(0);                 \
    }
#define wait  \
    while (1) \
    {         \
    }
#define debug cout << "********" << endl;

// inline int gcd(int a, int b) {
//     while (b ^= a ^= b ^= a %= b);
//     return a;
// }

inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

long long fastPower(long long base, long long power)
{
    long long result = 1;
    while (power > 0)
    {
        if (power & 1)
            result = result * base % mod;
        power >>= 1;
        base = (base * base) % mod;
    }
    return result;
}

inline ll rd()
{
    ll s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        s = s * 10 + ch - '0', ch = getchar();
    return s * w;
}

// freopen("C:/Users/ASUS/Desktop/Struct/in.txt", "r", stdin);
// //输入重定向,输入数据将从in.txt文件中读取
// freopen("C:/Users/ASUS/Desktop/Struct/out.txt", "w", stdout);
// //输出重定向,输出数据将保存out.txt文件中 fclose(stdin);//关闭重定向输入
// fclose(stdout);//关闭重定向输出

signed main(){

    int T = rd();
    while(T--){
        int n = rd();
        int a[60],b[60];
        int mina = inf, minb = inf;
        for(int i=0;i<n;i++)a[i]=rd(),mina = a[i] < mina ? a[i] : mina;
        for(int i=0;i<n;i++)b[i]=rd(),minb = b[i] < minb ? b[i] : minb;
        
        int x[60],y[60],res=0;
        for(int i=0;i<n;i++){
            x[i]=a[i]-mina;
            y[i]=b[i]-minb;
            res+=max(x[i],y[i]);
        }
        printf("%lld\n",res);
    }

    //system("pause");
    return 0;
}
View Code

 

posted @ 2021-01-22 12:58  濡苏  阅读(40)  评论(0)    收藏  举报