定点数,定点数二维向量,定点数三维向量,定点数数学类

2024-02-17 00:44

本文主要是介绍定点数,定点数二维向量,定点数三维向量,定点数数学类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

定点数,定点数二维向量,定点数三维向量,定点数数学类

  • 介绍
  • 浮点数
  • 定点数
  • 封装的定点数FixedNumber
  • 定点数二维向量
  • 定点数三维向量
  • 定点数数学类
  • 总结

介绍

众所周知定点数是用于做帧同步时保持不同cpu不同设备保持一致稳定的代替浮点数的变量,这里提供了之前封装好的定点数、定点数二维向量、定点数三位向量、定点数数学类。这里不是物理库,知识定点数变量。
定点数类库

浮点数

浮点数也就是float占用4个字节,而定点数是8long类型占用8个字节。不同的cpu机器在计算浮点数的时候都会有微小的差错,比如unity面板中设置一个对象的位置Position,有时候你输入的是一个整数,后来变成了接近你这个整数的.99或者.998等(用Unity时间久的应该是能感受到)。这是因为你输入之后cpu是要经过计算显示出来的。那么这种情况下我们在做帧同步的时候每个机型不一样,计算出来的float也会有差别,帧同步中有微乎其微的差别计算到最后也会是巨大的差别,会影响整个比赛的结果。

定点数

定点数通常使用long类型来计算,这里说明一下为什么是long类型,比如说一个浮点数9.988879,那么定点数可以这样标识,前4个字节记录9988879、后4个字节记录小数点(.)在第几位,最后拼接成我们想要的结果,这样就能保证不同的机器中运算结果一致。

封装的定点数FixedNumber

具体的使用方式其实跟Int float差不太多,只是API可能略有不同,下面是定点数完整的代码,具体的用法我就不做详细说明了,我简单的说明一下
用法

// Update is called once per frame
void Update()
{if (Input.GetKeyDown(KeyCode.Space)){FixedNumber fn = new FixedNumber(f);Debug.LogError(fn);Debug.LogError(fn.GetValue());Debug.LogError(fn.ToFloat());}
}

定点数代码

