Example #1
0
void Light::drawTriangle(sf::RenderWindow* win, Point L, Point A, Point B, sf::Color C, std::vector<Line > giv)
{
    std::vector<Line > line;
    if(giv.size()==0)   line = tab;
    else                line = giv;
    Point des = L+mn(A+B, 100);
    int num=1;
    double dis = 1000000;
    for(int k=0;k<line.size();k++)
    {
        if(cross(L,des,line[k].first,line[k].second))
        {
            if(dist(L,crossPoint(L,des,line[k].first,line[k].second))<dis)
            {
                num = k;
                dis = dist(L,crossPoint(L,des,line[k].first,line[k].second));
            }
        }
    }
    Point p1 = crossPoint(L,L+mn(A, 100),line[num].first,line[num].second);
    Point p2 = crossPoint(L,L+mn(B, 100),line[num].first,line[num].second);
    sf::ConvexShape convex;
    convex.setPointCount(3);
    convex.setPoint(0, L);
    convex.setPoint(1, p1);
    convex.setPoint(2, p2);
    convex.setFillColor(C);
    //convex.setTexture(this->drawTexture(L,p1,p2,C,100));
    win->draw(convex);
}
int main()
{
	long i,s;
	s=0;
	scanf("%s",a);
	scanf("%s",b);
	scanf("%s",c);
	la=strlen(a);
	lb=strlen(b);
	lc=strlen(c);
	lab=mx(la,lb);
	if (lc<lab)
	{
		printf("-1\n");
		return 0;
	}
	if ((lc>lab+1))
	{
		printf("-1\n");
		return 0;
	}
	memset(s1,0,sizeof(s1));
	s1[0]=lab;
	for (i=1;i<=lab;i++)
	{
		if (la>i) s1[i]+=(a[la-i]-48);
		if (lb>i) s1[i]+=(b[lb-i]-48);
	}
	s2[0]=lc;
	for (i=1;i<=lc;i++)
	{
		s2[i]=c[lc-i]-48;
	}
	memset(dp,0,sizeof(dp));
	dp[0][0]=0;
	dp[0][1]=100000;
	for (i=1;i<=s1[0];i++)
	{
		dp[0][i]=mn(abs(s1[i]- s2[i]+1)+dp[1][i-1],abs(s1[i]- s2[i])+dp[0][i-1]);
		dp[1][i]=mn(abs(s1[i]-10- s2[i]+1)+dp[1][i-1],abs(s1[i]-10- s2[i])+dp[0][i-1]);
	}
	if (s2[0]>s1[0])
	{
		dp[1][s1[0]]+=abs(s2[s2[0]]-1);
		printf("%ld\n",dp[1][s1[0]]);
	}
	else
	{
		printf("%ld\n",dp[0][s1[0]]);
	}
	return 0;
}
void bhkProxyObject::BuildColBox()
{
	Box3 box; box.Init();
	for (int i = 0;i < pblock2->Count(PB_MESHLIST); i++) {
		INode *tnode = NULL;
		pblock2->GetValue(PB_MESHLIST,0,tnode,FOREVER,i);	
		if (tnode)
		{
			ObjectState os = tnode->EvalWorldState(0);
			Matrix3 wm = tnode->GetNodeTM(0);
			TriObject *tri = (TriObject *)os.obj->ConvertToType(0, Class_ID(TRIOBJ_CLASS_ID, 0));
			if (tri)
			{
				Box3 box2; box2.Init();
				Mesh& mesh = tri->GetMesh();
				CalcAxisAlignedBox(mesh, box2, &wm);
				box += box2;
			}
		}
	}
	BuildBox(proxyMesh, box.Max().y-box.Min().y, box.Max().x-box.Min().x, box.Max().z-box.Min().z);

	MNMesh mn(proxyMesh);
	Matrix3 tm(true);
	tm.SetTranslate(box.Center());
	mn.Transform(tm);
	mn.OutToTri(proxyMesh);

	//proxyPos = box.Center();
	proxyPos = Point3::Origin;
	forceRedraw = true;
}
Example #4
0
  inline void run(Skeleton const& sk)
  {
    quaff::semantic::convert<quaff::tag::process_network_> mn;
    quaff::model::empty_environment en;

    quaff::current_backend.accept(mn(sk,en,quaff::current_backend).network());
  }
