如果我有这样的代码
for (long i = 0; i < Long.MAX_VALUE; i++)
{
//do something trivial
}
Run Code Online (Sandbox Code Playgroud)
从理论上讲,循环完成需要多长时间?
让甲分别表示该组正整数,其十进制表示不包含的元件的倒数之和的第0位甲已知为23.10345.
防爆.1,2,3,4,5,6,7,8,9,11-19,21-29,31-39,41-49,51-59,61-69,71-79,81-89, 91-99,111-119,......
然后取每个数的倒数,并总和.
如何通过数字验证?
编写一个计算机程序来验证这个号码.
以下是我迄今为止写的,我需要帮助的边界这个问题,因为目前这需要很长时间才能完成:
Java中的代码
import java.util.*;
public class recip
{
public static void main(String[] args)
{
int current = 0; double total = 0;
while(total < 23.10245)
{
if(Integer.toString(current).contains("0"))
{
current++;
}
else
{
total = total + (1/(double)current);
current++;
}
System.out.println("Total: " + total);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我们有两个未排序的数组,每个数组的长度为n.这些数组包含0-n 100范围内的随机整数.如何找出这两个数组在O(n)/线性时间内是否有任何共同元素?不允许排序.
我正在开发一款游戏,让我们说玩家在位置x = 100,y = 100并且爆炸半径为100个单位时放置炸弹......我很容易在游戏中找到所有"项目"被爆炸的炸弹击中(只需要检查他们与炸弹的距离是否低于100).
但现在我想考虑到我在游戏中遇到的障碍,障碍物是正方形,总是64*64像素,总是与轴对齐(不旋转)..我想知道一个项目是否"隐藏"背后知道他没被击中的障碍......
这样的事情:
右边的家伙没有被击中,但是底部的家伙被打了,我把灰色打到了打击区域,绿色的区域被隐藏了......
我的想法是:1.找到的所有项目在现场看到,从炸弹的距离越低则100 2.找到场景中的所有障碍,从炸弹的距离越低则100.3.计算从线炸弹中心的物品..然后检查线是否与任何障碍物相交,如果没有......你被击中了.
最后,问题1.有没有人有更好的主意?2.有免费的开源c#兼容引擎可以帮助我吗?Box2d可以帮到我吗?
谢谢
math collision-detection game-physics computational-geometry
public class AES {
public String getEncrypt(String pass){
String password = encrypt(pass);
return password;
}
public String getDecrypt(String pass){
String key = "AesSEcREtkeyABCD";
byte[] passwordByte = decrypt(key,pass);
String password = new String(passwordByte);
return password;
}
private byte[] decrypt(String key, String encrypted) {
try {
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(skeySpec.getEncoded(), "AES"));
//getting error here
byte[] original = cipher.doFinal(encrypted.getBytes());
return original;
} catch (IllegalBlockSizeException ex) {
ex.printStackTrace();
} catch (BadPaddingException ex) {
ex.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 BouncyCastle PGP SDK 解密 PGP 加密字符串。
我尝试了几种方法,在每种情况下,我都会在过程开始时遇到以下错误(具体位置如下所示):
流 47 中的未知对象
到目前为止,我已经尝试了两个 nuget 包:
我尝试了两篇文章中介绍的方法:
我尝试了三种获取测试密钥和加密字符串的方法:
目前我的代码如下所示:
public void DecryptFile(string inputFilePath, string outputPath)
{
using (FileStream fsEncryptedFile = File.Open(inputFilePath, FileMode.Open))
using (Stream decoderStream = PgpUtilities.GetDecoderStream(fsEncryptedFile))
{
PgpObjectFactory factory = new PgpObjectFactory(decoderStream);
PgpObject obj = factory.NextPgpObject(); //<-- ERROR THROWN HERE
if (!(obj is PgpEncryptedDataList))
{
obj = factory.NextPgpObject();
}
PgpEncryptedDataList edl = obj as PgpEncryptedDataList;
foreach (PgpPublicKeyEncryptedData data in edl.GetEncryptedDataObjects()) …Run Code Online (Sandbox Code Playgroud) 我有一个 python 项目,我使用该标志将应用程序作为模块执行-m。所以像这样:
python -m apps.validate -i input.mp4
Run Code Online (Sandbox Code Playgroud)
现在,我想使用命令行对其进行分析。因此,内联示例建议将 cProfile 本身调用为一个模块。但是,我不能做类似的事情:
python -m cProfile apps.validate -i input.mp4
Run Code Online (Sandbox Code Playgroud)
但是,这会导致错误“没有这样的文件或目录”。由于相对导入,我不能直接进入apps目录并启动。validate.py
有没有办法在命令行上分析模块?
我用谷歌搜索并搜索了几个小时如何在jsp或servlet中进行重定向.但是,当我尝试应用它时,它不起作用.
我在jsp页面中的代码:
<%
String articleId = request.getParameter("article_id").toString();
if(!articleId.matches("^[0-9]+$"))
{
response.sendRedirect("index.jsp");
}
%>
Run Code Online (Sandbox Code Playgroud)
我知道从调试regexp工作,如果任何时候,articleId不是数字,if内部,但当它到达response.sendRedirect时,它实际上不会重定向.
在这种情况下,我是否会错过一些非常基础
提前致谢.
在Android上,我有一个webView.我正在加载url它.首先,我得到一个登录页面,Facebook在填写登录详细信息后,它给了我一个JSON Response相同的webView.
我正在使用此代码来加载它,URL但现在我不知道如何JSON Response在string我完成的内容中得到它url.
WebViewClient yourWebClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
wb.loadUrl("javascript:window.HTMLOUT.processHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
}
};
wb = (WebView) findViewById(R.id.webview);
wb.getSettings().setJavaScriptEnabled(true);
wb.getSettings().setSupportZoom(true);
wb.getSettings().setBuiltInZoomControls(true);
wb.setWebViewClient(yourWebClient);
wb.loadUrl("http://pqrs.abcde.com/facebook");
Run Code Online (Sandbox Code Playgroud)
格式JSON Response是:
{"status":"success","msg":"You have successfully logged in."}
Run Code Online (Sandbox Code Playgroud) 所以我有一个方法有3种不同类型的参数可以进来:
Int32,Int和Double.因此,我们的想法是使用泛型来最小化界面
func resetProgressBarChunks<T:Numeric>(originalIterationCount: T) {
guard let iCount = originalIterationCount as? Double else {return}
Run Code Online (Sandbox Code Playgroud)
但我已经意识到了什么,是在运行时,Int32和Int论据实际上是失败guard let.这是有道理的,这只是我的一厢情愿.
但是,如果我尝试简单地将一个Numeric转换成双精度数,编译器将会吠叫:
func resetProgressBarChunks<T:Numeric>(originalIterationCount: T) {
guard let iCount = Double(originalIterationCount) else {return}
Run Code Online (Sandbox Code Playgroud)
无法使用类型为"(T)"的参数调用类型为"Double"的初始值设定项
我认为这也是有道理的,因为没有Double的初始化程序需要Generic.
所以看起来我将被迫用不同的参数类型编写3个方法.在Int32和Int参数的类型,将只投入Double,然后调用Double方法.这真的是最好的方式吗?我真的希望我能Numeric以某种方式利用