三角形类的数据摆放转矩阵、蛇形填数

文章展示了两种使用Java解决数学问题的方法:一种是通过找规律迭代,另一种是暴力打表法。第一段代码通过迭代计算特定序列的第20个数,而第二段代码通过填充矩阵直到找到第20行第20列的值。

直接上图模拟:

答案:761

AC代码1:(找规律)

import java.io.*;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

public class Main
{
    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static int N = 100010;

    public static void main(String[] args) throws NumberFormatException, IOException
    {
        int i = 4;

        int cnt = 0; // 记录迭代次数,需要迭代19次
        int sum = 1;
        while(true)
        {
            sum += i;
            i += 4;
            cnt ++; // 迭代次数+1
            if(cnt == 19) // 求第20个数,迭代19次
            {
                pw.println(sum);
                pw.flush();
                return;
            }
        }
    }
}

class rd
{
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tokenizer = new StringTokenizer("");

    static String nextLine() throws IOException { return reader.readLine(); }
    static String next() throws IOException
    {
        while(!tokenizer.hasMoreTokens())  tokenizer = new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException { return Integer.parseInt(next()); }
    static double nextDouble() throws IOException { return Double.parseDouble(next()); }
    static long nextLong() throws IOException { return Long.parseLong(next()); }
    static BigInteger nextBigInteger() throws IOException
    {
        BigInteger d = new BigInteger(rd.nextLine());
        return d;
    }
}

class math
{
    int gcd(int a,int b)
    {
        if(b == 0)  return a;
        else return gcd(b,a % b);
    }

    int lcm(int a,int b)
    {
        return a * b / gcd(a, b);
    }

    // 求n的所有约数
    List get_factor(int n)
    {
        List<Long> a = new ArrayList<>();
        for(long i = 1; i <= Math.sqrt(n) ; i ++)
        {
            if(n % i == 0)
            {
                a.add(i);
                if(i != n / i)  a.add(n / i);  // // 避免一下的情况:x = 16时,i = 4 ,x / i = 4的情况,这样会加入两种情况  ^-^复杂度能减少多少是多少
            }
        }

        // 相同因子去重,这个方法,完美
        a = a.stream().distinct().collect(Collectors.toList());

        // 对因子排序(升序)
        Collections.sort(a);

        return a;
    }

    // 判断是否是质数
    boolean check_isPrime(int n)
    {
        if(n < 2) return false;
        for(int i = 2 ; i <= n / i; i ++)  if (n % i == 0) return false;
        return true;
    }
}

class PII implements Comparable<PII>
{
    int x,y;
    public PII(int x ,int y)
    {
        this.x = x;
        this.y = y;
    }
    public int compareTo(PII a)
    {
        if(this.x-a.x != 0)
            return this.x-a.x;  //按x升序排序
        else return this.y-a.y;  //如果x相同,按y升序排序
    }
}

class Edge
{
    int a,b,c;
    public Edge(int a ,int b, int c)
    {
        this.a = a;
        this.b = b;
        this.c = c;
    }
}

AC代码2:(暴力打表)

 

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;



public class Main
{
    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static int N = (int)200;
    static int a[][] = new int[N][N];

    public static void main(String[] args ) throws IOException
    {
        a[1][1] = 1;

        int num = 1;
        int row = 1;
        int col = 1;
        while(a[20][20] == 0) // 更新到a[20][20]退出循环
        {
            // 右移
            a[row][++col] = ++num;

            // 左下方
            while(col > 1)  a[++row][--col] = ++num; // 注意等于

            // 下移
            a[++ row][col] = ++num;
            while(row > 1)  a[--row][++ col] = ++num; // 注意等于
        }

        pw.println(a[20][20]);
        pw.flush();
    }
}

class rd
{
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tokenizer = new StringTokenizer("");

    static String nextLine() throws IOException  { return reader.readLine(); }

