zoukankan      html  css  js  c++  java
  • 2019牛客暑期多校训练营(第七场)

    A - String

     T<=300, n<=200,采用O(n^3)居然能过,题解也是暴力。。。

    B - Irreducible Polynomial

     题解:签到题

     结论:所有 n 大于 2 的多项式在实数域上都是可分解的。

     所以本题只需要特判 n==2 时的 delta,判断 P(n)=0 是否有解即可。

    #include<iostream>
    #include<cstdio>
    using namespace std;
    typedef long long ll;
    ll a[25];
    int n;
     
    int main() {
        int t; cin>>t;
        while(t--) {
            scanf("%d", &n);
            for(int i=n;i>=0;i--) {
                scanf("%lld", &a[i]);
            }
            if(n>2) {
                printf("No
    ");
            } else if(n<=1) {
                printf("Yes
    ");
            } else { // n==2
                if(a[1]*a[1]-4*a[2]*a[0]<0) printf("Yes
    ");
                else printf("No
    ");
            }
              
        }
        return 0;
    }
    View Code

    C - Governing sand

    D - Number

     签到题。

     位数大于 p 的位数时,后面补 0 即可。小于则不存在,等于输出 p 。

    E - Find the median

     (待补。)

    H - Pair

     数位dp,按照二进制位搜索不满足两种条件的情况,A*B - ans 再加回 A=0 和 B=0 多减掉的部分。

    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<cstring>
    using namespace std;
     
    typedef long long ll;
     
    ll A, B, C;
    ll dp[33][2][2][2][2];
     
    ll dfs(int pos, int la, int lb, int And, int Xor) {
        if(pos<0) return 1;
        if(dp[pos][la][lb][And][Xor]!=-1) return dp[pos][la][lb][And][Xor];
     
        ll res = 0;
        int ua = la?(A>>pos)&1:1;
        int ub = lb?(B>>pos)&1:1;
     
        int nand = And?(C>>pos)&1:1;
        int nxor = Xor?(C>>pos)&1:0;  // 当前位结果
    
        for(int i=0;i<=ua;i++) {
            for(int j=0;j<=ub;j++) {
                if((i&j)>nand) continue;
                if((i^j)<nxor) continue;
     
                res += dfs(pos-1, la&&(i==ua), lb&&(j==ub), And&&((i&j)==nand), Xor&&((i^j)==nxor));
            }
        }
        return dp[pos][la][lb][And][Xor] = res;
    }
     
    int main() {
        int t; cin>>t;
        while(t--) {
            scanf("%lld %lld %lld", &A, &B, &C);
            memset(dp, -1, sizeof(dp));
     
            printf("%lld
    ", 1LL*A*B-dfs(32, 1, 1, 1, 1)+max(0LL, A-C+1)+max(0LL, B-C+1));
     
        }
        return 0;
    }
    View Code

    J - A+B problem

     真正的签到题。

     

  • 相关阅读:
    Java基础语法与变量初步学习
    Java基本数据类型转换
    Java变量常量与基本数据类型
    Java进制转换
    Java 开发环境配置
    Java运算符
    STL—vector删除重复元素
    子窗口和父窗口重绘
    怎么判断文件是否被占用
    多线程的理解
  • 原文地址:https://www.cnblogs.com/izcat/p/11329638.html
Copyright © 2011-2022 走看看