如何计算n个售票窗口的m门票所赚取的最高金额,票价与票房的票数相等?
火车站有n个售票窗口.带窗口的(j)门票可用.票价与当时该窗口中剩余的票数相等.卖火车票的最高金额是多少?
例如,如果我们有3个售票窗口,有3个,3个,4个门票,我们想卖5张门票.然后:
n = 3, m = 5
A[3] = {3, 3, 4}
Run Code Online (Sandbox Code Playgroud)
赚取的最高金额是4 + 3 + 3 + 3 + 2 = 15
我在网上看到了这个问题,我的解决方案是首先将所有票号都推到maxHeap并运行for循环m次.每次我们弹出maxHeap的最高值并将其添加到所赚取的总金额中,如果该值大于1,我们将(value - 1)推送到maxHeap.
但这在某种程度上耗费时间消耗任何更好的解决方案?
是否真的有使用typeof(String)
vs的显着性能优势System.Type.GetType("System.String")
?
如果有的话,我想知道原因.尽可能深入CLR以证明它.
我的测试显示是,差不多.
结果
配置=释放
baseline: 5572 ticks 2 ms
typeof(Test): 8757 ticks 3 ms
Type.GetType(String): 3899966 ticks 1482 ms
Run Code Online (Sandbox Code Playgroud)
码
[MethodImpl(MethodImplOptions.NoInlining)]
static int Call(Type t)
{
return 1;
}
static void Main(string[] args)
{
const int Iterations = 1000000;
int count;
Stopwatch sw = Stopwatch.StartNew(); count = 0;
for (int i = 0; i < Iterations; i++)
{
count += Call(null);
}
sw.Stop();
Console.WriteLine("baseline: {0} ticks {1} ms", sw.ElapsedTicks, sw.ElapsedMilliseconds);
sw = Stopwatch.StartNew(); count …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来向emails
Azure AD B2C的自定义策略添加声明(电子邮件集合).此应用程序声明可直接从Azure门户获得,但我找不到在我需要创建的自定义策略中实现此方法的方法.
我想要实现的是为我的WebApp用户提供Azure AD B2C身份验证,为员工提供Azure AD身份验证作为自定义身份验证提供程序,这意味着我需要emails
为本地帐户和Azure AD 添加两次声明.
我按照本指南制作自定义策略,因此我添加了一个新ClaimsProvider
的TrustFrameworkExtensions.xml文件.
当我下载在Azure门户中创建的注册和登录策略时,我可以看到以下输出声明:
<OutputClaim ClaimTypeReferenceId="emails" />
Run Code Online (Sandbox Code Playgroud)
我试图将该行添加到我的自定义策略中,但它不会返回emails
声明.
有任何想法吗?
下午好,
我有一个使用 linqdatasource + 实体框架 iqueryable 查询填充的列表视图。
该查询使用如下所示的 take(t-sql 上的 top):
context.Categories().OrderBy(c=>c.Name).Take(20);
Run Code Online (Sandbox Code Playgroud)
它为我提供了我想要按名称排序的 20 条记录。
现在我想按随机顺序显示这 20 条记录。完成此任务的最佳方法是什么?
当您使用应用程序的当前配置文件时,从使用System.Configuration.NameValueSectionHandler定义的部分的配置文件中获取值很容易.
示例配置文件.
<configuration>
<configSections>
<section name="MyParams" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<MyParams>
<add key="FirstParam" value="One"/>
<add key="SecondParam" value="Two"/>
</MyParams>
</configuration>
Run Code Online (Sandbox Code Playgroud)
示例代码,可以轻松读取它.
NameValueCollection myParamsCollection =
ConfigurationManager.GetSection("MyParams") as NameValueCollection;
Run Code Online (Sandbox Code Playgroud)
这是不起作用的代码.
NameValueCollection collection =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
.GetSection("MyParams") as NameValueCollection;
Run Code Online (Sandbox Code Playgroud)
在编译时失败并出现以下错误.
无法通过引用转换,装箱转换,拆箱转换,换行转换或空类型转换将类型'System.Configuration.ConfigurationSection'转换为'System.Collections.Specialized.NameValueCollection'.
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)返回System.Configuration.Configuration,Configuration.GetSection返回ConfigurationSection.
ConfigurationManager.GetSection返回对象.
那么,当我必须使用OpenExeConfiguration时,如何取回我的NameValueCollection?
我有一个非常大的sql文件,我想分成批处理执行.我想确保我以与SSMS和SQLCMD相同的方式解析它.
微软有一个很棒的混合模式程序集,名为Microsoft.SqlServer.BatchParser,它有一个名为Parser的类,它可以像它一样接缝.
它希望在调用Parse()之前将IBatchSource的实现作为SetBatchSource的参数.
我在哪里可以找到IBatchSource的实现,以及有关如何使用此功能的更多信息?
Windows 8附带了一个新字体Segoe UI Symbol.该字体有许多图标,范围为U + E000 - U + EF013,可用于为Windows商店构建应用程序时的按钮.
这些符号的名称列表在哪里?
有很多关于这个主题的帖子,但似乎没有一个名单.
Jeremy Likeness Windows 8图标:Segoe UI符号
Jeremy Foster Windows 8 App Bar图标(来自Segoe UI)
Jerry Nixon Windows 8:已经安装了1,000个Metro图标
我需要知道如何更新和删除数据库中的记录.我知道如何添加记录但无法更新和删除数据库中的记录.
namespace Ex.Models
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class MyEntities : DbContext
{
public MyEntities()
: base("name= MyEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Friend> Friend { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
-
控制器
// POST: /Home/Edit/5
[HttpPost]
public ActionResult Edit(int id, Friend f)
{
try
{
// TODO: Add update logic here
myEntities.Friend.Attach(f);// Doesn't work.. How to update ?
myEntities.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
} …
Run Code Online (Sandbox Code Playgroud) 我需要将此特定JSON字段提取到Visual Studio中的性能测试参数中:
"ExamAnswerId":"757a3735-e626-412b-934c-e577c6963d51"
当我尝试通过右键单击响应并单击"添加提取规则"手动执行此操作时,会出现此问题.文本被分成3个不同的行,旁边有许多不可读的数字,如下所示:"0x00000000 7B 22 45 78 61 6D 41 6E 73 77 65 72 49 64 22 3A {"ExamAnswerId":0x00000010 22 37 35 37 61 33 37 33 35 2D 65 36 32 36 2D 34"757a3735-e626-4
这听起来愚蠢的,但我有点需要提取3个不同的参数,只是因为我不能复制/粘贴 - 这也是在那里,我想我会失败.
ExamAnswerId对于我以后填写另一个webrequest很重要,但我似乎无法正确传递它.
所有输入都非常感谢!
我想将 Dictionary 的参数传递给方法。
public static void Method(Dictionary<string, string> hash)
Run Code Online (Sandbox Code Playgroud)
我真的很想使用内联集合初始值设定项
这是不合法的
Method({{"Foo", "Bar"}, {"Bing", "Bong"}})
Run Code Online (Sandbox Code Playgroud)
这也不是
Method(new {{"Foo", "Bar"}, {"Bing", "Bong"}})
Run Code Online (Sandbox Code Playgroud)
这是
// outside the class
using D = System.Collections.Generic.Dictionary<string, string>;
// calling with the type alias
Method(new D {{"Foo", "Bar"}, {"Bing", "Bong"}})
Run Code Online (Sandbox Code Playgroud)
这也是
// once in a library somewhere
class SD : System.Collections.Generic.Dictionary<string, string> {}
// calling with the class
Method(new SD {{"Foo", "Bar"}, {"Bing", "Bong"}})
Run Code Online (Sandbox Code Playgroud)
你有一个像这样的我不知道的好快捷方式来解决我的类型集合初始化吗?
.net ×4
c# ×4
asp.net ×2
algorithm ×1
asp.net-mvc ×1
azure-ad-b2c ×1
fonts ×1
identity-experience-framework ×1
json ×1
parsing ×1
sorting ×1
sql-server ×1
t-sql ×1
windows-8 ×1