“Only true or false. 就是算法的魅力。”
1.题目:
2.分析:
从题目中我们可以得到很多信息。但是对于我们要做的而言,最关键的信息就是示例输出和示例输入,以及最后的解释。那么既然是在Unity中做这题,那么Unity要做什么,符合题意的算法又要做什么呢?
因为只需要将算法达到更容易理解的方式。
所以算法实现的是产生必定能够拼成正方形的火柴。
而Unity实现的就是,能让你用你的手将火柴,拼成正方形。
“Just do it”.
3.演示:
失败:
成功:
=。= 因为实在太难操作,所以加了个推子hhh。
4.核心代码:
MakeSquare类:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class MakeSquare : MonoBehaviour
{
public int[] orgNum = new int[10];
public GameObject tishi;
public static GameObject m_Square;
public GameObject[] m_Match,Square;
public List<int> numList = new List<int>();
public Button showSquare;
public Button isOK;
public bool canSquare;
public static int totalLen;
private Vector3 trs;
void Awake