using System;/// <summary>
/// 定点数 使用Int64实现
/// </summary>
[Serializable]
public struct FixedNumber
{/// <summary>/// 小数占用位数/// </summary>public static int Fix_Fracbits = 16;/// <summary>/// 0/// </summary>public static FixedNumber Zero = new FixedNumber(0);internal Int64 m_Bits;public FixedNumber(int x){m_Bits = (x << Fix_Fracbits);}public FixedNumber(float x){m_Bits = (Int64)((x) * (1 << Fix_Fracbits));}public FixedNumber(Int64 x){m_Bits = ((x) * (1 << Fix_Fracbits));}public Int64 GetValue(){return m_Bits;}public FixedNumber SetValue(Int64 i){m_Bits = i;return this;}public static FixedNumber Lerp(FixedNumber a, FixedNumber b, float t){return a + (b - a) * t;}public static FixedNumber Lerp(FixedNumber a, FixedNumber b, FixedNumber t){return a + (b - a) * t;}public FixedNumber Abs(){return FixedNumber.Abs(this);}public FixedNumber Sqrt(){return FixedNumber.Sqrt(this);}//******************* +  **************************public static FixedNumber operator +(FixedNumber p1, FixedNumber p2){FixedNumber tmp;tmp.m_Bits = p1.m_Bits + p2.m_Bits;return tmp;}public static FixedNumber operator +(FixedNumber p1, int p2){FixedNumber tmp;tmp.m_Bits = p1.m_Bits + (Int64)(p2 << Fix_Fracbits);return tmp;}public static FixedNumber operator +(int p1, FixedNumber p2){return p2 + p1;}public static FixedNumber operator +(FixedNumber p1, Int64 p2){FixedNumber tmp;tmp.m_Bits = p1.m_Bits + p2 << Fix_Fracbits;return tmp;}public static FixedNumber operator +(Int64 p1, FixedNumber p2){return p2 + p1;}public static FixedNumber operator +(FixedNumber p1, float p2){FixedNumber tmp;tmp.m_Bits = p1.m_Bits + (Int64)(p2 * (1 << Fix_Fracbits));return tmp;}public static FixedNumber operator +(float p1, FixedNumber p2){FixedNumber tmp = p2 + p1;return tmp;}//*******************  -  **************************public static FixedNumber operator -(FixedNumber p1, FixedNumber p2){FixedNumber tmp;tmp.m_Bits = p1.m_Bits - p2.m_Bits;return tmp;}public static FixedNumber operator -(FixedNumber p1, int p2){FixedNumber tmp;tmp.m_Bits = p1.m_Bits - (Int64)(p2 << Fix_Fracbits);return tmp;}public static FixedNumber operator -(int p1, FixedNumber p2){FixedNumber tmp;tmp.m_Bits = (p1 << Fix_Fracbits) - p2.m_Bits;return tmp;}public static FixedNumber operator -(FixedNumber p1, Int64 p2){FixedNumber tmp;tmp.m_Bits = p1.m_Bits - (p2 << Fix_Fracbits);return tmp;}public static FixedNumber operator -(Int64 p1, FixedNumber p2){FixedNumber tmp;tmp.m_Bits = (p1 << Fix_Fracbits) - p2.m_Bits;return tmp;}public static FixedNumber operator -(float p1, FixedNumber p2){FixedNumber tmp;tmp.m_Bits = (Int64)(p1 * (1 << Fix_Fracbits)) - p2.m_Bits;return tmp;}public static FixedNumber operator -(FixedNumber p1, float p2){FixedNumber tmp;tmp.m_Bits = p1.m_Bits - (Int64)(p2 * (1 << Fix_Fracbits));return tmp;}//******************* * **************************public static FixedNumber operator *(FixedNumber p1, FixedNumber p2){FixedNumber tmp;tmp.m_Bits = ((p1.m_Bits) * (p2.m_Bits)) >> (Fix_Fracbits);return tmp;}public static FixedNumber operator *(int p1, FixedNumber p2){FixedNumber tmp;tmp.m_Bits = p1 * p2.m_Bits;return tmp;}public static FixedNumber operator *(FixedNumber p1, int p2){return p2 * p1;}public static FixedNumber operator *(FixedNumber p1, float p2){FixedNumber tmp;tmp.m_Bits = (Int64)(p1.m_Bits * p2);return tmp;}public static FixedNumber operator *(float p1, FixedNumber p2){FixedNumber tmp;tmp.m_Bits = (Int64)(p1 * p2.m_Bits);return tmp;}//******************* / **************************public static FixedNumber operator /(FixedNumber p1, FixedNumber p2){FixedNumber tmp;if (p2 == FixedNumber.Zero){//UnityEngine.Debug.LogError("/0");tmp.m_Bits = Zero.m_Bits;}else{tmp.m_Bits = (p1.m_Bits) * (1 << Fix_Fracbits) / (p2.m_Bits);}return tmp;}public static FixedNumber operator /(FixedNumber p1, int p2){FixedNumber tmp;if (p2 == 0){//UnityEngine.Debug.LogError("/0");tmp.m_Bits = Zero.m_Bits;}else{tmp.m_Bits = p1.m_Bits / (p2);}return tmp;}public static FixedNumber operator %(FixedNumber p1, int p2){FixedNumber tmp;if (p2 == 0){//UnityEngine.Debug.LogError("/0");tmp.m_Bits = Zero.m_Bits;}else{tmp.m_Bits = (p1.m_Bits % (p2 << Fix_Fracbits));}return tmp;}public static FixedNumber operator /(int p1, FixedNumber p2){FixedNumber tmp;if (p2 == Zero){//UnityEngine.Debug.LogError("/0");tmp.m_Bits = Zero.m_Bits;}else{Int64 tmp2 = ((Int64)p1 << Fix_Fracbits << Fix_Fracbits);tmp.m_Bits = tmp2 / (p2.m_Bits);}return tmp;}public static FixedNumber operator /(FixedNumber p1, Int64 p2){FixedNumber tmp;if (p2 == 0){//UnityEngine.Debug.LogError("/0");tmp.m_Bits = Zero.m_Bits;}else{tmp.m_Bits = p1.m_Bits / (p2);}return tmp;}public static FixedNumber operator /(Int64 p1, FixedNumber p2){FixedNumber tmp;if (p2 == Zero){//UnityEngine.Debug.LogError("/0");tmp.m_Bits = Zero.m_Bits;}else{if (p1 > Int32.MaxValue || p1 < Int32.MinValue){tmp.m_Bits = 0;return tmp;}tmp.m_Bits = (p1 << Fix_Fracbits) / (p2.m_Bits);}return tmp;}public static FixedNumber operator /(float p1, FixedNumber p2){FixedNumber tmp;if (p2 == Zero){//UnityEngine.Debug.LogError("/0");tmp.m_Bits = Zero.m_Bits;}else{Int64 tmp1 = (Int64)p1 * ((Int64)1 << Fix_Fracbits << Fix_Fracbits);tmp.m_Bits = (tmp1) / (p2.m_Bits);}return tmp;}public static FixedNumber operator /(FixedNumber p1, float p2){FixedNumber tmp;if (p2 > -0.000001f && p2 < 0.000001f){//UnityEngine.Debug.LogError("/0");tmp.m_Bits = Zero.m_Bits;}else{tmp.m_Bits = (p1.m_Bits << Fix_Fracbits) / ((Int64)(p2 * (1 << Fix_Fracbits)));}return tmp;}public static FixedNumber Sqrt(FixedNumber p1){FixedNumber tmp;Int64 ltmp = p1.m_Bits * (1 << Fix_Fracbits);tmp.m_Bits = (Int64)Math.Sqrt(ltmp);return tmp;}public static bool operator >(FixedNumber p1, FixedNumber p2){return (p1.m_Bits > p2.m_Bits) ? true : false;}public static bool operator <(FixedNumber p1, FixedNumber p2){return (p1.m_Bits < p2.m_Bits) ? true : false;}public static bool operator <=(FixedNumber p1, FixedNumber p2){return (p1.m_Bits <= p2.m_Bits) ? true : false;}public static bool operator >=(FixedNumber p1, FixedNumber p2){return (p1.m_Bits >= p2.m_Bits) ? true : false;}public static bool operator !=(FixedNumber p1, FixedNumber p2){return (p1.m_Bits != p2.m_Bits) ? true : false;}public static bool operator ==(FixedNumber p1, FixedNumber p2){return (p1.m_Bits == p2.m_Bits) ? true : false;}public static bool Equals(FixedNumber p1, FixedNumber p2){return (p1.m_Bits == p2.m_Bits) ? true : false;}public bool Equals(FixedNumber right){if (m_Bits == right.m_Bits){return true;}return false;}public static bool operator >(FixedNumber p1, float p2){return (p1.m_Bits > (p2 * (1 << Fix_Fracbits))) ? true : false;}public static bool operator <(FixedNumber p1, float p2){return (p1.m_Bits < (p2 * (1 << Fix_Fracbits))) ? true : false;}public static bool operator <=(FixedNumber p1, float p2){return (p1.m_Bits <= p2 * (1 << Fix_Fracbits)) ? true : false;}public static bool operator >=(FixedNumber p1, float p2){return (p1.m_Bits >= p2 * (1 << Fix_Fracbits)) ? true : false;}public static bool operator !=(FixedNumber p1, float p2){return (p1.m_Bits != p2 * (1 << Fix_Fracbits)) ? true : false;}public static bool operator ==(FixedNumber p1, float p2){return (p1.m_Bits == p2 * (1 << Fix_Fracbits)) ? true : false;}public static FixedNumber Max(){FixedNumber tmp;tmp.m_Bits = Int64.MaxValue;return tmp;}public static FixedNumber Max(FixedNumber p1, FixedNumber p2){return p1.m_Bits > p2.m_Bits ? p1 : p2;}public static FixedNumber Min(FixedNumber p1, FixedNumber p2){return p1.m_Bits < p2.m_Bits ? p1 : p2;}public static FixedNumber Precision(){FixedNumber tmp;tmp.m_Bits = 1;return tmp;}public static FixedNumber MaxValue(){FixedNumber tmp;tmp.m_Bits = Int64.MaxValue;return tmp;}public static FixedNumber Abs(FixedNumber P1){FixedNumber tmp;tmp.m_Bits = Math.Abs(P1.m_Bits);return tmp;}public static FixedNumber operator -(FixedNumber p1){FixedNumber tmp;tmp.m_Bits = -p1.m_Bits;return tmp;}public float ToFloat(){return m_Bits / (float)(1 << Fix_Fracbits);}public UnityEngine.Quaternion ToUnityRotation(){return UnityEngine.Quaternion.Euler(0, -this.ToFloat(), 0);}public int ToInt(){return (int)(m_Bits >> (Fix_Fracbits));}public override string ToString(){double tmp = (double)m_Bits / (double)(1 << Fix_Fracbits);return tmp.ToString();}
}

