Codeforces Round #483 (Div. 2)

标签: codeforces


A.Game

code ```cpp #include #include #include #include #include using namespace std; typedef long long ll; const int maxn=1000050; const int MOD=1e9+7; int a[maxn]; int main(int argc, char const *argv[]) { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", a+i); } sort(a,a+n); printf("%d\n", a[(n-1)/2]); return 0; } ```

B.Minesweeper

code ```cpp #include #include #include #include #include using namespace std; const int maxn=100050; const int MOD=1e9+7; char a[150][150]; int n,m; int dx[]={0,0,1,1,1,-1,-1,-1}; int dy[]={1,-1,-1,1,0,0,1,-1}; int f(int x,int y){ int ans=0; for (int i = 0; i < 8; ++i) { int nx=x+dx[i]; int ny=y+dy[i]; if(nx>=0&&nx=0&&ny='1'&&a[i][j]<='8'&&a[i][j]-'0'!=f(i,j)) ans=false; if(a[i][j]=='.'&&f(i,j)!=0) ans=false; } } printf("%s\n", ans?"Yes":"No"); return 0; } ```

C.Finite or not?

  问\(\frac{p}{q}\)\(b\)进制下能否表示为有限小数。如果可以表示为有限小数的话,我们一定可以通过把这个小数的小数点左移若干位使之成为正整数,也就是乘以若干个\(b\)之后变成正整数。那么我们至少需要给\(p\)乘以多少个\(b\)呢,因为\(q\)中质因子的最大次幂不超过\(64\),所以只要\(p \times b^{64}\)能整除\(q\)即可。

code ```cpp #include #include #include #include #include using namespace std; const int maxn=300050; typedef long long ll; ll qmul(ll x,ll y,ll MOD){ x%=MOD,y%=MOD; ll ans=(x*y-(ll)((long double)x/MOD*y+1e-3)*MOD); ans=(ans%MOD+MOD)%MOD; return ans; } ll Pow(ll x,ll n,ll MOD){ ll ans=1,base=x; while(n){ if(n&1) ans=qmul(ans,base,MOD); base=qmul(base,base,MOD); n>>=1; } return ans; } int main(int argc, char const *argv[]) { int q; scanf("%d", &q); while(q--){ ll p,q,b; scanf("%lld%lld%lld", &p,&q,&b); ll a=Pow(b,64,q); ll ans=qmul(p,a,q); printf("%s\n", ans==0?"Finite":"Infinite"); } return 0; } ```

D.XOR-pyramid

\(n\)个相同元素\(x\)的亦或记为\(x^n\).
找规律可以发现\[f(a_1,a_2,a_3)=a_1 a_2^2 a_3\]
\[f(a_2,a_3,a_4)=a_2 a_3^2 a_4\]
\[f(a_1,a_2,a_3,a_4)=a_1a_2^3a_3^3a4\]
可以发现其实是一个杨辉三角,进而得出
\[f(a_l,a_{l+1}......,a_{r-1},a_r)=f(a_{l+1},a_{l+2}......,a_{r-1},a_r)\oplus f(a_l,a_{l+1}......,a_{r-2},a_{r-1})\]
code

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=100050;
const int MOD=1e9+7;
typedef long long ll;
int a[5050],n;
int f[5050][5050];
int dp[5050][5050];
int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d", a+i);
    }
    for (int len = 1; len <= n; ++len)
    {
        for (int i = 1; i+len-1 <= n; ++i)
        {
            int j=i+len-1;
            if(len==1) f[i][j]=a[i],dp[i][j]=a[i];
            else f[i][j]=f[i][j-1]^f[i+1][j],dp[i][j]=max(f[i][j],max(dp[i][j-1],dp[i+1][j]));
        }
    }
    int q;
    scanf("%d", &q);
    while(q--){
        int l,r;
        scanf("%d%d", &l,&r);
        printf("%d\n", dp[l][r]);
    }
    return 0;
}

E.Elevator

留坑

转载于:https://www.cnblogs.com/sciorz/p/9046286.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值