    static String next() throws IOException
    {
        while (!tokenizer.hasMoreTokens())  tokenizer = new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException  { return Integer.parseInt(next()); }

    static double nextDouble() throws IOException { return Double.parseDouble(next()); }

    static long nextLong() throws IOException  { return Long.parseLong(next());}

    static BigInteger nextBigInteger() throws IOException
    {
        BigInteger d = new BigInteger(rd.nextLine());
        return d;
    }
}

class PII
{
    int x,y;
    public PII(int x ,int y)
    {
        this.x = x;
        this.y = y;
    }
}

你是字IC的专家还是学专家,我现有一任务为ICS电路设计,针对交织处理需要你根据已知参E,P,N,S,L推导出输出数据是哪些。详细的任务描述如下: 任务整体描述:设计一个电路完成三路bit数据的交织(interleave)、合并(combine)和加扰(scramble)处理。交织处理通过同一组接口,从外部IN_BUF(外部模块,无需开发)分时读取三路长度为N0/N1/N2 bit的待交织数据,分别进行交织处理后的bit数据长度为E0/E1/E2。IN_BUF读接口支持每cycle读取连续128bit待交织数据。三路交织处理后的bit数据并不是所有bit都有效,有效bit数据起始点为S0/S1/S2,有效bit数据长度为L0/L1/L2,总有效bit数据长度LL = L0 + L1 + L2。取三路交织处理后的有效bit按照特定规则合并成一路的过程即为合并处理。加扰处理过程为对合并处理后的输出bit数据和特定随机序列进行按位异或。最后将加扰处理后的bit数据按照特定规则拼接成120bit对外输出。 交织处理:PART0/PART1/PART2三路交织处理各自独立,但处理流程完全相同,具体交织处理流程如下4步:1.从外部读取N bit待加扰bit数据{A0,A1,…,An-1},循环重复到E bit,得到序列{A0,A1,…,An-1,A0,A1,…,An-1,A0,A1,…,Ax},其中E值为交织后的bit数据长度;2.找到一个边长为P的倒等腰直角三角形,使得P*(P+1)/2 >=E,(P-1)*P/2<E;3.将循环重复后的E bit数据按行从左到右从上到下的顺序放入三角形;4.按列从上到下从左到右的顺序,从首个有效bit数据位置S开始连续输出L bit数据。 交织处理有以下约束:1.PART0/PART1/PART2三路不一定都有效,但至少有一路有效;2.PART0/PART1/PART2三路交织处理的N/E/S/L参值不一定相同;3.待交织处理的bit数据长度N的取值集合为{32,64,128,256,512,1024},共6种取值;4.交织处理后bit数据长度E和输入bit数据长度N满足,E >= N且E <= 8192;5.交织处理后的bit数据长度E,有效bit数据起点S和bit长度L满足,L % Q = 0,L+S-1 <= E,L >=1;其中Q为合并处理模块参,表示连续Qbit数据为一个整体进行合并处理,取值集合为{1,2,4,6,8,10},共6种取值; 合并处理:合并处理过程即是将所有有效PART的有效bit数据,按照一定的规则摆放成LL/Q行,每行摆放10bit数据,其中低Qbit摆放有效bit数据,其余位置全部摆放0。有效bit数据从低bit到高bit,从低行到高行顺序摆放,最终按照行从小到大的顺序输出。合并处理bit数据摆放存在优先级,具体优先级为PART0>PART1>PART2。对于PARTX(X的取值范围为0/1/2)摆放规则为,剔除比PARTX优先级高的PART已经占用的行,从剩余行中的第0行开始,固定每间隔行,占用一行用来摆放PARTX的bit数据,直到PARTX的有效bit数据摆完为止。其中,Lx为PARTX有效bit数据长度,Lt为LL剔除优先级大于PARTX的所有有效PART的有效bit数据长度之和。 加扰处理:将合并处理后的有效bit数据(每行仅低Qbit数据有效)和随机序列进行按bit异或处理的过程即为加扰处理。具体的扰码发生器c(n)的生成公式为:c(n)=(x_1(n+N_c)+x_2(n+N_c))mod2;x_1(n+31)=(x_1(n+3)+x_1(n))mod2;x_2(n+31)=(x_2(n+3)+x_2(n+2)+x_2(n+1)+x_2(n))mod2;其中N_c=16000,x_1(n)的初值为x_1(0)=1,x_1(n)=0,n=1,2,...,30;x_2(n)的初值不固定,由外部输入的31bit信号c_init决定,c_init=求和(x_2(i)*2^i)(i从0到30)。加扰处理后的数据每连续12行为一组,按照行从小到大的顺序拼接成120bit的数据,不足12行时不足部分用零补充,最后再按照组从小到大的顺序输出。由于不是每次输出12行都有效,因此还需要输出有效行指示,表示当前12行输出数据中有多少行是有效数据,取值范围为1~12。
03-14
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

21RGHLY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值