C# 高精度乘法 支持小数(待优化)
将N*N乘法转化为(N*n1)+(N*n2)....(N*nn)
乘完后在补充小数点
public static char[] Quadrature(string a, string b)
{
char[] r = new char[] { '' };
List<int> bu = new List<int>();
List<int> au = new List<int>();
int adot = a.Length;
int bdot = b.Length;
for (int i = b.Length - ; i >= ; i--)
{
if (b[i] == '.')
{
bdot = i;
}
else
{
bu.Add(b[i] - );
}
}
for (int i = a.Length - ; i >= ; i--)
{
if (a[i] == '.')
{
adot = i;
}
else
{
au.Add(a[i] - );
}
}
a = "";
for (int i = au.Count() - ; i >= ; i--)
{
a += au[i];
} for (int i = ; i < bu.Count(); i++)
{
char[] qq = QuadUnit(a, bu[i]);
string qqq = "";
for (int j = ; j < i + ; j++)
{
qqq = "";
foreach (var item in qq)
{
qqq += item;
}
qq = QuadUnit(qqq, );
}
qqq = "";
foreach (var item in qq)
{
qqq += item;
}
string rr = "";
foreach (var item in r)
{
rr += item;
}
r = SumF(rr, qqq); }
List<char> rer = new List<char>();
for (int i = ; i < r.Count(); i++)
{
rer.Add(r[i]);
}
int con = rer.Count();
int dot = a.Length + b.Length - (adot + bdot); //Console.WriteLine(a);
//Console.WriteLine(b);
//Console.WriteLine(a.Length);
//Console.WriteLine(b.Length);
//Console.WriteLine(adot);
//Console.WriteLine(bdot);
//Console.WriteLine(con);
//Console.WriteLine(dot);
//Console.WriteLine(con-dot); if (con - dot > )
{
if (con - dot != con)
{
rer.Insert(con - dot + , '.');
}
}
else if (con - dot < )
{
rer.Insert(, '.');
rer.Insert(, ''); int co = - * (con - dot) - ;
while (co > )
{
rer.Insert(, '');
co--;
}
}
else
{
rer.Insert(, '.');
rer.Insert(, '');
} return rer.ToArray();
}
public static char[] QuadUnit(string a, int b)
{
int r = ;
int jw = ;
char[] c = a.ToCharArray();
List<char> items = new List<char>();
List<char> ritems = new List<char>();
for (int i = c.Count() - ; i >= ; i--)
{
if (a[i] == '.')
{
r = '.';
items.Add(Convert.ToChar(r));
}
else
{
r = ((int)c[i] - ) * b + jw;
jw = ;
if (r >= )
{
jw = r / ;
r %= ;
}
items.Add(Convert.ToChar(r.ToString()));
} }
if (jw > )
{
items.Add(Convert.ToChar(jw.ToString()));
} for (int i = (items.Count() - ); i >= ; i--)
{
ritems.Add(items[i]);
}
return ritems.ToArray();
}
C# 高精度乘法 支持小数(待优化)的更多相关文章
- C# 高精度加法 支持小数(待优化)
直接上代码 实现思路: 1.首先小数点补 位,9223372036854775808.9+9223372036854775808.9223372036854775808 => 922337203 ...
- C# 高精度减法 支持小数(待优化)
是现实思路 1,先小数点补位,8913758923475893274958738945793845-4893127498372459823745324532453245.284929384729837 ...
- JS高精度乘法计算问题(牛客网乘法-求 a 和 b 相乘的值,a 和 b 可能是小数,需要注意结果的精度问题)
用到的知识点===> toFixed(num); toFixed() 方法可把 Number 四舍五入为指定小数位数的数字; 参数num: 代表小数位数: 例:var num = 5.56789 ...
- 高精度乘法--C++
高精度乘法--C++ 模仿竖式乘法,在第一步计算的时候将进位保留,第一步计算完再处理进位.(见代码注释) 若要处理正负情况,可在数据输入后加以判断,处理比较简单. 小数计算也可参照该方法,不过对齐方式 ...
- 高精度乘法(FFT)
学会了FFT之后感觉自己征服了世界! 当然是幻觉... 不过FFT还是很有用的,在优化大规模的动规问题的时候有极大效果. 一般比较凶残的计数动规题都需要FFT(n<=1e9). 下面是高精度乘法 ...
- [vijos P1040] 高精度乘法
如果这次noip没考好,完全是因为从7月29日之后就没有再写过程序了.说起来,真是一个泪流满面的事实… 那这样一个弱智题练手恢复代码能力,竟然还花了我两个晚上(当然不是两整个晚上…) 第一天TLE了, ...
- 【PKU1001】Exponentiation(高精度乘法)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 145642 Accepted: 35529 ...
- hdu 1042 N!(高精度乘法 + 缩进)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...
- hdu 1042 N!(高精度乘法)
Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in ...
随机推荐
- 理解js中的原型链,prototype与__proto__的关系
说到prototype,就不得不先说下new的过程. 我们先看看这样一段代码: 1 <script type="text/javascript"> 2 var Pers ...
- 教你50招提升ASP.NET性能(九):显式的使用using语句减少内存泄露
(15)Reduce memory leaks dramatically with the “using” statement 招数15: 显式的使用using语句减少内存泄露 If a type i ...
- libpq程序例子
程序: [root@lex tst]# cat testlibpq.c /* * testlibpq.c * Test the C version of LIBPQ, the POSTGRES fro ...
- 【转】来自《轻松scrum之旅》的敏捷开发总结
敏捷开发的核心价值观是,软件开发最重要的是给用户提供有价值的.可以工作的软件.如何保证提供有价值的软件,是通过反馈机制来完成的.这一点,我们体会很深.自从采用敏捷开发以后,我们比以前更有意识地希望得到 ...
- UVa 131 - The Psychic Poker Player
题目:手里有五张牌,桌上有一堆牌(五张).你能够弃掉手中的k张牌,然后从牌堆中取最上面的k个. 比較规则例如以下:(按优先级排序) 1.straight-flush:同花顺.牌面为T(10) - A, ...
- Apache 目录权限
目录访问权限 输入用户名.密码后方可访问home目录下的文件: httpd.conf <Directory "D:/software/wwwroot/home"> Op ...
- DebuggingWithGdb
https://wiki.python.org/moin/DebuggingWithGdb http://blog.nsfocus.net/python-program-troubleshooting ...
- Android屏幕分辨率详解(VGA、HVGA、QVGA、WVGA、WQVGA)
这些术语都是指屏幕的分辨率. VGA:Video Graphics Array,即:显示绘图矩阵,相当于640×480 像素: HVGA:Half-size VGA:即:VGA的一半,分辨率为480× ...
- C#获取指定网页源码的几种方法
// WebClient private string GetWebClient(string url) { string strHTML = ""; WebClient myWe ...
- 数据库通用Jdbc操作
public class JdbcUtil { /** * 关闭一个数据库链接 * @param conn */ public static void closeConnection(Connecti ...