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\n");
        } else if(n<=1) {
            printf("Yes\n");
        } else { // n==2
            if(a[1]*a[1]-4*a[2]*a[0]<0) printf("Yes\n");
            else printf("No\n");
        }
          
    }
    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\n", 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

 真正的签到题。

 

 

 

转载于:https://www.cnblogs.com/izcat/p/11329638.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值