class Program
{
static void Main(string[] args)
{ List<int> c = new List<int>() { , , , , };
c.Sort();
var result = getNumber(c, );
Console.WriteLine("{0}", result); Console.ReadKey(); } private static int getNumber(List<int> c, int k)
{
c.Sort();
int result = ;
int kk = k;
List<int> eachNum = new List<int>();
//convert each bit of k to a list.
while (k != )
{
eachNum.Add(k % );
k = k / ;
}
//get the each bit which is larger or equal the same position of k.
for (int i = eachNum.Count - ; i >= ; i--)
{
result = result * + getCurrentNum(c, eachNum[i]);
} //If the result by below is small than target. Replace the number from low position.
int j = ;
while (result <= kk && j < eachNum.Count)
{
j++;
if (c.Where(item => item > eachNum[j - ]).Count() == )
{ continue;
} result = (result / (int)Math.Pow(, j)) * (int)Math.Pow(, j);
result = result + getMinValLargerThanT(c.Where(item => item > eachNum[j - ]).First(), c.First(), j - ); } //If the result is still small than target, carry in adding.
if (result <= kk)
{
result = getMinValLargerThanT(c.Where(item => item > ).First(), c.First(), eachNum.Count);
} return result;
} public static int getMinValLargerThanT(int firstIsNotZero, int firstNum, int length)
{
int result = firstIsNotZero;
for (int i = ; i < length; i++)
{
result = result * + firstNum;
}
return result;
} //Get for each number min value larger than the same position.
public static int getCurrentNum(List<int> c, int highNum)
{
foreach (int cItem in c)
{
if (cItem >= highNum)
{
return cItem;
}
}
return ;
}
}

C#实现:给定[0-9]数组,求用数组组成的任意数字的最小值的更多相关文章

  1. 【POJ2774】Long Long Message(后缀数组求Height数组)

    点此看题面 大致题意: 求两个字符串中最长公共子串的长度. 关于后缀数组 关于\(Height\)数组的概念以及如何用后缀数组求\(Height\)数组详见这篇博客:后缀数组入门(二)--Height ...

  2. Java后缀数组-求sa数组

    后缀数组的一些基本概念请自行百度,简单来说后缀数组就是一个字符串所有后缀大小排序后的一个集合,然后我们根据后缀数组的一些性质就可以实现各种需求. public class MySuffixArrayT ...

  3. 用n(0)次求一个数组里面最大子数组的和(数组可以输入负数)

    今天老师布置了题目上的任务,可谓是杀死人脑细胞不偿命呐... 在课上叽叽咕咕的讨论了一节课也没有答案,只得出几个备选方案,一个是通过枚举法将数组里面的子数组和一个个列出来然后在进行比较,可想而知(n2 ...

  4. 牛客练习赛33 D tokitsukaze and Inverse Number (树状数组求逆序对,结论)

    链接:https://ac.nowcoder.com/acm/contest/308/D 来源:牛客网 tokitsukaze and Inverse Number 时间限制:C/C++ 1秒,其他语 ...

  5. 给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除。

    题目描述: 给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除. 输入: 两个整数n(2<=n<=1000),a(2<=a<=1000) 输出: 一个整数. ...

  6. [nowCoder] 两个不等长数组求第K大数

    给定两个有序数组arr1和arr2,在给定一个整数k,返回两个数组的所有数中第K小的数.例如:arr1 = {1,2,3,4,5};arr2 = {3,4,5};K = 1;因为1为所有数中最小的,所 ...

  7. poj 1743 男人八题之后缀数组求最长不可重叠最长重复子串

    Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14874   Accepted: 5118 De ...

  8. POJ-2299 Ultra-QuickSort---树状数组求逆序对+离散化

    题目链接: https://vjudge.net/problem/POJ-2299 题目大意: 本题要求对于给定的无序数组,求出经过最少多少次相邻元素的交换之后,可以使数组从小到大有序. 两个数(a, ...

  9. K:求取数组中最大连续子序列和的四个算法

    相关介绍:  求取数组中最大连续子序列和问题,是一个较为"古老"的一个问题.该问题的描述为,给定一个整型数组(当然浮点型也是可以的啦),求取其下标连续的子序列,且其和为该数组的所有 ...

随机推荐

  1. Android之全局的dialog的显示

    今天做项目有个需求就是有一个页面需要弹出一个dialog,但是这个dialog不可以影响,这个页面的跳转.这个页面可能跳转也可能不跳转,跳转后,这个dialog,还是显示的, 然而我们平时写的dial ...

  2. 使用github参与开源项目

    github上有很多非常优秀的开源项目,作为开源项目的受益者,你否想过为开源项目贡献自己的代码?

  3. vim 图

  4. css中伪元素before或after中content的特殊用法attr

    html代码如下: <div class="haorooms"> <span data-haorooms="haorooms鼠标效果tips-纯css& ...

  5. fiddler抓取Android 真机app数据包

    fiddler功能强大 不仅能抓pc上的请求还能抓取手机上的请求.下面以fiddler4 +android手机为例介绍一下 手机抓包. 官网下载fiddler后下一步下一步安装成功. 首先是fiddl ...

  6. textview 弹出键盘上面添加完成按钮,并设置输入内容的格式。

    - (void)setContentView{ self.contentTextView = [[UITextView alloc]initWithFrame:CGRectMake(11, 70, S ...

  7. 一个简单的左侧固定右侧自适应demo

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  8. c++ 对象的内存布局

    之前介绍过了普通对象比如系统自带的int等对象的对齐方式,在学习类型转换的时候遇到了自定义类型的继承体系中的downcast与upcast. 于是顺藤摸瓜,摸到了这里.发现还是 陈皓的博客里面写的最早 ...

  9. 把HBITMAP 保存图片文件.

    //VC下把HBITMAP保存为bmp图片 BOOL CtestBitMapDlg::SaveBmp(HBITMAP hBitmap, CString FileName) { HDC hDC; //当 ...

  10. Light OJ 1032 - Fast Bit Calculations(数学)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...