定点数二维向量

using UnityEngine;/// <summary>
/// 定点数二维向量
/// </summary>
[System.Serializable]
public struct Fixed2
{public FixedNumber x;public FixedNumber y;public Fixed2(float x, float y){this.x = new FixedNumber(x);this.y = new FixedNumber(y);}public Fixed2(FixedNumber x, FixedNumber y){this.x = x;this.y = y;}public Vector3 ToVector3(){return new Vector3(x.ToFloat(), 0, y.ToFloat());}public static Fixed2 GetV2(FixedNumber x, FixedNumber y){return new Fixed2(x, y);}public static Fixed2 operator +(Fixed2 a, Fixed2 b){return new Fixed2(a.x + b.x, a.y + b.y);}public static Fixed2 operator -(Fixed2 a, Fixed2 b){return new Fixed2(a.x - b.x, a.y - b.y);}public static Fixed2 operator *(Fixed2 a, FixedNumber b){return new Fixed2(a.x * b, a.y * b);}public Fixed2 Rotate(FixedNumber value){FixedNumber tx, ty;tx = MathFixed.CosAngle(value) * x - y * MathFixed.SinAngle(value);ty = MathFixed.CosAngle(value) * y + x * MathFixed.SinAngle(value);//1,0   tx=1*0-0  tyreturn new Fixed2(tx, ty);}public FixedNumber ToRotation(){if (x == 0 && y == 0){return new FixedNumber();}FixedNumber sin = this.normalized.y;if (this.x >= 0){return MathFixed.Asin(sin) / MathFixed.PI * 180;}else{return MathFixed.Asin(-sin) / MathFixed.PI * 180 + 180;}}public static Fixed2 Parse(FixedNumber ratio){return new Fixed2(MathFixed.CosAngle(ratio), MathFixed.SinAngle(ratio));}public Fixed2 normalized{get{if (x == 0 && y == 0){return new Fixed2();}FixedNumber n = ((x * x) + (y * y)).Sqrt();return new Fixed2(x / n, y / n);}}public static Fixed2 left = new Fixed2(-1, 0);public static Fixed2 right = new Fixed2(1, 0);public static Fixed2 up = new Fixed2(0, 1);public static Fixed2 down = new Fixed2(0, -1);public static Fixed2 zero = new Fixed2(0, 0);public FixedNumber Dot(Fixed2 b){return Dot(this, b);}public static FixedNumber Dot(Fixed2 a, Fixed2 b){return a.x * b.x + b.y * a.y;}public static Fixed2 operator -(Fixed2 a){return new Fixed2(-a.x, -a.y);}public static Fixed3 operator *(Fixed2 a, Fixed2 b){return new Fixed3(new FixedNumber(), new FixedNumber(), a.x * b.y - a.y * b.x);}public static bool operator ==(Fixed2 a, Fixed2 b){return a.x == b.x && a.y == b.y;}public static bool operator !=(Fixed2 a, Fixed2 b){return a.x != b.x || a.y != b.y;}public override string ToString(){return "{" + x.ToString() + "," + y.ToString() + "}";}}

定点数三维向量

using UnityEngine;/// <summary>
/// 定点数三维向量
/// </summary>
public struct Fixed3
{public FixedNumber x{get;private set;}public FixedNumber y{get;private set;}public FixedNumber z{get;private set;}public Fixed3(int x = 0, int y = 0, int z = 0){this.x = new FixedNumber(x);this.y = new FixedNumber(y);this.z = new FixedNumber(z);}public Fixed3(float x, float y, float z){this.x = new FixedNumber(x);this.y = new FixedNumber(y);this.z = new FixedNumber(z);}public Fixed3(FixedNumber x, FixedNumber y, FixedNumber z){this.x = x;this.y = y;this.z = z;}public Vector3 ToVector3(){return new Vector3(x.ToFloat(), 0, y.ToFloat());}public static Fixed3 operator +(Fixed3 a, Fixed3 b){return new Fixed3(a.x + b.x, a.y + b.y, a.z + b.z);}public static Fixed3 operator -(Fixed3 a, Fixed3 b){return new Fixed3(a.x - b.x, a.y - b.y, a.z - b.z);}public static Fixed3 left = new Fixed3(-1, 0);public static Fixed3 right = new Fixed3(1, 0);public static Fixed3 up = new Fixed3(0, 1);public static Fixed3 down = new Fixed3(0, -1);public static Fixed3 zero = new Fixed3(0, 0);public FixedNumber Dot(Fixed3 b){return Dot(this, b);}public static FixedNumber Dot(Fixed3 a, Fixed3 b){return a.x * b.x + b.y * a.y;}public static Fixed3 operator -(Fixed3 a){return new Fixed3(-a.x, -a.y, -a.z);}public static Fixed2 operator *(Fixed3 a, Fixed2 b){return new Fixed2(-a.z * b.y, a.z * b.x);}public override string ToString(){return "{" + x.ToString() + "," + y.ToString() + "}";}
}

定点数数学类

using System.Collections.Generic;/// <summary>
/// 定点数数学类
/// </summary>
class MathFixed
{protected static int tabCount = 18 * 4;/// <summary>/// sin值对应表/// </summary>protected static readonly List<FixedNumber> _m_SinTab = new List<FixedNumber>();public static readonly FixedNumber PI = new FixedNumber(3.14159265f);protected static FixedNumber GetSinTab(FixedNumber r){FixedNumber i = new FixedNumber(r.ToInt());//UnityEngine.Debug.Log(i.ToInt());if (i.ToInt() == _m_SinTab.Count - 1){return _m_SinTab[(int)i.ToInt()];}else{// UnityEngine.Debug.Log(i.ToInt()+":"+ _m_SinTab[i.ToInt()]+":"+ Ratio.Lerp(_m_SinTab[i.ToInt()], _m_SinTab[(i + 1).ToInt()], r - i));return FixedNumber.Lerp(_m_SinTab[(int)i.ToInt()], _m_SinTab[(int)(i + 1).ToInt()], r - i);}}public static FixedNumber GetAsinTab(FixedNumber sin){MathFixed math = Instance;//UnityEngine.Debug.Log("GetAsinTab");for (int i = _m_SinTab.Count - 1; i >= 0; i--){if (sin > _m_SinTab[i]){if (i == _m_SinTab.Count - 1){return new FixedNumber(i) / (tabCount / 4) * (PI / 2);}else{//return new Ratio(i);return FixedNumber.Lerp(new FixedNumber(i), new FixedNumber(i + 1), (sin - _m_SinTab[i]) / (_m_SinTab[i + 1] - _m_SinTab[i])) / (tabCount / 4) * (PI / 2);}}}return new FixedNumber();}protected static MathFixed Instance{get{if (_m_instance == null){_m_instance = new MathFixed();}return _m_instance;}}protected static MathFixed _m_instance;protected MathFixed(){if (_m_instance == null){_m_SinTab.Add(new FixedNumber(0f));//0_m_SinTab.Add(new FixedNumber(0.08715f));_m_SinTab.Add(new FixedNumber(0.17364f));_m_SinTab.Add(new FixedNumber(0.25881f));_m_SinTab.Add(new FixedNumber(0.34202f));//20_m_SinTab.Add(new FixedNumber(0.42261f));_m_SinTab.Add(new FixedNumber(0.5f));_m_SinTab.Add(new FixedNumber(0.57357f));//35_m_SinTab.Add(new FixedNumber(0.64278f));_m_SinTab.Add(new FixedNumber(0.70710f));_m_SinTab.Add(new FixedNumber(0.76604f));_m_SinTab.Add(new FixedNumber(0.81915f));//55_m_SinTab.Add(new FixedNumber(0.86602f));//60_m_SinTab.Add(new FixedNumber(0.90630f));_m_SinTab.Add(new FixedNumber(0.93969f));_m_SinTab.Add(new FixedNumber(0.96592f));_m_SinTab.Add(new FixedNumber(0.98480f));//80_m_SinTab.Add(new FixedNumber(0.99619f));_m_SinTab.Add(new FixedNumber(1f));}}public static FixedNumber PiToAngel(FixedNumber pi){return pi / PI * 180;}public static FixedNumber Asin(FixedNumber sin){if (sin < -1 || sin > 1) { return new FixedNumber(); }if (sin >= 0){return GetAsinTab(sin);}else{return -GetAsinTab(-sin);}}public static FixedNumber Sin(FixedNumber r){MathFixed math = Instance;//int tabCount = SinTab.Count*4;FixedNumber result = new FixedNumber();r = (r * tabCount / 2 / PI);//int n = r.ToInt();while (r < 0){r += tabCount;}while (r > tabCount){r -= tabCount;}if (r >= 0 && r <= tabCount / 4)                // 0 ~ PI/2{result = GetSinTab(r);}else if (r > tabCount / 4 && r < tabCount / 2)       // PI/2 ~ PI{r -= new FixedNumber(tabCount / 4);result = GetSinTab(new FixedNumber(tabCount / 4) - r);}else if (r >= tabCount / 2 && r < 3 * tabCount / 4)    // PI ~ 3/4*PI{r -= new FixedNumber(tabCount / 2);result = -GetSinTab(r);}else if (r >= 3 * tabCount / 4 && r < tabCount)      // 3/4*PI ~ 2*PI{r = new FixedNumber(tabCount) - r;result = -GetSinTab(r);}return result;}public static FixedNumber Abs(FixedNumber ratio){return FixedNumber.Abs(ratio);}public static FixedNumber Sqrt(FixedNumber r){return FixedNumber.Sqrt(r);}public static FixedNumber Cos(FixedNumber r){return Sin(r + PI / 2);}public static FixedNumber SinAngle(FixedNumber angle){return Sin(angle / 180 * PI);}public static FixedNumber CosAngle(FixedNumber angle){return Cos(angle / 180 * PI);}
}

总结

上面做的封装基本还算完善,可以看下代码具体怎么使用。
感谢大家的支持

这篇关于定点数,定点数二维向量,定点数三维向量,定点数数学类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/716182

相关文章

hdu1240、hdu1253(三维搜索题)

1、从后往前输入,(x,y,z); 2、从下往上输入,(y , z, x); 3、从左往右输入,(z,x,y); hdu1240代码如下: #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#inc

poj2576(二维背包)

题意:n个人分成两组,两组人数只差小于1 , 并且体重只差最小 对于人数要求恰好装满,对于体重要求尽量多,一开始没做出来,看了下解题,按照自己的感觉写,然后a了 状态转移方程:dp[i][j] = max(dp[i][j],dp[i-1][j-c[k]]+c[k]);其中i表示人数,j表示背包容量,k表示输入的体重的 代码如下: #include<iostream>#include<

hdu2159(二维背包)

这是我的第一道二维背包题,没想到自己一下子就A了,但是代码写的比较乱,下面的代码是我有重新修改的 状态转移:dp[i][j] = max(dp[i][j], dp[i-1][j-c[z]]+v[z]); 其中dp[i][j]表示,打了i个怪物,消耗j的耐力值,所得到的最大经验值 代码如下: #include<iostream>#include<algorithm>#include<

hdu4826(三维DP)

这是一个百度之星的资格赛第四题 题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1004&cid=500 题意:从左上角的点到右上角的点,每个点只能走一遍,走的方向有三个:向上,向下,向右,求最大值。 咋一看像搜索题,先暴搜,TLE,然后剪枝,还是TLE.然后我就改方法,用DP来做,这题和普通dp相比,多个个向上

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

uva 10014 Simple calculations(数学推导)

直接按照题意来推导最后的结果就行了。 开始的时候只做到了第一个推导,第二次没有继续下去。 代码: #include<stdio.h>int main(){int T, n, i;double a, aa, sum, temp, ans;scanf("%d", &T);while(T--){scanf("%d", &n);scanf("%lf", &first);scanf

uva 10025 The ? 1 ? 2 ? ... ? n = k problem(数学)

题意是    ?  1  ?  2  ?  ...  ?  n = k 式子中给k,? 处可以填 + 也可以填 - ,问最小满足条件的n。 e.g k = 12  - 1 + 2 + 3 + 4 + 5 + 6 - 7 = 12 with n = 7。 先给证明,令 S(n) = 1 + 2 + 3 + 4 + 5 + .... + n 暴搜n,搜出当 S(n) >=

uva 11044 Searching for Nessy(小学数学)

题意是给出一个n*m的格子,求出里面有多少个不重合的九宫格。 (rows / 3) * (columns / 3) K.o 代码: #include <stdio.h>int main(){int ncase;scanf("%d", &ncase);while (ncase--){int rows, columns;scanf("%d%d", &rows, &col

【生成模型系列(初级)】嵌入(Embedding)方程——自然语言处理的数学灵魂【通俗理解】

【通俗理解】嵌入(Embedding)方程——自然语言处理的数学灵魂 关键词提炼 #嵌入方程 #自然语言处理 #词向量 #机器学习 #神经网络 #向量空间模型 #Siri #Google翻译 #AlexNet 第一节:嵌入方程的类比与核心概念【尽可能通俗】 嵌入方程可以被看作是自然语言处理中的“翻译机”,它将文本中的单词或短语转换成计算机能够理解的数学形式,即向量。 正如翻译机将一种语言

HDU 2159 二维完全背包

FATE 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务。久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级。现在的问题是,xhd升掉最后一级还需n的经验值,xhd还留有m的忍耐度,每杀一个怪xhd会得到相应的经验,并减掉相应的忍耐度。当忍耐度降到0或者0以下时,xhd就不会玩这游戏。xhd还说了他最多只杀s只怪。请问他能