Example #5
0
// returns volume
Real computeOBB(const std::vector<Vector3r>& pts, const Matrix3r& rot, Vector3r& center, Vector3r& halfSize){
	const Real inf=std::numeric_limits<Real>::infinity();
	Vector3r mn(inf,inf,inf), mx(-inf,-inf,-inf);
	FOREACH(const Vector3r& pt, pts){
		Vector3r ptT=rot*pt;
		mn=mn.cwiseMin(ptT); 
		mx=mx.cwiseMax(ptT);
	}
Example #6
0
void sn(int start, int n) {
  if(n > 2) {
    sn(start, n/2);
    sn(start + n/2, n/2);
  }
  
  mn(start, n);
}
int main()
{
	long n,k,l,a,b;
	scanf("%ld%ld%ld",&k,&l,&n);
	a=mx(calc(k,l,n),calc(k,0,n-1));
	b=mn(calc2(k,l,n),calc2(0,l,n-1)+3);
	printf("%ld %ld\n",a,b);
	return 0;
}
Example #8
0
bool
Date::isValidDate(std::string s)
{
    std::string mn("january february march april may june july");
    mn += " august september october november december" ;
    Split x_mn(mn);

    s = hdhC::Lower()(s);
    s = hdhC::replaceChars(s, ',', ' ');
    Split x_s(s);

    if( x_s.size() != 3 )
        return false;

    int i_d, i_m, i_y;
    i_d = i_m = i_y = 0;

    for(size_t i=0 ; i < x_s.size() ; ++i )
    {
        if( hdhC::isAlpha(x_s[i]) )
        {
            for(size_t m=0 ; m < x_mn.size() ; ++m )
            {
                if( x_s[i] == x_mn[m].substr(0, x_s[i].size()) )
                {
                    i_m = hdhC::string2Double(x_s[i]) ;
                    break;
                }
            }
        }
        else
        {
            if( hdhC::isDigit(x_s[i]) )
            {
                if( x_s[i].size() > 2 )
                    i_y = hdhC::string2Double(x_s[i]) ;
                else
                    i_d = hdhC::string2Double(x_s[i]) ;
            }
            else
                i_d = hdhC::string2Double(x_s[i]) ;
        }
    }

    bool is=true;
    if( i_d == 0 )
        is=false ;
    if( i_m == 0 )
        is=false ;
    if( i_y == 0 )
        is=false ;

    if(is)
        return true;

    return false;
}
    static int Write(const vnv::structuredGrid<_real>& grid,
    		const std::string fileName)
    {
    	std::string vtkFileName = fileName + ".vtk";

    	unsigned pos;
	    if((pos = fileName.rfind(".vtk")) != std::string::npos &&
	    	fileName.size() - pos == 4)
	    	vtkFileName = fileName;

	    std::ofstream fileVTK(vtkFileName.c_str(), std::ios::out);

	    if(!fileVTK.is_open())
	    {
	        std::cout << std::endl;
	        std::cout << "\tCouldn't create specified file '" << vtkFileName;
	        std::cout << "'." << std::endl;
	        return 1;
	    }


		_real delta;

		delta = grid.getDelta();
		std::vector<_real> mn(3), mx(3);
		unsigned N;

		grid.getLimits(mn[0], mn[1], mn[2], mx[0], mx[1], mx[2]);
	    grid.get(N);

	    fileVTK << "# vtk DataFile Version 3.0" << std::endl;
	    fileVTK << "Generated with Meshchk for Vistrails" << std::endl;
	    fileVTK << "ASCII" << std::endl;
	    fileVTK << "DATASET STRUCTURED_POINTS" << std::endl;
	    fileVTK << "DIMENSIONS " << N << " " << N << " " << N << std::endl;
	    fileVTK << "SPACING " << delta  << " " << delta  << " " << delta  << std::endl;
	    fileVTK << "ORIGIN " << mn[0] << " " << mn[1] << " " << mn[2] << std::endl;
	    fileVTK << "POINT_DATA " << N * N * N << std::endl;
	    fileVTK << "SCALARS " << "ImageFile " << getTypeAsString(T()) << std::endl;
	    fileVTK << "LOOKUP_TABLE " << "default" << std::endl;

    	unsigned i, j, k;
    	for(k = 0; k < N; ++k)
			for(i = 0; i < N; ++i)
				for(j = 0; j < N; ++j)
    			{
    				T value = grid.get(i, j, k);
    				fileVTK << value << " ";
    				if((j+1) % 9 == 0)
    					fileVTK << std::endl;
    			}

	    fileVTK.close();

	    return 0;
    }
Example #10
0
int main(){

    ll n, m, k; scanf("%lld %lld %lld", &n, &m, &k);
    if(n % 2 == 0){puts("0");}
    else{
        ll mn(k * (m  / ((n + 1) / 2)));
        for (ll p = 0; p < n; p++){
            ll x; scanf("%lld", &x);
            if(p % 2 == 0){mn = (mn < x) ? mn : x;}
        }

        printf("%lld\n", mn);
    }

    return 0;
}
Example #11
0
bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, std::string &retErrorMessage) {
    std::string errorMessage;
    std::vector<unsigned char> vchMasterNodeSignature;
    std::string strMasterNodeSignMessage;
    int64_t masterNodeSignatureTime = GetAdjustedTime();

    std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end());
    std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end());

    std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(PROTOCOL_VERSION);

    if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchMasterNodeSignature, keyCollateralAddress)) {
		retErrorMessage = "sign message failed: " + errorMessage;
		LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str());
		return false;
    }

    if(!darkSendSigner.VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, errorMessage)) {
		retErrorMessage = "Verify message failed: " + errorMessage;
		LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str());
		return false;
	}

    bool found = false;
    LOCK(cs_masternodes);
    BOOST_FOREACH(CMasterNode& mn, vecMasternodes)
        if(mn.vin == vin)
            found = true;

    if(!found) {
        LogPrintf("CActiveMasternode::Register() - Adding to masternode list service: %s - vin: %s\n", service.ToString().c_str(), vin.ToString().c_str());
        CMasterNode mn(service, vin, pubKeyCollateralAddress, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyMasternode, PROTOCOL_VERSION);
        mn.UpdateLastSeen(masterNodeSignatureTime);
        vecMasternodes.push_back(mn);
    }

    //send to all peers
    LogPrintf("CActiveMasternode::Register() - SendDarkSendElectionEntry vin = %s\n", vin.ToString().c_str());
    SendDarkSendElectionEntry(vin, service, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyCollateralAddress, pubKeyMasternode, -1, -1, masterNodeSignatureTime, PROTOCOL_VERSION);

    return true;
}
void bhkProxyObject::BuildColOBB()
{
	proxyMesh.FreeAll();
	MeshDelta md(proxyMesh);
	for (int i = 0;i < pblock2->Count(PB_MESHLIST); i++) {
		INode *tnode = NULL;
		pblock2->GetValue(PB_MESHLIST,0,tnode,FOREVER,i);	
		if (tnode)
		{
			ObjectState os = tnode->EvalWorldState(0);
			Matrix3 wm = tnode->GetNodeTM(0);
			TriObject *tri = (TriObject *)os.obj->ConvertToType(0, Class_ID(TRIOBJ_CLASS_ID, 0));
			if (tri)
			{
				Mesh& mesh = tri->GetMesh();
				MeshDelta tmd (mesh);
				md.AttachMesh(proxyMesh, mesh, wm, 0);
				md.Apply(proxyMesh);
			}
		}
	}
	Matrix3 rtm(true);
	Point3 center = Point3::Origin;;
	float udim = 0.0f, vdim = 0.0f, ndim = 0.0f;

	if (proxyMesh.getNumVerts() > 3) // Doesn't guarantee that the mesh is not a plane.
	{
		// First build a convex mesh to put the box around;
		// the method acts oddly if extra vertices are present.
		BuildColConvex();
		CalcOrientedBox(proxyMesh, udim, vdim, ndim, center, rtm);
		BuildBox(proxyMesh, vdim, udim, ndim);
	}

	MNMesh mn(proxyMesh);
	mn.Transform(rtm);
	mn.OutToTri(proxyMesh);

	proxyPos = Point3::Origin;
	forceRedraw = true;
}
Example #13
0
bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, CScript rewardAddress, int rewardPercentage, std::string &retErrorMessage) {
    std::string errorMessage;
    std::vector<unsigned char> vchMasterNodeSignature;
    std::string strMasterNodeSignMessage;
    int64_t masterNodeSignatureTime = GetAdjustedTime();

    std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end());
    std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end());

    std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(PROTOCOL_VERSION) + rewardAddress.ToString() + boost::lexical_cast<std::string>(rewardPercentage);

    if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchMasterNodeSignature, keyCollateralAddress)) {
		retErrorMessage = "sign message failed: " + errorMessage;
		LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str());
		return false;
    }

    if(!darkSendSigner.VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, errorMessage)) {
		retErrorMessage = "Verify message failed: " + errorMessage;
		LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str());
		return false;
	}

    CMasternode* pmn = mnodeman.Find(vin);
    if(pmn == NULL)
    {
        LogPrintf("CActiveMasternode::Register() - Adding to masternode list service: %s - vin: %s\n", service.ToString().c_str(), vin.ToString().c_str());
        CMasternode mn(service, vin, pubKeyCollateralAddress, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyMasternode, PROTOCOL_VERSION, rewardAddress, rewardPercentage); 
        mn.ChangeNodeStatus(false);
        mn.UpdateLastSeen(masterNodeSignatureTime);
        mnodeman.Add(mn);
    }

    //send to all peers
    LogPrintf("CActiveMasternode::Register() - RelayElectionEntry vin = %s\n", vin.ToString().c_str());
    mnodeman.RelayMasternodeEntry(vin, service, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyCollateralAddress, pubKeyMasternode, -1, -1, masterNodeSignatureTime, PROTOCOL_VERSION, rewardAddress, rewardPercentage);

    return true;
}
long st(char map[10],char g)
{
	long i,s;
	bool f=false;
	s=check(map);
	if (s!=0) return s;
	if (g==88) s=-1;
	else s=1;
	for (i=0;i<=8;i++)
	{
		if (map[i]==35)
		{
			map[i]=g;
			if (g==88) s=mx(s,st(map,79));
			else s=mn(s,st(map,88));
			map[i]=35;
			f=true;
		}
	}
	if (f) return s;
	else return 0;
}
int main()
{
	long i,j,s;
	memset(dp,1,sizeof(dp));
	dp[0]=0;
	memset(mir,0,sizeof(mir));
	memset(c,0,sizeof(c));
	memset(nn,0,sizeof(nn));
	scanf("%ld",&n);
	s=0;
	for (i=1;i<=n;i++)
	{
		scanf("%ld",&mir[i]);
		s+=mir[i];
	}
	for (i=1;i<=n;i++)
	{
		crt(i,0,0,0);
	}
	c[1]=1+(3<<(n-2));
	c[2]=3+(1<<(n-1));
	c[3]=7;
	for (i=4;i<=n;i++)
	{
		c[i]=c[i-1]<<1;
	}
	nn[0]=0;
	for (i=0;i<(1<<n);i++)
	{
		for (j=1;j<=n;j++)
		{
			dp[nn[i]|c[j]]=mn(dp[nn[i]|c[j]],dp[nn[i]]+s-ss[nn[i]|c[j]]);
		}
	}
	printf("%ld\n",dp[nn[(1<<n)-1]]);
	return 0;
}
Example #16
0
void BoxTreeInnerNode::recalcBounds(Vector3D& center)
{
  if (m_Boxes.empty()) return;
  center=Vector3D::Zero;
  Vector3D mn(9e9f,9e9f,9e9f),mx(-9e9f,-9e9f,-9e9f);
  for(unsigned i=0;i<m_Boxes.size();i++)
  {
    BoxedTriangle* bt=m_Boxes[i];
    center+=bt->center;
    mn.x=Min(Min(Min(bt->v1.x,bt->v2.x),bt->v3.x),mn.x);
    mn.y=Min(Min(Min(bt->v1.y,bt->v2.y),bt->v3.y),mn.y);
    mn.z=Min(Min(Min(bt->v1.z,bt->v2.z),bt->v3.z),mn.z);
    mx.x=Max(Max(Max(bt->v1.x,bt->v2.x),bt->v3.x),mx.x);
    mx.y=Max(Max(Max(bt->v1.y,bt->v2.y),bt->v3.y),mx.y);
    mx.z=Max(Max(Max(bt->v1.z,bt->v2.z),bt->v3.z),mx.z);
  }
  center/=float(m_Boxes.size());
  m_Pos=mn;
  m_Size=mx-mn;
  if (m_Size.x==0.0f) { m_Size.x=0.002f; m_Pos.x-=0.001f; }
  if (m_Size.y==0.0f) { m_Size.y=0.002f; m_Pos.y-=0.001f; }
  if (m_Size.z==0.0f) { m_Size.z=0.002f; m_Pos.z-=0.001f; }
  m_Center=getPosition()+0.5f*getSize();
}
int main()
{
	long i,j,i1,i2,j1,j2,k1,k2;
	char f1,f2,t1,t2;
	memset(map,50,sizeof(map));
	for (i=f;i<=t;i++)
		for (j=f;j<=t;j++)
		{
			map[i][j][i][j]=0;
			map[i][j][i+1][j+2]=1;
			map[i][j][i-1][j+2]=1;
			map[i][j][i+1][j-2]=1;
			map[i][j][i-1][j-2]=1;
			map[i][j][i+2][j+1]=1;
			map[i][j][i-2][j+1]=1;
			map[i][j][i+2][j-1]=1;
			map[i][j][i-2][j-1]=1;
		}
	for (k1=f;k1<=t;k1++)
		for (k2=f;k2<=t;k2++)
			for (i1=f;i1<=t;i1++)
				for (i2=f;i2<=t;i2++)
					for (j1=f;j1<=t;j1++)
						for (j2=f;j2<=t;j2++)
							map[i1][i2][j1][j2]=mn(map[i1][i2][j1][j2],map[i1][i2][k1][k2]+map[k1][k2][j1][j2]);
	while (scanf("%s",&inp)==1)
	{
		f1=inp[0]-97+f;
		f2=inp[1]-49+f;
		scanf("%s",&inp);
		t1=inp[0]-97+f;
		t2=inp[1]-49+f;
		printf("To get from %c%c to %c%c takes %d knight moves.\n",f1+97-f,f2+49-f,t1+97-f,t2+49-f,map[f1][f2][t1][t2]);
	}
	return 0;
}
Example #18
0
bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, std::string &errorMessage) {
    CMasternodeBroadcast mnb;
    CMasternodePing mnp(vin);
    if(!mnp.Sign(keyMasternode, pubKeyMasternode)){
        errorMessage = strprintf("Failed to sign ping, vin: %s", vin.ToString());
        LogPrintf("CActiveMasternode::Register() -  %s\n", errorMessage);
        return false;
    }
    mnodeman.mapSeenMasternodePing.insert(make_pair(mnp.GetHash(), mnp));

    LogPrintf("CActiveMasternode::Register() - Adding to Masternode list\n    service: %s\n    vin: %s\n", service.ToString(), vin.ToString());
    mnb = CMasternodeBroadcast(service, vin, pubKeyCollateralAddress, pubKeyMasternode, PROTOCOL_VERSION);
    mnb.lastPing = mnp;
    if(!mnb.Sign(keyCollateralAddress)){
        errorMessage = strprintf("Failed to sign broadcast, vin: %s", vin.ToString());
        LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
        return false;
    }
    mnodeman.mapSeenMasternodeBroadcast.insert(make_pair(mnb.GetHash(), mnb));
    masternodeSync.AddedMasternodeList(mnb.GetHash());

    CMasternode* pmn = mnodeman.Find(vin);
    if(pmn == NULL)
    {
        CMasternode mn(mnb);
        mnodeman.Add(mn);
    } else {
        pmn->UpdateFromNewBroadcast(mnb);
    }

    //send to all peers
    LogPrintf("CActiveMasternode::Register() - RelayElectionEntry vin = %s\n", vin.ToString());
    mnb.Relay();

    return true;
}
Example #19
0
TEST(monom, throw_then_set_negative_sv)
{
	monom mn(4, 5, NULL);
	ASSERT_ANY_THROW(mn.setConv(-505));
}
Example #20
0
TEST(monom, can_get_sv)
{
	monom mn(4, 505, NULL);
	int i, j, k;
	ASSERT_NO_THROW(mn.getN(i, j, k));
}
Example #21
0
TEST(monom, can_set_sv)
{
	monom mn(4, 0, NULL);
	int i = 1, j = 3, k = 5;
	ASSERT_NO_THROW(mn.setN(i, j, k));
}
Example #22
0
TEST(monom, can_setnext)
{
	monom mn(4, 5);
	ASSERT_NO_THROW(mn.setnext(NULL));
}
Example #23
0
TEST(monom, can_create_monom)
{
	ASSERT_NO_THROW(monom mn(5, 1, NULL));
}
Example #24
0
TEST(monom, throw_then_create_monom_with_too_large_sv)
{
	ASSERT_ANY_THROW(monom mn(5, 1001, NULL));
}
Example #25
0
bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDoS)
{
    // we are a masternode with the same vin (i.e. already activated) and this mnb is ours (matches our Masternode privkey)
    // so nothing to do here for us
    if(fMasterNode && vin.prevout == activeMasternode.vin.prevout && pubkey2 == activeMasternode.pubKeyMasternode)
        return true;

    // search existing Masternode list
    CMasternode* pmn = mnodeman.Find(vin);

    if(pmn != NULL) {
        // nothing to do here if we already know about this masternode and it's enabled
        if(pmn->IsEnabled()) return true;
        // if it's not enabled, remove old MN first and continue
        else mnodeman.Remove(pmn->vin);
    }

    CValidationState state;
    CMutableTransaction tx = CMutableTransaction();
    CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey);
    tx.vin.push_back(vin);
    tx.vout.push_back(vout);

    {
        TRY_LOCK(cs_main, lockMain);
        if(!lockMain) {
            // not mnb fault, let it to be checked again later
            mnodeman.mapSeenMasternodeBroadcast.erase(GetHash());
            masternodeSync.mapSeenSyncMNB.erase(GetHash());
            return false;
        }

        if(!AcceptableInputs(mempool, state, CTransaction(tx), false, NULL)) {
            //set nDos
            state.IsInvalid(nDoS);
            return false;
        }
    }

    LogPrint("masternode", "mnb - Accepted Masternode entry\n");

    if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){
        LogPrintf("mnb - Input must have at least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS);
        // maybe we miss few blocks, let this mnb to be checked again later
        mnodeman.mapSeenMasternodeBroadcast.erase(GetHash());
        masternodeSync.mapSeenSyncMNB.erase(GetHash());
        return false;
    }

    // verify that sig time is legit in past
    // should be at least not earlier than block when 1000 DASH tx got MASTERNODE_MIN_CONFIRMATIONS
    uint256 hashBlock = 0;
    CTransaction tx2;
    GetTransaction(vin.prevout.hash, tx2, hashBlock, true);
    BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
    if (mi != mapBlockIndex.end() && (*mi).second)
    {
        CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation
        CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS
        if(pConfIndex->GetBlockTime() > sigTime)
        {
            LogPrintf("mnb - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)\n",
                      sigTime, addr.ToString(), vin.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime());
            return false;
        }
    }

    LogPrintf("mnb - Got NEW Masternode entry - %s - %s - %s - %lli \n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime);
    CMasternode mn(*this);
    mnodeman.Add(mn);

    // if it matches our Masternode privkey, then we've been remotely activated
    if(pubkey2 == activeMasternode.pubKeyMasternode && protocolVersion == PROTOCOL_VERSION){
        activeMasternode.EnableHotColdMasterNode(vin, addr);
    }

    bool isLocal = addr.IsRFC1918() || addr.IsLocal();
    if(Params().NetworkID() == CBaseChainParams::REGTEST) isLocal = false;

    if(!isLocal) Relay();

    return true;
}
Example #26
0
TEST(monom, throw_then_set_too_large_sv)
{
	monom mn(505, 0, NULL);
	int i = 10, y = 11, z = 51;
	ASSERT_ANY_THROW(mn.setN(i, y, z));
}
Example #27
0
TEST(monom, throw_then_create_monom_with_negative_sv)
{
	ASSERT_ANY_THROW(monom mn(5, -3, NULL));
}
Example #28
0
TEST(monom, can_setval)
{
	monom mn(0, 1, NULL);
	ASSERT_NO_THROW(mn.setval(5));
}
Example #29
0
TEST(monom, can_getval)
{
	monom mn(2, 3, NULL);
	ASSERT_NO_THROW(mn.GetVal());
}
Example #30
-1
int main(){
  // double r=2.0;
  //  double i=3.0;
Zespolone a=zes(20.0,32.0);
Zespolone b=zes(4.0,4.0);

dod2(&a,&b);
printz(b);
b=zes(4.0,4.0);
a=zes(20.0,32.0);
printz(*dod(a,b));

od2(&a,&b);
printz(b);
b=zes(4.0,4.0);
a=zes(20.0,32.0);
printz(*od(a,b));

mn2(&a,&b);
printz(b);
b=zes(4.0,4.0);
a=zes(20.0,32.0);
printz(*mn(a,b));

dziel2(&a,&b);
printz(b);
b=zes(4.0,4.0);
a=zes(20.0,32.0);
printz(*dziel(a,b));

return 0;}