我在算法设计中有一个关于复杂性的问题.在这个问题中给出了一段代码,我应该计算这段代码的复杂性.伪代码是:
for(i=1;i<=n;i++){
j=i
do{
k=j;
j = j / 2;
}while(k is even);
}
Run Code Online (Sandbox Code Playgroud)
我为一些数字尝试了这个算法.我得到了不同的结果.例如,如果n = 6,则该算法输出如下所示
i = 1 -> executes 1 time
i = 2 -> executes 2 times
i = 3 -> executes 1 time
i = 4 -> executes 3 times
i = 5 -> executes 1 time
i = 6 -> executes 2 times
Run Code Online (Sandbox Code Playgroud)
它没有常规主题,我该如何计算呢?
我在ASP MVC.NET项目中读过一篇关于忽略某些url机器人的文章.在他的文章中,作者说我们应该在这样的一些off控制器中添加一些动作.在此示例中,他将操作添加到Home Controller:
#region -- Robots() Method --
public ActionResult Robots()
{
Response.ContentType = "text/plain";
return View();
}
#endregion
Run Code Online (Sandbox Code Playgroud)
然后我们应该在我们的项目中添加一个Robots.cshtml文件
@{
Layout = null;
}
# robots.txt for @this.Request.Url.Host
User-agent: *
Disallow: /Administration/
Disallow: /Account/
Run Code Online (Sandbox Code Playgroud)
最后我们应该将这行代码添加到 Gloabal.asax
routes.MapRoute("Robots.txt",
"robots.txt",
new { controller = "Home", action = "Robots" });
Run Code Online (Sandbox Code Playgroud)
我的问题是机器人是否抓取了具有[授权]属性的控制器Administration
?
我在yii2中定义了一个名为`admin'的模块.我已在web.php配置文件中注册了此模块.但是当我尝试访问它时,我面临一个错误.
这是我的web.php
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'language'=>'fa_ir',
'bootstrap' => ['log'],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'SiMhYyhP2MZ_BAi321KfDHFk5uleQFa9',
],
'jdate' => [
'class' => 'jDate\DateTime'
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => …
Run Code Online (Sandbox Code Playgroud) 我在yii2有一个模型
<?php
namespace app\models;
/**
* This is the model class for table "car_ad".
*
* @property integer $id
* @property integer $brand_id
* @property integer $sub_brand_id
* @property integer $sell_type
* @property integer $year
* @property integer $the_function
* @property integer $fuel_type_id
* @property integer $gearbox
* @property integer $sell_mode
* @property integer $real_price
* @property integer $prepayment
* @property integer $installment_price
* @property integer $no_installments
* @property integer $delivery_time_id
* @property integer $installments_period
* @property integer $body_status_id
* …
Run Code Online (Sandbox Code Playgroud) 我想统计我的 Yii 2 应用程序中的所有在线用户,您的解决方案是什么?
甚至我想计算经过身份验证的用户。一种解决方案是在登录时使用身份验证方法,登录后我在 db 中设置了一条记录。但在这里我有一个问题。我应该如何确定用户何时离线?如果我在注销操作中更改在线标志,则会出现一些问题。也许有些用户没有登录就关闭了浏览器。然后数据库将显示他在线。这个问题的最佳解决方案是什么?
编辑
我的问题是如何超越会话过期方法。不更改过期时间。更详细地说,我想确定用户是否处于离线状态,即使他在没有注销操作的情况下关闭了浏览器
关于数组的算法设计我有一个问题,应该用C语言实现.假设我们有一个有n个元素的数组.为简单起见,n是'2'的幂1, 2, 4, 8, 16 , etc
.我想用(n/2)
元素将它分成两部分.分离的条件是lowest absolute difference between sum of all elements in two arrays
,例如,如果我有这样的阵列(9,2,5,3,6,1,4,7)
将是单独的对这些阵列(9,5,1,3)
和(6,7,4,2)
.第一个数组的元素18
的总和是和第二个数组的元素的总和是19
,差异是1,这两个数组是答案,但是两个数组喜欢(9,5,4,2)
并且(7,6,3,1)
不是答案,因为元素求和的差异是4
我们已经找到的1
.所以4
不是最小的差异.怎么解决这个?谢谢.