zoukankan      html  css  js  c++  java
  • Codeforces Round #604(Div. 2,

    // https://codeforces.com/contest/1265/problem/D
    /*
    感觉像是遍历的思维构造题 有思路就很好做的
    可以把该题想象成过山车或者山峰......
    */
    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    int n;
    int cnt[5], last[5]; // last 是记录当前还有多少 0, 1, 2, 3
    int ans[100005];
    bool ok;
    
    int main()
    {
    for(int i = 0; i < 4; i++) {
    scanf("%d", &cnt[i]);
    n += cnt[i]; // n 就是输出的总长度
    }
    
    for(int i = 0; i < 4; i++){
    if(!cnt[i]) continue;
    ans[1] = i; // 依次取 0, 1, 2, 3 为第一位开始
    ok = true;
    for(int j = 0; j < 4; j++){
    last[j] = cnt[j] - (i == j); // 初始化 last
    }
    
    for(int j = 2; j <= n; j++){ // 因为第一位已经放了所以从第二位开始
    int p = ans[j - 1];
    if(p - 1 >= 0 && last[p - 1]){ // 往小(低)处走
    ans[j] = p - 1; last[p - 1]--;
    }
    else if(p + 1 < 4 && last[p + 1]){ // 往大(高)处走
    ans[j] = p + 1; last[p + 1]--;
    }
    else ok = false; // 假如都不能 则当前做法不可取
    }
    if(ok){
    printf("YES\n");
    for(int i = 1; i <= n; i++){
    printf("%d%c", ans[i], i == n ? '\n' : ' ');
    }
    break;
    }
    }
    if(!ok) printf("NO\n");
    
    return 0;
    }
    

     E,概率dp(目前还是不太懂

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int maxx = 2e5+10;
    const int mod = 998244353;
    LL p[maxx],dp[maxx];
    LL quick(LL a,LL b)
    {
        LL res=1;
        while(b)
        {
            if(b&1)res=(res*a)%mod;
            b>>=1;
            a=(a*a)%mod;
        }
        return res;
    }
    int main()
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%lld",&p[i]);
        //dp[i]=(dp[i-1]+1)*(pi/100)+(dp[i-1]+1+dp[i])*(1-pi/100)
        for(int i=1;i<=n;i++)
            dp[i]=(dp[i-1]+1)*100%mod*quick(p[i],mod-2)%mod;
        printf("%lld\n",dp[n]);
        return 0;
    }
    

      

  • 相关阅读:
    Handler机制来处理子线程去更新UI线程控件
    获得某月份的天数
    listview选中没有效果
    kali或其他系统,虚拟机中不能加载镜像
    tomcat开启多个端口
    kali自定义分辨率
    Redis 安装手册
    bash检查centos服务器运行状态
    关于利用RD client远程电脑,和输入法的一些问题
    centOS下 MYSQL基本操作
  • 原文地址:https://www.cnblogs.com/hgangang/p/12003153.html
Copyright © 2011-2022 走看看