我是这个论坛的新手,并不太了解这个论坛的协议,所以请原谅我的无知.我的问题与spoj问题https://www.spoj.pl/problems/KPRIMES2/有关.我正在为这个问题获得超时限制.我认为这个程序的瓶颈正在产生10 ^ 9.可能有人建议如何改进这个筛子,更快的方式来生成素数或如何解决这个问题.这是我算法的草图
该程序生成2k + 1形式的所有素数,并将这些素数编码为数组a [i]的32位整数,其中未设置位代表primes.a [0]编码3,5,7 ....... 65 .a [1]编码67以后,依此类推.我有一个辅助数组bitcnt [],其中bitcnt [i]存储[0],[1],......... a [i]的未设置位的总和.我使用bitcnt进行二分搜索并找到第k个数字的位置.这里是函数的位解释.prime()函数生成素数,并且我将素数编码到数字[32位无符号整数]的位上.bitcnt数组存储数组a的未设置位的总和,用于二进制搜索目的.bsearchupper(int m)返回m lie的bitcnt索引.最后在main函数中,我存储了多少素数到m的上限并开始递减值直到我得到K.谢谢.
编辑:SPOJ的问题陈述
输入
一个整数,表示查询数Q(等于100000),Q行跟随,每个包含1到50000000之间的一个整数K(含).
产量
Q行与每个查询的答案:Kth素数.
例
输入:8 1 10 100 1000 10000 100000 1000000 10000000
产量:2 29 541 7919 104729 1299709 15485863 179424673
#include<cstdio>
#include<vector>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#define Lim 1000000000
using namespace std;
unsigned int a[(Lim>>6)+10],bitcnt[(Lim>>6)+10];
int bound;
void prime()
{
int p_1,q_1,p_2,q_2,Ub=sqrt(Lim*1.0);
for(int i=3;i<=Ub;i+=2)
{
p_1=(i-3)>>6,q_1=((i-3)>>1)&31;
if(!(a[p_1] & (1L<<q_1)))
for(int j=i*i;j<Lim;j+=i)
if(j&1)
{
p_2=(j-3)>>6,q_2=((j-3)>>1)&31;
a[p_2]|=(1L<<q_2);
} …Run Code Online (Sandbox Code Playgroud) 我的Windows机器上安装了Ruby 1.8.7和Ruby 1.9.2.
在我的控制台中,当我这样做时,ruby -v它给了我Ruby 1.7.7
现在,当我尝试
gem install rails -v 2.3.8
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
ERROR: http://gems.rubyforge.org/ does not appear to be a repository
ERROR: could not find gem rails locally or in a repository
Run Code Online (Sandbox Code Playgroud)
我的RubyGems版本显示1.3.5,所以我尝试更新它
gem update --system
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
Updating RubyGems
ERROR: http://gems.rubyforge.org/ does not appear to be a repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::E10013: An attempt was made to access a socket in a way forbidden by
its access permissions. - connect(2) (http://gems.rubyforge.org/yaml)`
Run Code Online (Sandbox Code Playgroud)
出了什么问题?
便携式草莓perl是天赐之物 - 我可以将它与实际脚本一起捆绑到NSIS安装程序中并让用户双击它.但是,我仍然需要在每个用户的计算机上手动安装脚本所需的CPAN模块.
是否有一种可移植的方式将cpan模块"注入"草莓perl的便携版本?
将便携式草莓放在开发机器上,通过CPAN安装模块并重新压缩以便分发是不是一个好主意?(我想我需要将安装位置修复为c:\ custom-perl或者如果我这样做的话).谁知道更直接的方式?我想我应该将cpan命令编写到安装程序中,但如果用户不必等待20分钟+安装程序(这是编译所有依赖项所需的时间),那就太好了.
我即将使用Sencha touch开发应用程序.我现在面临的问题是Sencha代码应该读取以下XML("data.xml"并显示新闻,文章...),任何可以帮助的专家都可以吗?
<ns2:categories>
<category>
<catId>96</catId>
<title>News</title>
</category>
<category>
<catId>97</catId>
<title>Articles</title>
</category>
</ns2:categories>
Run Code Online (Sandbox Code Playgroud)
当我点击News作为示例时,应该读取"data_read.xml"中的特定"recordId"元素并显示"origUrl","title","data".the data_read.xml如下所示.
<ns2:records>
<record>
<recordId>96</recordId>
<title>123 Lifted</title>
<author>|</author>
<published>2010-01-20T14:36:00.000-08:00</published>
<origUrl>
http://www.abc.com/</origUrl>
<numComments>0</numComments>
<data>
<![CDATA[<p>According to a report on sd asdas das asdasd asdasd hjjasd .</p>
<p> </p>
<p>This is a landmark vote, and a harbinger of change for this extremely traditional area that also has banned the use of metal r bolt.</p>
<p> </p>
<p>Check out: abc.com and xyz .com for more information.</p>
<p class="modifydate">Last Updated (Wednesday, 20 …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的视图层次结构:
UIView (A)
UIView > UIImageView
UIView > UIView (B)
UIView > UIView (B) > Rounded Rect Button
UIView > UIView (B) > UIImageView
UIView > UIView (B) > UILabel
Run Code Online (Sandbox Code Playgroud)
我已将手势识别器附加到我的UIView(B).我面临的问题是我没有对UIView(B)中的Rounded Rect Button进行任何操作.singleTap手势识别器捕获/覆盖按钮的Touch Up Inside事件.
我怎样才能使它工作?我认为响应者链层次结构将确保按钮触摸事件将被优先使用,并且它将被触发!我错过了什么?
这是一些相关的代码:
#pragma mark -
#pragma mark View lifecycle (Gesture recognizer setup)
- (void)viewDidLoad {
[super viewDidLoad];
// double tap gesture recognizer
UITapGestureRecognizer *dtapGestureRecognize = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapGestureRecognizer:)];
dtapGestureRecognize.delegate = self;
dtapGestureRecognize.numberOfTapsRequired = 2;
[self.viewB addGestureRecognizer:dtapGestureRecognize];
// single tap gesture recognizer
UITapGestureRecognizer *tapGestureRecognize = …Run Code Online (Sandbox Code Playgroud) 我需要以不区分大小写的方式比较两个字段.我有这样的规则:
foo : ObjectTypeA()
bar : ObjectTypeB( name == foo.name )
Run Code Online (Sandbox Code Playgroud)
这适用于相同情况下的字符串.我需要的是这样的东西,但它似乎不起作用:
foo : ObjectTypeA()
bar : ObjectTypeB( name.equalsIgnoreCase( foo.name ) )
Run Code Online (Sandbox Code Playgroud)
有关如何使其工作的任何建议?谷歌搜索点击建议使用"匹配",但匹配运算符似乎只对硬编码模式.
感谢Schermvlieger在anddev.org上提出这个问题,
我只是把他的问题复制到SO,因为没有人在另一个网站上回复,我也面临同样的问题.
我想知道BitmapFactory.Options.inSampleSize关于显示图像的速度的最佳用途是什么.
文档提到使用2的幂的值,所以我正在使用2,4,8,16等.
我想知道的是:
OutOfMemoryError?BitmapFactory对于较大的文件,setImageURI()对于较小的文件)显示图像是否有效.我正在使用一种ImageSwitcher方式.Bitmap,BitmapFactory.Options并inTempStorage在应用程序的开头或只对动态创建它们,在需要的时候?兼职C#程序员在这里试图学习Python.
我希望能够从另一个线程中设置一个将在WxPython中的GUI线程上运行的函数.目前,我能想到这样做的唯一方法是将函数推送到某个跨线程同步列表,然后每隔几毫秒(在GUI线程上)触发一个计时器,该计时器检查列表并运行已推送的任何函数在它上面.我想知道是否有更规范的方式来做这个,类似于BeginInvoke.NET.
我正在使用datagridview,因为我正在使用datagridviewcomboboxcolumn,comboboxcolumn正在显示文本,但问题是我想默认选择第一项comboboxcolumn如何才能这样做
DataGridViewComboBoxColumn dgvcb = (DataGridViewComboBoxColumn)grvPackingList.Columns["PackingUnits"];
Globals.G_ProductUtility G_Utility = new Globals.G_ProductUtility();
G_Utility.addUnittoComboDGV(dgvcb);
DataSet _ds = iRawMaterialsRequest.SelectBMR(bmr_ID, branch_ID, "PACKING");
grvPackingList.DataSource = _ds.Tables[0];
int i = 0;
foreach (DataRow dgvr in _ds.Tables[0].Rows)
{
grvPackingList.Rows[i].Cells["Units"].Value = dgvr["Units"].ToString();
i++;
}
Run Code Online (Sandbox Code Playgroud) 我有一个基类实现INotifyPropertyChanged:
protected void OnNotifyChanged(string pName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(pName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
Run Code Online (Sandbox Code Playgroud)
我有一个派生类,其属性Latitude如下:
private double latitude;
public double Latitude
{
get { return latitude; }
set { latitude = value; OnNotifyChanged("Latitude"); }
}
Run Code Online (Sandbox Code Playgroud)
我的派生类也有一个Fly操作方法Latitude.
我还有一个Form,其TextBox绑定到Latitude我的派生类:
txtLat.DataBindings.Clear();
txtLat.DataBindings.Add("Text", bindSrc, "Latitude");
Run Code Online (Sandbox Code Playgroud)
一个线程用于启动,Fly如下所示:
Thread tFly = new Thread(f.Fly);
tFly.IsBackground = true;
tFly.Start();
Run Code Online (Sandbox Code Playgroud)
当Latitude改变,一个异常被抛出:
DataBinding cannot find a row in the list …