zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 121

    A - White Cells

    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    
    int main(){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        cout << (a - c) * (b - d) << endl;
        return 0;
    }
    

    B - Can you solve this?

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 20 + 5;
    typedef long long LL;
    int n, m, c;
    int b[N], a[N][N];
    int res = 0;
    int main() {
        cin >> n >> m >> c;
        for (int i = 0; i < m; i++) cin >> b[i];
        for (int i = 0; i < n; i++) {
            int tmp = 0;
            for (int j = 0; j < m; j++) {
                cin >> a[i][j];
                tmp += a[i][j] * b[j];
            }
            if (tmp + c > 0) res++;
        }
        cout << res << endl;
        return 0;
    }
    

    C - Energy Drink Collector

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    struct node {
        LL v, num;
    } a[N];
    bool cmp(node a, node b) { return a.v < b.v; }
    int main() {
        int n, m;
        cin >> n >> m;
        for (int i = 0; i < n; i++) cin >> a[i].v >> a[i].num;
        sort(a, a + n, cmp);
        LL res = 0;
        LL num = 0;
        for (int i = 0; i < n; i++) {
            if (num + a[i].num <= m) {
                res += a[i].v * a[i].num;
                num += a[i].num;
            }
            else{
                res += a[i].v * (m - num);
                break;
            }
        }
        cout << res << endl;
        return 0;
    }
    

    D - XOR World

    给出a和b,求出a异或到b的和

    一个偶数和比他大1的奇数异或得到1,根据此可以将计算优化到O(1)

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    LL a, b;
    int main() {
        cin >> a >> b;
        if (a == b)
            cout << b << endl;
        else {
            if (a % 2 == 0) {
                if (b % 2 == 1) {
                    if (((b - a + 1)/2) % 2 == 0) cout << 0 << endl;
                    else cout << 1 << endl;
                } else {
                    if (((b - a)/2) % 2 == 0) cout << b << endl;
                    else cout << (1ll^b) << endl;
                }
            }
            else{
                if(b%2==1){
                    if (((b - a)/2) % 2 == 0) cout << a << endl;
                    else cout << (1ll^a) << endl;
                }
                else{
                    if (((b - a - 1)/2) % 2 == 0) cout << (a^b) << endl;
                    else cout << (a^1ll^b) << endl;
                }
            }
        }
    
        return 0;
    }
    
  • 相关阅读:
    Redis 代理 twemproxy
    redis sentinel 集群监控 配置
    RabbitMQ 消息队列 配置
    codis 新版本 CodisLabs 编译安装
    CentOS7 开源跳板机(堡垒机) Jumpserver
    tomcat 优化配置 java-8 tomcat-7
    CentOS 7 安装配置 NFS
    CentOS 7 x64 安装 Ceph
    自动化运维 Ansible
    Java之数据类型讲解
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14399699.html
Copyright © 2011-2022 走看看