2019年我能变强组队训练赛第一场

Array Without Local Maximums

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int maxn=100001;
const ll mod=998244353;
int n,a[maxn];
ll f[maxn][201][3],sum,ans;
int main()
{
    scanf("%d",&n);
    for (int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    for (int i=1; i<=200; i++)
    {
        if (a[1]!=-1&&a[1]!=i)
        {
            f[1][i][0]=f[1][i][1]=f[1][i][2]=0;
        }
        else
        {
            f[1][i][0]=1;
            f[1][i][1]=0;
            f[1][i][2]=0;
        }
    }
    for (int i=2; i<=n; i++)
    {
        sum=0;
        for (int j=1; j<=200; j++)
        {
            if (a[i]!=-1&&a[i]!=j)
            {
                f[i][j][0]=0;
            }
            else
            {
                f[i][j][0]=sum;
            }
            sum=(sum+f[i-1][j][0]+f[i-1][j][1]+f[i-1][j][2])%mod;
        }
        for (int j=1; j<=200; j++)
        {
            if (a[i]!=-1&&a[i]!=j)
            {
                f[i][j][1]=0;
            }
            else
            {
                f[i][j][1]=(f[i-1][j][0]+f[i-1][j][1]+f[i-1][j][2])%mod;;
            }
        }
        sum=0;
        for (int j=200; j>=1; j--)
        {
            if (a[i]!=-1&&a[i]!=j)
            {
                f[i][j][2]=0;
            }
            else
            {
                f[i][j][2]=sum;
            }
            sum=(sum+f[i-1][j][1]+f[i-1][j][2])%mod;
        }
    }
    for (int i=1; i<=200; i++)
    {
        ans=(ans+f[n][i][2]+f[n][i][1])%mod;
    }
    printf("%lld\n",ans);
}

Shell Pyramid

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll i,j,k,n;
  
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&n) ;
        i = (ll)(pow(double(n) * 6.0,1.0/3.0))-1;
        while(i*(i+1)/2*(i+2)/3 < n )
        {
            i ++ ;
        }
        n -= (i-1)*(i)/2*(i+1)/3 ;
        j = (ll)(sqrt(n * 2.0)) ;
        while(j * (j+1)/2 < n)
            j ++ ;
        n -=j*(j-1)/2 ;
        k= n;
        printf("%lld %lld %lld\n",i,j,k) ;
    }
    return 0;
}

Gauss Elimination

import java.util.*;
import java.math.*;
 
public class Main
{
    public static BigInteger g[][] = new BigInteger[110][110];
 
    public static boolean Gauss_Elimination(int n)
    {
        BigInteger tmp,a,b;
        int i,j,k;
        for (i=0; i<n; i++)
        {
            for (j=i; j<n; j++)
            {
                if (g[j][i].compareTo(BigInteger.ZERO)!=0)
                {
                    break;
                }
            }
            if (j>=n)
            {
                return false;
            }
            if (i!=j)
            {
                for (k=0; k<=n; k++)
                {
                    tmp=g[i][k];
                    g[i][k]=g[j][k];
                    g[j][k]=tmp;
                }
            }
            a=g[i][i];
            for (j=i+1; j<n; j++)
            {
                if (g[j][i].compareTo(BigInteger.ZERO)!=0)
                {
                    b=g[j][i];
                    for (k=i; k<=n; k++)
                    {
                        g[j][k]=g[j][k].multiply(a).subtract(g[i][k].multiply(b));
                    }
                }
            }
        }
        return true;
    }
    public static void main (String[] args)
    {
        Scanner cin = new Scanner(System.in);
        BigInteger x[]= new BigInteger[110];
        BigInteger y[]= new BigInteger[110];
 
        BigInteger tmp,up,down;
 
        int n,i,j;
 
        boolean neg;
 
        while (cin.hasNext())
        {
            n=cin.nextInt();
            for (i=0; i<n; i++)
            {
                for (j=0; j<=n; j++)
                {
                    g[i][j]=cin.nextBigInteger();
                }
            }
            if (Gauss_Elimination(n))
            {
                for (i=n-1; i>=0; i--)
                {
                    up=BigInteger.ZERO;
                    down=BigInteger.ONE;
                    for (j=i+1; j<n; j++)
                    {
                        up=y[j].multiply(up).add(g[i][j].multiply(x[j].multiply(down)));
                        down=y[j].multiply(down);
                    }
                    up=g[i][n].multiply(down).subtract(up);
                    down=g[i][i].multiply(down);
                    if (up.multiply(down).compareTo(BigInteger.ZERO)<0)
                    {
                        neg=true;
                    }
                    else
                    {
                        neg=false;
                    }
                    up=up.abs();
                    down=down.abs();
                    tmp=up.gcd(down);
                    x[i]=up.divide(tmp);
                    y[i]=down.divide(tmp);
                    if (neg)
                    {
                        x[i]=x[i].negate();
                    }
                }
                for (i=0; i<n; i++)
                {
                    if (x[i].mod(y[i]).compareTo(BigInteger.ZERO)==0)
                    {
                        System.out.println(x[i].divide(y[i]));
                    }
                    else
                    {
                        System.out.println(x[i]+"/"+y[i]);
                    }
                }
            }
            else
            {
                System.out.println("No solution.");
            }
            System.out.println();
        }
    }
}

Simple Addition expression

Degree Sequence of Graph G

Navy maneuvers

Mining Station on the Sea

猜你喜欢

转载自www.cnblogs.com/Accpted/p/11310855.html