- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这已经困扰了我几个小时,所以我想知道是否有人可以帮助我,因为我可能以错误的方式思考这个问题。
我希望能够从具有无限宽度和高度的网格上的一组 x 和 y 坐标中获取一个 bool 值。还有其他限制,沿着 x 轴,两个真值之间至少需要 n 个位置,我还需要知道从 0,0 到 x,y 的区域中真值的数量。
给定 getTrueCoordinatesInArea 的区域的宽度和高度等于 x 和 y,因为它的区域是从 0,0 到 x,y 创建的
如果这是有道理的..
例如:
value = coordinateContainsTrue( x, y );//return true or false.
total = getTrueCoordinatesInArea( x , y );//Returns the total true values inside the area.
编辑:这会产生种子。
最佳答案
我不是很清楚您需要什么,但我认为这听起来像是一个很好且有趣的练习。我希望这是你想要的。 =) 它没有按照我想要的方式编码。宁愿使用 bool[,] 数组,但不知道如何使它动态化,也不想为此编写我自己的类,但也许我应该这样做。
但是,这个解决方案应该可行。
private List<List<bool>> grid = new List<List<bool>>();
private int N = 4;
Random randomNumberGenerator = new Random();
private bool getRandomBoolean()
{
return this.randomNumberGenerator.Next(0, 2) == 1;
}
private void testProgram()
{
var containsTrue = coordinateContainsTrue(0, 10);
var total = getTrueCoordinatesInArea(14, 2);
var isTrue = coordinateIsTrue(15, 11);
}
private bool coordinateIsTrue(int x, int y)
{
expandGridOfNeeded(x, y);
return grid[x][y];
}
private bool coordinateContainsTrue(int x, int y)
{
expandGridOfNeeded(x, y);
for (int xTemp = 0; xTemp < x; xTemp++) // Loop columns
{
for (int yTemp = 0; yTemp < y; yTemp++) // Loop rows
{
if (grid[xTemp][yTemp])
return true; // Return true if any true was found
}
}
return false;
}
private int getTrueCoordinatesInArea(int x, int y)
{
expandGridOfNeeded(x, y);
var total = 0;
for (int xTemp = 0; xTemp < x; xTemp++) // Loop columns
{
for (int yTemp = 0; yTemp < y; yTemp++) // Loop rows
{
if (grid[xTemp][yTemp])
total++; // Increase count if true was found
}
}
return total;
}
private void expandGridOfNeeded(int x, int y)
{
if (x < 0 || y < 0)
return;
// Add needed columns
while (grid.Count <= x)
{
var column = new List<bool>();
// Only add rows if the others have rows
if (grid.Count > 0)
{
while (column.Count < grid[0].Count)
{
// Check if legal to add a true value, if it is then add random else add false
bool forceFalseValue = false;
for (int i = grid.Count - 1; i > grid.Count + N && forceFalseValue == false; i--)
{
forceFalseValue = grid[i][column.Count - 1];
}
column.Add(forceFalseValue ? false : getRandomBoolean());
}
}
grid.Add(column);
}
// Add needed rows
while (grid[0].Count <= y)
{
var counter = N;
foreach (var column in grid)
{
// Check if legal to add a true value, if it is then add random else add false
if (counter < N)
{
column.Add(false);
counter++;
}
else
{
var randomValue = getRandomBoolean();
if (randomValue)
counter = 0;
else
counter++;
column.Add(randomValue);
}
}
}
}
关于c# - 种子随机绘制二维网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14774303/
Sequelize 中有没有办法添加另一列,然后用另一列的内容填充它? 最佳答案 您可以使用迁移来做到这一点。 就像是 queryInterface.addColumn( 'MyAwesomeTa
如何计算info_hash参数?又名对应于信息字典的哈希?? 来自官方规范: info_hash The 20 byte sha1 hash of the bencoded form of the i
是否可以直接从数据库或服务等将 URL 获取到 Nutch。我对从数据库或服务获取数据并将其写入 Seed.txt 的方式不感兴趣. 最佳答案 没有。这不能直接使用默认的 nutch 代码库来完成。需
MessageDigest 类实现了 SHA-1 算法(以及许多其他算法)。 SHA-1 算法允许使用不同的“种子”或初始摘要。参见 SHA-1 Psuedocode 算法初始化变量,或种子: Ini
我想创建一个应用程序,其中登录密码可以作为伪随机数生成器的种子以重新创建加密 key 。然后,该加密 key 将用于加密发送到应用程序数据库和从应用程序数据库发送的所有数据,使用户数据甚至主机都无法访
这个问题在这里已经有了答案: Recommended way to initialize srand? (15 个答案) 关闭 8 年前。 使用 srand(time(NULL))似乎过于确定性。例
我在获取要在我的自定义数据库初始值设定项上调用的 Seed 方法时遇到问题。我正在使用 EF 5.0 并具有以下代码: public static class MyDatabase { pub
是否可以像在 Rails 中那样“播种”数据库?我想将种子与图像对象管理器结合使用,以便我可以按标题获取记录。 最佳答案 根据您对 Ingo 的回答留下的评论,您想将 requireDefaultRe
我现在设置了一个应用程序来使用 EF6 代码优先迁移。我使用 Add-Migration 的标准工作流程,然后在控制台中使用 Update-Database。我在本地以及我们的开发环境中使用 Migr
如果 Name 返回然后删除 first name Name john Age 30 Name Alice Name Travis Age 12 Name Monty Name Hannah 期望的输
在迁移完成后,是否可以在我的迁移中放入一些东西来自动为表播种测试数据? 或者您必须单独播种? 最佳答案 您可以使用 --seed 选项调用 migrate:refresh 以在迁移完成后自动播种: p
我正在尝试使用不同的种子生成 scipy.stats.pareto.rvs(b, loc=0, scale=1, size=1)。 在 numpy 中,我们可以使用 numpy.random.seed
我的种子有问题。这是我的表结构: 1.Complaints: Schema::create('complaints', function (Blueprint $table) {
我在使用数据库初始化程序时遇到问题 - 从未调用过种子方法。类似的代码在另一个项目中工作,所以我很困惑为什么他们这次不工作。 这是我的代码: RecipeContext.cs public c
我正在尝试做一些我认为非常简单的事情,只需使用 RAND 创建 0-1 之间的随机数,并将其分配给十进制变量。但每次我在 MySQL 中运行代码时,它都会返回零! 参见下面的代码: DELIMITER
我有一个问题...... 这里我们得到了一个二维字节数组: byte[][] duengonMap = new byte[500][500]; 因为我想将它从客户端发送到服务器或者相反,我需要将其放入
我尝试在我的计算机上运行 Angular-seed(Windows 10,上次更新)https://github.com/angular/angular-seed 。网络工作正常,但我的 Protra
我有一个随机过程的分布式过程。因此,我使用 numpy.random.RandomState 来播种数字。问题是我必须在包装器中使用另一个 numpy.random 函数。现在我失去了种子的再现性,因
我需要确保我程序中的所有随机性都是完全可复制的。我应该在哪里调用 random.seed()? 我认为它应该在我的 main.py 模块中,但它导入了碰巧使用随机函数的其他模块。 我可以仔细浏览我的导
首先尝试使用 Entity Framework 和代码在 ASP.NET 网络应用程序中植入数据。我将这段代码放在 Configuration.cs 文件的 Seed() 方法中。现在,我正在处理解决
我是一名优秀的程序员,十分优秀!