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

    A - Happy Birthday!

    大意:

    一个蛋糕分为16份,A和B各自需要拿a和b份,问能否使得每个人拿到的蛋糕都是不连续的:

    思路:

    先把较少的蛋糕数一一对应相隔,然后判断剩下的能否隔一个取一个即可

    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int a, b;
    int main(){
        cin >> a >> b;
        if (a < b) swap(a, b);
        if (2 * (a - b) > (16 - 2 * b)) cout << ":(" << endl;
        else
            cout << "Yay!" << endl;
        return 0;
    }
    

    B - Ringo's Favorite Numbers

    大意:

    给出两个数d和n,要求输出第n个能被100整除d次的数(注意必须是d次,d+1次也不行)

    思路:

    两个数之间的间隔至少是pow(100,d),在此基础上,枚举一下判断即可

    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int n, d;
    int get(int num){
        int sum = 0;
        while (num){
            if (num % 100 == 0) sum++;
            num /= 100;
        }
        return sum;
    }
    int main(){
        cin >> d >> n;
        int base = pow(100, d);
        int res=0;
        while(n){
            res += base;
            if(get(res)==d){
                n--;
            }
        }
        cout << res << endl;
        return 0;
    }
    

    C - *3 or /2

    大意:

    给出n个数,每次操作需要将这n个数中,一部分乘3,一部分除以2,但是不能全部乘3,每次操作得到的数必须是整数

    问最多能操作多少次

    思路:

    计算这n个数一共能被2整除多少次即可

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int n, x;
    int get(int num){
        int sum = 0;
        while(num){
            if(num%2==0){
                sum++;
                num /= 2;
            }
            else
                break;
        }
        return sum;
    }
    int main() {
        cin >> n;
        int res = 0;
        for (int i = 0; i < n; i++) {
            cin >> x;
            res += get(x);
        }
        cout << res << endl;
        return 0;
    }
    

    D - Patisserie ABC

    大意:

    n个蛋糕,都有三个属性值xyz,现在需要取出m个蛋糕,使得x的和的绝对值+y的和的绝对值+z的和的绝对值

    思路:

    因为xyz各自的和要么是正要么是负,那么每个对于每个标号,每个蛋糕都会产生相应的贡献

    例如,最后的x的和的绝对值是正,y是负,z是负,那么对于一个x为正,y为正,z为正的蛋糕,它的贡献就是x-y-z

    所以可以枚举8种情况,每次都排序一下,取前m个数,然后更新最大值即可

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int n, m;
    struct node {
        LL x, y, z;
    } a[N];
    int f1, f2, f3;
    bool cmp(node a, node b) {
        return ((LL)f1 * a.x + (LL)f2 * a.y + (LL)f3 * a.z >
                (LL)f1 * b.x + (LL)f2 * b.y + (LL)f3 * b.z);
    }
    int main() {
        cin >> n >> m;
        for (int i = 0; i < n; i++) {
            cin >> a[i].x >> a[i].y >> a[i].z;
        }
        LL res = 0;
        for (f1 = -1; f1 <= 1; f1 += 2) {
            for (f2 = -1; f2 <= 1; f2 += 2) {
                for (f3 = -1; f3 <= 1; f3 += 2) {
                    sort(a, a + n, cmp);
                    LL tmp = 0;
                    for (int i = 0; i < m; i++) {
                        tmp += (LL)f1 * a[i].x + (LL)f2 * a[i].y + (LL)f3 * a[i].z;
                    }
                    res = max(res, tmp);
                }
                
            }
        }
        cout << res << endl;
        return 0;
    }
    
  • 相关阅读:
    python 基础到字符串学习
    Newtonsoft.Json 获取匿名类数据
    Abp Wcf结合使用问题
    Ef Migration 操作出现SQLEXPRESS
    No context type was found in the assembly 'xxx.xxxx'. CodeFirst Ef错误
    Ef Code First 发生”provider: SQL Network Interfaces, error: 26
    ef 多条数据插入处理方案(据说还有更好的)
    记录一次 HttpWebRequest 尝试自动重定向太多 错误
    NetCore 下使用RSA加密,解密;并且前端使用jsencrypt.js实现Rsa相关方法。
    The specified framework version '2.0' could not be parsed 错误处理
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14355492.html
Copyright © 2011-2022 走看看