コード例 #1
0
ファイル: 1362.cpp プロジェクト: ZhouWeikuan/zoj
int fun(){
	d.clear();
	int i,ret =0;
	for(i=player*card;i>0;i--){
		if(mask[i] ==0){
			d.push_back(i);
		}
	}
	sort(cards,cards+card,greater<int>());
	for(i=0;i<card;i++){
		if(cards[i] > d[0]){
			ret++;
			for(int j=1;j<player;j++){
				d.pop_back();
			}
		} else {
			d.pop_front();
			for(int j=2;j<player;j++){
				d.pop_back();
			}
		}
	}
	return ret;
}
コード例 #2
0
ファイル: 217.cpp プロジェクト: a00012025/Online_Judge_Code
void solve()
{
    int n,k,A,B ; scanf("%d%d%d%d%s",&n,&k,&A,&B,s+1) ;
    for(int i=1;i<=n;i++) scanf("%d",&val[i]) ;
    fill(dp[0],dp[0]+n+1,-INF) ; dp[0][0]=0 ;
    for(int i=1;i<=k;i++)
    {
        fill(dp[i],dp[i]+n+1,-INF) ;
        dq.clear() ;
        for(int j=A;j<=n;j++)
        {
            while(!dq.empty() && dq.back().id<j-B)
                dq.pop_back() ;
            while(!dq.empty() && dq.front().val<=dp[i-1][j-A])
                dq.pop_front() ;
            dq.push_front((P){j-A,dp[i-1][j-A]}) ;
            dp[i][j]=dq.back().val+i*val[j] ;
            last[i][j]=dq.back().id ;
        }
    }
    printf("Case #%d:\n",++tc) ;
    if(dp[k][n]<0) printf("Sorry, you're milk cheese.\n") ;
    else printf("%d\n",dp[k][n]) , print(k,n) ;
}
コード例 #3
0
int get_partition_from_file_tp_format(string S, deque<deque<int> > & M, bool anyway) {


	// if anyway = true il also takes the homeless
	
	M.clear();
	
	char b[S.size()+1];
	cast_string_to_char(S, b);
	
	ifstream inb(b);
	
	string st;
	while(getline(inb, st)) {
	
		deque<string>  vv;
		separate_strings(st, vv);
		if(st.size()>0 && (vv[0]=="#module" || vv[0]=="#group") ) if(cast_string_to_double(vv[5])<1 || anyway) {
			
			getline(inb, st);

			deque<int> v;
			cast_string_to_doubles(st, v);
			sort(v.begin(), v.end());
			if(!v.empty())
				M.push_back(v);
		}
		
		
	}

	
	return 0;


}
コード例 #4
0
ファイル: msgc.cpp プロジェクト: CyberShadow/FAR
void parse_cmd_line(const deque<wstring>& params, deque<FileNamePair>& files, wstring& header_file) {
  CHECK_CMD(params.size());
  unsigned idx = 0;
  CHECK_CMD(params[idx] == L"-in");
  idx++;
  files.clear();
  FileNamePair fnp;
  while ((idx < params.size()) && (params[idx] != L"-out")) {
    fnp.in = params[idx];
    files.push_back(fnp);
    idx++;
  }
  CHECK_CMD(files.size());
  CHECK_CMD(idx != params.size());
  idx++;
  CHECK_CMD(idx != params.size());
  header_file = params[idx];
  idx++;
  for (unsigned i = 0; i < files.size(); i++) {
    CHECK_CMD(idx != params.size());
    files[i].out = params[idx];
    idx++;
  }
}
コード例 #5
0
void ELAS::clear_buffers() {
	esqBuffer.clear();
	esqBufferRejeitados.clear();
	dirBuffer.clear();
	dirBufferRejeitados.clear();
}
コード例 #6
0
ファイル: wenx.cpp プロジェクト: bestdpf/poj
int main(){
	int width;
	int indexinfo=-1;
	int indexans=0;
	int j;

	while(1){
		scanf("%d",&width);
		printf("%d\n",width);
		if(width==0)
			break;
		indexinfo=-1;
		indexans=0;
		pr tmp;

		int nowpos=width;

		tmp.first=0;tmp.second=width;
		zero.clear();zero.push_back(tmp);

		while(1){
			scanf("%d%d",&p1,&p2);
			if(p1==p2&&p2==0)
				break;

			while(p2!=0){
				if(nowpos==width){
					nowpos=0;
					indexinfo++;
					info[indexinfo].floors=p2/width;
					info[indexinfo].list.clear();
					if(p2>=width){
						//we can store more than 1 floor in an struct info.
						tmp.first=p1;
						tmp.second=width;
						info[indexinfo].list.push_back(tmp);
						p2%=width;
						nowpos=width;
					}else{
						tmp.first=p1;
						tmp.second=p2;
						info[indexinfo].list.push_back(tmp);
						nowpos+=p2;
						p2=0;
					}
				}else{
					if(nowpos+p2>width){
						tmp.first=p1;
						tmp.second=width-nowpos;
						p2-=width-nowpos;
						nowpos=width;
						info[indexinfo].list.push_back(tmp);
					}else{
						tmp.first=p1;
						tmp.second=p2;
						nowpos+=p2;
						p2=0;
						info[indexinfo].list.push_back(tmp);
					}
				}
			}
		}//Input finished

		for(i=0;i<=indexinfo;i++){
			if(i==0)
				tmpanstop=zero;
			else{
				tmpanstop=compare1(-1,i,1);
				tmpanstop=combine(compare1(0,i,0),tmpanstop);
				tmpanstop=combine(compare1(1,i,-1),tmpanstop);
			}

			if(info[i].floors){
				tmpansmid=zero;
			}else{
				tmpansmid=compare2(i);
			}

			if(i==indexinfo)
				tmpansbot=zero;
			else{
				tmpansbot=compare1(-1,i+1,-1);
				tmpansbot=combine(compare1(0,i+1,0),tmpansbot);
				tmpansbot=combine(compare1(1,i+1,1),tmpansbot);
			}

			if(info[i].floors<=1){
				tmpansbot=combine(tmpansbot,tmpansmid);
				tmpansbot=combine(tmpansbot,tmpanstop);
				ans[indexans].floors=0;
				ans[indexans].list=tmpansbot;
				indexans++;
			}else{
				ans[indexans].floors=0;
				ans[indexans].list=tmpanstop;
				indexans++;

				if(info[i].floors>2){
					ans[indexans].floors=info[i].floors-2;
					ans[indexans].list=zero;
					indexans++;
				}

				ans[indexans].floors=0;
				ans[indexans].list=tmpansbot;
				indexans++;
			}
		}

		tmp.first=ans[0].list[0].first;
		tmp.second=0;

		for(i=0;i<indexans;i++){
			if((tmp.first!=ans[i].list[0].first)&&(tmp.second!=0)){
				printf("%d %d\n",tmp.first,tmp.second);
				tmp.second=0;
			}

				if(ans[i].floors>=1){
					tmp.first=ans[i].list[0].first;
					tmp.second+=ans[i].floors*width;
				}else{
					for(j=0;j<ans[i].list.size();j++){
						if((tmp.first!=ans[i].list[j].first)&&(tmp.second!=0)){
							printf("%d %d\n",tmp.first,tmp.second);
							tmp.second=0;
						}
						tmp.first=ans[i].list[j].first;
						tmp.second+=ans[i].list[j].second;
					}
				}
		}
		if(tmp.second>0)
			printf("%d %d\n",tmp.first,tmp.second);
		printf("%d %d\n",0,0);
	}
	return 0;
}
コード例 #7
0
ファイル: sereja.cpp プロジェクト: shashwat001/Codechef
int main()
{
	int n,b,maxm,minm,minidx,maxidx;
	int a[100001];
	lli p=1;
	n = readInt();
	for(i = 0;i < n;i++)
	{
		a[i] = readInt();
	}
	for(i = 2;i <= n;i++)
	{
		//minm = INF;
		//maxm = 0;
		dmin.clear();
		dmax.clear();
		dmin.push_front(mp(a[0],0));
		dmax.push_front(mp(a[0],0));
		for(j = 1;j < i;j++)
		{
			while(!dmin.empty())
			{
				if((a[j] <= dmin.back().first)|| ((j - dmin.back().second) >= i))
				{
					dmin.pop_back();
				}
				else
				{
					break;
				}
			}
			while(!dmin.empty())
			{
				if(a[j] <= dmin.front().first ||  ((j - dmin.front().second) >= i))
				{
					dmin.pop_front();
				}
				else
				{
					break;
				}
			}
			dmin.push_front(make_pair(a[j],j));
			
			
			while(!dmax.empty())
			{
				if((a[j] >= dmax.back().first)|| ((j - dmax.back().second) >= i))
				{
					dmax.pop_back();
				}
				else
				{
					break;
				}
			}
			while(!dmax.empty())
			{
				if(a[j] >= dmax.front().first ||  ((j - dmax.front().second) >= i))
				{
					dmax.pop_front();
				}
				else
				{
					break;
				}
			}
			dmax.push_front(make_pair(a[j],j));		
		}
		p = (p*(dmax.back().first-dmin.back().first))%MOD;
		for(j = j;j < n;j++)
		{
			while(!dmin.empty())
			{
				if((a[j] <= dmin.back().first)|| ((j - dmin.back().second) >= i))
				{
					dmin.pop_back();
				}
				else
				{
					break;
				}
			}
			while(!dmin.empty())
			{
				if(a[j] <= dmin.front().first ||  ((j - dmin.front().second) >= i))
				{
					dmin.pop_front();
				}
				else
				{
					break;
				}
			}
			dmin.push_front(make_pair(a[j],j));
			
			
			while(!dmax.empty())
			{
				if((a[j] >= dmax.back().first)|| ((j - dmax.back().second) >= i))
				{
					dmax.pop_back();
				}
				else
				{
					break;
				}
			}
			while(!dmax.empty())
			{
				if(a[j] >= dmax.front().first ||  ((j - dmax.front().second) >= i))
				{
					dmax.pop_front();
				}
				else
				{
					break;
				}
			}
			dmax.push_front(make_pair(a[j],j));		
			
			p = (p*(dmax.back().first-dmin.back().first))%MOD;
		}
	}
	printf("%lld\n",p);
	return 0;
}
コード例 #8
0
 void clearItems()
 {
     p.clear();
     H.clear();
 }
コード例 #9
0
ファイル: naive.cpp プロジェクト: Zubeen/CIS501
 void reset(int n)
 {
     q.clear();
     maxMicroOps = n;
 }
コード例 #10
0
ファイル: main.cpp プロジェクト: mdyang/oj-solutions
const bigint bigint::operator=(const bigint& a){
    _digits.clear();
    for(int i=0;i<a._digits.size();i++)_digits.push_back(a._digits[i]);
    return *this;
}
コード例 #11
0
ファイル: 10070.cpp プロジェクト: bhrzslm/practice
void convertToDeque(const string& str, deque<unsigned int>& d){
  d.clear();
  for (string::const_iterator itr = str.begin(), endItr = str.end(); itr != endItr; itr++)
    if ((*itr) >= 48 && (*itr) <= 57)
      d.push_back((int) (*itr) - 48);
}
コード例 #12
0
ファイル: perms.c プロジェクト: amitchhajer/Codesprint
int main()
{
    long i=0,j=0,nsc=0,temp;
    scanf("%ld",&n);
    long N1[MAX*MAX][2]={0,-1};
    //long Ns[MAX][2];
    //long NS[51][3]={0,0,0};
    for(i=0;i<n*n;i++)
    {
      scanf("%ld", &N[i]);
      if(i/n!=i)
      {
        N1[i][0]=N[i];
        N1[i][1]=i;
       }
    }
    
    for(i=0;i<MAX;i++)
     {
        for(j=0;j<n*n;j++)
        {
            //if(j/n!=j||!(i*j))
            {
                if(N1[j][0]<N1[j+1][0])
                {
                    temp=N1[j][0];
                    N1[j][0]=N1[j+1][0];
                    N1[j+1][0]=temp;
                    
                    temp=N1[j][1];
                    N1[j][1]=N1[j+1][1];
                    N1[j+1][1]=temp;
                    
                    
                }
            }
        }
     }
     int px,py;
     for(i=0;i<MAX;i++)
     {      
            //long st=0;
            //long sm=0;
            px=N1[i][1]/n;
            py=N1[i][1]%n; 
            a.push_front(px);
            a.push_back(py);
            for(j=0;j<n;j++)
            {   if(j!=px&&j!=py)
                {
                    if(N[pos(j,px)]>N[pos(py,j)])
                    {
                        a.push_front(j);  
                    }
                    else
                    {
                        a.push_back(j);  
                    }
                }
            }
            if(b.empty()==true)
            {
                b=a;
            }
            else
            {
                if(sum(a)>sum(b))
                {
                    b=a;
                }
            }
            a.clear();
     }          
 
        
         while(b.empty()==false)
        {   
            cout<<b.front()<<" ";
            b.pop_front();
           
         }
       
    return 0;
}
コード例 #13
0
			void clear() {
				list.clear();
			}
コード例 #14
0
ファイル: wiBackLog.cpp プロジェクト: turanszkij/WickedEngine
	void clear() 
	{
		logLock.lock();
		stream.clear();
		logLock.unlock();
	}
コード例 #15
0
ファイル: FFTTracer.cpp プロジェクト: bimyoo/AudioVisualApps
 void clear() {
     points.clear();
 }
コード例 #16
0
int main(int argc, char* argv[])
{
	srand((unsigned int)time(0));

	int xres = 1024;
	int yres = 768;

	bool usePatch = true;

	for(int i = 1; i < argc; ++i)
	{
		if(!strcmp(argv[i], "-f")) 
			fullscreen = 1;
		else if(!strcmp(argv[i], "-w")) 
			fullscreen = 0;
		else if(!strcmp(argv[i], "-1024") || !strcmp(argv[i], "-1024x768"))
		{
			xres = 1024;
			yres = 768;
		}
		else if(!strcmp(argv[i], "-1280") || !strcmp(argv[i], "-1280x1024"))
		{
			xres = 1280;
			yres = 1024;
		}
		else if(!strcmp(argv[i], "-1280x960"))
		{
			xres = 1280;
			yres = 960;
		}
		else if(!strcmp(argv[i], "-1400") || !strcmp(argv[i], "-1400x1050"))
		{
			xres = 1400;
			yres = 1050;
		}
		else if(!strcmp(argv[i], "-1280x800"))
		{
			xres = 1280;
			yres = 800;
		}
		else if(!strcmp(argv[i], "-1600") || !strcmp(argv[i], "-1600x1200"))
		{
			xres = 1600;
			yres = 1200;
		}
		else if(!strcmp(argv[i], "-1920") || !strcmp(argv[i], "-1920x1200"))
		{
			xres = 1920;
			yres = 1200;
		}
		else if(!strcmp(argv[i], "-2048") || !strcmp(argv[i], "-2048x1536"))
		{
			xres = 2048;
			yres = 1536;
		}
		
		else if(!strcmp(argv[i], "-p"))
			usePatch = true;
		else if(!strcmp(argv[i], "-np"))
			usePatch = false;
	}

	checkConfig();

	/*if(!loadPath())
	{
		getGamePath();
	}
	else
	{
		getGamePath() = loadPath();
	}*/

	getGamePath();
	CreateStrips();

	gLog("[World of Warcraft Studio - Editor] - " APP_TITLE " : " APP_VERSION "\n[World of Warcraft Studio - Editor] - Game path: %s\n[World of Warcraft Studio - Editor] - Game Version: %d\n", gamepath, loadGameVersion());
	GraphicCard(); // Send to Log info about Graphic Card

	checkConfig2();

	vector<string> archiveNames;
	fillArchiveNameVector(archiveNames);
	for(size_t i = 0; i < archiveNames.size(); ++i)
		MPQArchive *archive = new MPQArchive(archiveNames[i].c_str());

	if(gOpenArchives.empty())
	{
		gLog("[World of Warcraft Studio - Editor] - ERROR: No one archive found");
		return 1;
	}

	gAreaDB.open();

	video.init(xres, yres, fullscreen != 0);

	gLog("[World of Warcraft Studio - Editor] - Initializing Ground Effects\n");
	InitGroundEffects();
	gLog("[World of Warcraft Studio - Editor] - Initializing Fonts\n");
	InitFonts();
	gLog("[World of Warcraft Studio - Editor] - Main Initializing complete\n");

	float ftime;
	uint32 t, last_t, frames = 0, time = 0, fcount = 0, ft = 0;
	AppState* as;
	gFPS = 0;

	gLog("[World of Warcraft Studio - Editor] - Creating Menu\n");
	Menu* m = new Menu();
	as = m;

	gStates.push_back(as);

	if(glExtGetGLProcs_VertexProgram_1_0_ARB() == 0)
	{
		gLog("[World of Warcraft Studio - Editor] - Unable to load ARB Vertex Program Code\n");
		return 0;
	}
	loadWaterShader();

	bool done = false;
	t = SDL_GetTicks();
	gLog("[World of Warcraft Studio - Editor] - Entering Main Loop\n");
	while(gStates.size() > 0 && !done)
	{
		last_t = t;
		t = SDL_GetTicks();
		Uint32 dt = t - last_t;
		time += dt;
		ftime = time / 1000.0f;

		as = gStates[gStates.size()-1];

		SDL_Event event;
		while(SDL_PollEvent(&event))
		{
			if(event.type == SDL_QUIT)
				done = true;
			else if(event.type == SDL_MOUSEMOTION)
			{
				if(SDL_GetAppState()&SDL_APPMOUSEFOCUS)
					as->mousemove(&event.motion);
			}
			else if((event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) && (SDL_GetAppState()&SDL_APPINPUTFOCUS))
			{	
				if(event.button.type == SDL_MOUSEBUTTONUP)
					as->mouseclick(&event.button);
				else if(SDL_GetAppState()&SDL_APPMOUSEFOCUS)
					as->mouseclick(&event.button);
			}
			else if(event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
			{
				if(SDL_GetAppState()&SDL_APPINPUTFOCUS)
					as->keypressed(&event.key);
			}
			else if(event.type == SDL_VIDEORESIZE)
				video.resize(event.resize.w, event.resize.h);
		}

		if(SDL_GetAppState()&SDL_APPACTIVE)
		{
			as->tick(ftime, dt / 1000.0f);
			as->display(ftime, dt / 1000.0f);
		}

		if(gPop) 
		{
			gPop = false;
			gStates.pop_back();
			delete as;
		}

		frames++;
		fcount++;
		ft += dt;
		
		if(ft >= 1000)
		{
            float fps = (float)fcount / (float)ft * 1000.0f;
			gFPS = fps;
			char buf[32];
			sprintf_s(buf, APP_TITLE " - %.2f fps", fps);
			SDL_WM_SetCaption(buf, NULL);
            ft = 0;
			fcount = 0;
		}

		video.flip();
	}
	gLog("[World of Warcraft Studio - Editor] - Exited Main Loop\n");

	deleteFonts();
	
	video.close();

	for(deque<MPQArchive*>::iterator it = archives.begin(); it != archives.end(); ++it)
        (*it)->close();
		
	archives.clear();

	gLog("\n[World of Warcraft Studio - Editor] - Exiting.\n");

	return 0;
}
コード例 #17
0
bool ELAS::buffer_mechanism(vector<HoughLine> & houghs_X, ConfigXML * _cfg) {
	// adiciono as houghs em potenciais para o buffer
	bool esqH = false, dirH = false; // flag para descartar as houghs
	if (!houghs_X[0].isEmpty()) {
		if (esqBuffer.size() < BUFFER_HOUGHS_SIZE || Houghs::validaHough(houghs_X[0], esqBuffer, _cfg)) {
			esqBufferRejeitados.clear();
			Helper::pushBuffer(esqBuffer, houghs_X[0], BUFFER_HOUGHS_SIZE);
		} else {
			Helper::pushBuffer(esqBufferRejeitados, houghs_X[0], BUFFER_HOUGHS_SIZE);
			esqH = true;
		}
	}

	if (!houghs_X[1].isEmpty()) {
		if (dirBuffer.size() < BUFFER_HOUGHS_SIZE || Houghs::validaHough(houghs_X[1], dirBuffer, _cfg)) {
			dirBufferRejeitados.clear();
			Helper::pushBuffer(dirBuffer, houghs_X[1], BUFFER_HOUGHS_SIZE);
		} else {
			Helper::pushBuffer(dirBufferRejeitados, houghs_X[1], BUFFER_HOUGHS_SIZE);
			dirH = true;
		}
	}

	bool esqCheio = esqBufferRejeitados.size() == BUFFER_HOUGHS_SIZE;
	bool dirCheio = dirBufferRejeitados.size() == BUFFER_HOUGHS_SIZE;

	if (esqCheio || dirCheio) {

		bool resetarKalman = false;

		// se somente um estiver cheio
		// swap desse buffer
		// zerar os outros
		if (esqCheio) {
			HoughDoMeio rawMeasurement = HoughLine::getKalmanMeasurement(esqBufferRejeitados.back(), dirBuffer.back(), _cfg);
			if (rawMeasurement.largura > BUFFER_MIN_LENGTH) {
				esqBuffer = esqBufferRejeitados;
				resetarKalman = true;
			}
			esqBufferRejeitados.clear();
		}

		if (dirCheio) {
			HoughDoMeio rawMeasurement = HoughLine::getKalmanMeasurement(esqBuffer.back(), dirBufferRejeitados.back(), _cfg);
			if (rawMeasurement.largura > BUFFER_MIN_LENGTH) {
				double mediaPosicao, desvioPosicao;
				Houghs::posicaoBufferStatistics(dirBufferRejeitados, mediaPosicao, desvioPosicao, _cfg);
				Houghs::posicaoBufferStatistics(dirBuffer, mediaPosicao, desvioPosicao, _cfg);
				if (desvioPosicao < 5) {
					dirBuffer = dirBufferRejeitados;
					resetarKalman = true;
				}
			}
			dirBufferRejeitados.clear();
		}

		if (resetarKalman) {
			Houghs::validaEmptyHoughs(houghs_X, *kalmanState, _cfg);
			HoughDoMeio rawMeasurement = HoughLine::getKalmanMeasurement(houghs_X[0], houghs_X[1], _cfg);
			// TODO: particle filter -> houghPF.reset(rawMeasurement.toKalman(), false);
			Kalman::resetaKalman(KF, 6, 3, rawMeasurement.toKalman());
		}
	}

	if (esqH) houghs_X[0] = HoughLine::empty();
	if (dirH) houghs_X[1] = HoughLine::empty();

	const bool estimarLargura = (!houghs_X[0].isEmpty() && !houghs_X[1].isEmpty());

	Houghs::validaEmptyHoughs(houghs_X, *kalmanState, _cfg);

	return estimarLargura;

}
コード例 #18
0
ファイル: main.cpp プロジェクト: wzcjj/cjj1
int main(int argc, const char * argv[]) {
    int i,j,m,n,N,I=0;
    cin>>N;
    while (N--) {
        I++;
        printf("Case #%d:\n",I);
        int l=maxn,r=maxn-1;
        int re=1;
        b.clear();
        scanf("%d",&n);
        for(j=1;j<=n;j++){
            scanf("%s",s);
            if(s[2]=='S'){
                int x;
                scanf("%d",&x);
                r+=re;
                a[r]=x;
                if(!x){
                    if(re==1)b.push_back(r);
                    else b.push_front(r);
                }
            }
            else if(s[2]=='P'){
                if(!a[r]){
                    if(re==1)b.pop_back();
                    else b.pop_front();
                }
                r-=re;
            }
            else if(s[2]=='V'){
                re=-re;
                swap(l,r);
            }
            else {
                if(l==r+re){
                    printf("Invalid.\n");
                }
                else {
                    int x;
                    bool ans;
                    if(b.empty()){
                        if((l-r)&1)ans=0;
                        else ans=1;
                    }
                    else {
                        if(re==1)x=b.front();
                        else x=b.back();
                        if((x-l)&1){
                            if(r==x)ans=1;
                            else ans=0;
                        }
                        else {
                            if(r==x)ans=0;
                            else ans=1;
                        }
                    }
                    if(ans)printf("1\n");
                    else printf("0\n");
                }
            }
        }
    }
    return 0;
}
コード例 #19
0
ファイル: wlan.cpp プロジェクト: brickcode/simulation-wlan
void Monitor :: execute()
{
    reset();
    opoznienia.clear();
}
コード例 #20
0
int internal_degree_and_membership (double mixing_parameter, int overlapping_nodes, int max_mem_num, int num_nodes, deque<deque<int> >  & member_matrix, 
                                    bool excess, bool defect,  deque<int> & degree_seq, deque<int> &num_seq, deque<int> &internal_degree_seq, bool fixed_range, int nmin, int nmax, double tau2) {
	
	
	
	
	
	if(num_nodes< overlapping_nodes) {
		
		cerr<<"\n***********************\nERROR: there are more overlapping nodes than nodes in the whole network! Please, decrease the former ones or increase the latter ones"<<endl;
		return -1;
	}
	
	
	// 
	member_matrix.clear();
	internal_degree_seq.clear();
	
	deque<double> cumulative;
	
	// it assigns the internal degree to each node -------------------------------------------------------------------------
	int max_degree_actual=0;		// maximum internal degree
    
	for (int i=0; i<degree_seq.size(); i++) {
		
		double interno=(1-mixing_parameter)*degree_seq[i];
		int int_interno=int(interno);
		
		
		if (ran4()<(interno-int_interno))
			int_interno++;
		
		if (excess) {
			
			while (   (  double(int_interno)/degree_seq[i] < (1-mixing_parameter) )  &&   (int_interno<degree_seq[i])   )
				int_interno++;
            
            
		}
		
		
		if (defect) {
			
			while (   (  double(int_interno)/degree_seq[i] > (1-mixing_parameter) )  &&   (int_interno>0)   )
				int_interno--;
            
            
		}
        
		
		
		
		internal_degree_seq.push_back(int_interno);
		
		
		if (int_interno>max_degree_actual)
			max_degree_actual=int_interno;
		
        
	}
	
	
	// it assigns the community size sequence -----------------------------------------------------------------------------
	
	powerlaw(nmax, nmin, tau2, cumulative);
	
	
	if (num_seq.empty()) {
		
		int _num_=0;
		if (!fixed_range && (max_degree_actual+1)>nmin) {
            
			_num_=max_degree_actual+1;			// this helps the assignment of the memberships (it assures that at least one module is big enough to host each node)
			num_seq.push_back(max_degree_actual+1);
            
		}
		
		
		while (true) {
			
			
			int nn=lower_bound(cumulative.begin(), cumulative.end(), ran4())-cumulative.begin()+nmin;
			
			if (nn+_num_<=num_nodes + overlapping_nodes * (max_mem_num-1) ) {
				
				num_seq.push_back(nn);				
				_num_+=nn;
                
			}
			else
				break;
			
			
		}
		
		num_seq[min_element(num_seq.begin(), num_seq.end()) - num_seq.begin()]+=num_nodes + overlapping_nodes * (max_mem_num-1) - _num_;
		
	}
	
	
	//cout<<"num_seq"<<endl;
	//prints(num_seq);
	
	int ncom=num_seq.size();
	
	//cout<<"\n----------------------------------------------------------"<<endl;
    
	/*
     cout<<"community sizes"<<endl;
     for (int i=0; i<num_seq.size(); i++)
     cout<<num_seq[i]<<" ";
     cout<<endl<<endl;
     //*/
	
    
	/*
     deque <int> first;
     for (int i=0; i<ncom; i++)
     member_matrix.push_back(first);
     
     
     
     // it puts the overlapping_nodes inside
     cout<<ncom<<endl;
     for (int i=degree_seq.size() - overlapping_nodes; i<degree_seq.size(); i++) {
     
     cout<<i<<endl;
     set<int> members;
     int hh=0;
     
     while(members.size()<max_mem_num) {
     
     int random_module=irand(ncom-1);
     
     if(member_matrix[random_module].size()!=num_seq[random_module])
     members.insert(random_module);
     
     hh++;
     
     if(hh>3*num_nodes) {
     cerr<<"it seems that the overlapping nodes need more communities that those I provided. Please increase the number of communities or decrease the number of overlapping nodes"<<endl;
     return -1;				
     }
     
     }
     
     
     for (set<int>::iterator its=members.begin(); its!=members.end(); its++)
     member_matrix[*its].push_back(i);
     
     }
     
     
     
     // it decides the memberships for the not overlapping nodes		
     
     int moment_module=0;
     for (int i=0; i<num_nodes - overlapping_nodes; i++) {
     
     while(member_matrix[moment_module].size()==num_seq[moment_module])
     moment_module++;
     
     member_matrix[moment_module].push_back(i);
     
     }
     
     
     
     */
	
	// I have to assign the degree to the nodes
	
	
	deque<int> member_numbers;
	for(int i=0; i<overlapping_nodes; i++)
		member_numbers.push_back(max_mem_num);
	for(int i=overlapping_nodes; i<degree_seq.size(); i++)
		member_numbers.push_back(1);
	
	//prints(member_numbers);
	//prints(num_seq);
	
	if(build_bipartite_network(member_matrix, member_numbers, num_seq)==-1) {
		
		cerr<<"it seems that the overlapping nodes need more communities that those I provided. Please increase the number of communities or decrease the number of overlapping nodes"<<endl;
		return -1;			
        
	}
    
	//printm(member_matrix);
	
	//cout<<"degree_seq"<<endl;
	//prints(degree_seq);
	
	//cout<<"internal_degree_seq"<<endl;
	//prints(internal_degree_seq);
    
	deque<int> available;
	for (int i=0; i<num_nodes; i++)
		available.push_back(0);
	
	for (int i=0; i<member_matrix.size(); i++) {
		for (int j=0; j<member_matrix[i].size(); j++)
			available[member_matrix[i][j]]+=member_matrix[i].size()-1;
	}
	
	//cout<<"available"<<endl;
	//prints(available);
	
	
	deque<int> available_nodes;
	for (int i=0; i<num_nodes; i++)
		available_nodes.push_back(i);
	
	
	deque<int> map_nodes;				// in the position i there is the new name of the node i
	for (int i=0; i<num_nodes; i++)
		map_nodes.push_back(0);
    
	
	for (int i=degree_seq.size()-1; i>=0; i--) {
		
		int & degree_here=internal_degree_seq[i];
		int try_this = irand(available_nodes.size()-1);
		
		int kr=0;
		while (internal_degree_seq[i] > available[available_nodes[try_this]]) {
            
			kr++;
			try_this = irand(available_nodes.size()-1);
			if(kr==3*num_nodes) {
                
				if(change_community_size(num_seq)==-1) {
					
					cerr<<"\n***********************\nERROR: this program needs more than one community to work fine"<<endl;
					return -1;
                    
				}
				
				cout<<"it took too long to decide the memberships; I will try to change the community sizes"<<endl;
                
				cout<<"new community sizes"<<endl;
				for (int i=0; i<num_seq.size(); i++)
					cout<<num_seq[i]<<" ";
				cout<<endl<<endl;
				
				return (internal_degree_and_membership(mixing_parameter, overlapping_nodes, max_mem_num, num_nodes, member_matrix, excess, defect, degree_seq, num_seq, internal_degree_seq, fixed_range, nmin, nmax, tau2));
                
                
			}
			
			
		}
		
		
		
		map_nodes[available_nodes[try_this]]=i;
		
		available_nodes[try_this]=available_nodes[available_nodes.size()-1];
		available_nodes.pop_back();
		
        
        
	}
	
	
	for (int i=0; i<member_matrix.size(); i++) {
		for (int j=0; j<member_matrix[i].size(); j++)
			member_matrix[i][j]=map_nodes[member_matrix[i][j]];	
	}
	
	
	
	for (int i=0; i<member_matrix.size(); i++)
		sort(member_matrix[i].begin(), member_matrix[i].end());
    
    
	return 0;
    
}
コード例 #21
0
ファイル: graphics.cpp プロジェクト: sngvahmed/Graphics
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	Draw Ahmed;
	switch (message)
	{
		case WM_LBUTTONDOWN: 
			if(!isSecond) 
				X1 = LOWORD(lParam), Y1 = HIWORD(lParam) , isSecond = true;
			else 
				X2 = LOWORD(lParam) , Y2 = HIWORD(lParam) , InvalidateRect(hWnd, NULL, false);
		break;
		case WM_COMMAND:
			wmId = LOWORD(wParam) , wmEvent = HIWORD(wParam);
			// Parse the menu selections:
			switch (wmId){
				case IDM_S:
					ss.open("input.in") , tmp.clear() , tmp = var;
					while(var.size())
						ss << var.front().x1 << " " << var.front().y1 << " " << var.front().x2 << " " << 
							var.front().y2 << " " << var.front().P <<"\n" , var.pop_front();
					var = tmp , ss.close();
				break;
				case IDM_O:
					clr() , OT = true;
					InvalidateRect(hWnd, NULL, true); // draw only a line on the screen
				break;
				case IDM_DDA_LINE:
					clr() , BDDA = 1;
				break;
				case IDM_MP_LINE:
					clr() , BMP = true;
				break;
					case IDM_MP_CIRCULE:
					clr() , MPC = true;
				break;
				case IDM_CIRC_CART:
					clr() , cartizen = true;
				break;
				case IDM_RES:
					RES = true;
					isSecond  = false;
					InvalidateRect(hWnd, NULL, true); // draw only a line on the screen
				break;
				case IDM_R:
					clr() ,  R = true , InvalidateRect(hWnd , 0 , false);
				break;
				case IDM_U:
					clr() ,  U = true , InvalidateRect(hWnd , 0 , false);
				break;
				case IDM_COL:
					memset(&color,0,sizeof(color));
					color.lStructSize=sizeof(CHOOSECOLOR);
					color.hwndOwner=hWnd;
					color.lpCustColors=ccref;
					color.rgbResult=selcolor;
					color.Flags=CC_RGBINIT;
					if(ChooseColor(&color))
						selcolor=color.rgbResult;
					isSecond = false;
				break;
				case IDM_ABOUT:
					DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
					break;
				case IDM_EXIT:
					DestroyWindow(hWnd);
					break;
				default:
					return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
			case WM_PAINT:
				hdc = BeginPaint(hWnd, &ps);
				Ahmed.ps = ps ;
				if(OT == true){
					ss.open("input.in");
					PT tmst;
					while(!ss.eof()){
						ss >> tmst.x1 >> tmst.y1 >> tmst.x2 >> tmst.y2 >> tmst.P;			
						if (tmst.P == 'D')
							Ahmed.DDA(tmst.x1 , tmst.y1 , tmst.x2 , tmst.y2 , selcolor);
						if (tmst.P == 'M')
							Ahmed.MidPoint(tmst.x1 , tmst.y1 , tmst.x2 , tmst.y2 , selcolor);
						if (tmst.P == 'C')
							Ahmed.drawCircle(tmst.x1 , tmst.y1 , Ahmed.Distance(tmst.x1 , tmst.y1 , tmst.x2 , tmst.y2), selcolor);
						if(tmst.P == 'Z')
							Ahmed.MIDPOINT_CARTISIEAN(tmst.x1, tmst.y1 , Ahmed.Distance(tmst.x1 , tmst.y1 , tmst.x2 , tmst.y2), selcolor);
					}
					ss.close();
					clr() , BDDA = true , X1 = X2 = Y1 = Y2 = 0;
					EndPaint(hWnd, &ps);
					break;
				}
				if(U == true){
					if(var.size() != 0){
						PT t = var.back();
						var.pop_back() , var.push_front(t) ;
						if (t.P == 'D')
							Ahmed.DDA(t.x1 , t.y1 , t.x2 , t.y2 , RGB(250,250,250));
						if (t.P == 'M')
							Ahmed.MidPoint(t.x1 , t.y1 , t.x2 , t.y2 , RGB(250,250,250)); 
						if (t.P == 'C')
							Ahmed.drawCircle(t.x1 , t.y1 , Ahmed.Distance(t.x1,t.y1,t.x2,t.y2), RGB(250,250,250));
						if(t.P == 'Z')
							Ahmed.MIDPOINT_CARTISIEAN(t.x1, t.y1 , Ahmed.Distance(t.x1 , t.y1 , t.x2 , t.y2), RGB(250,250,250));
					}
					clr() , BDDA = true , X1 = X2 = Y1 = Y2 = 0;
					EndPaint(hWnd, &ps);
					break;
				} 
				if(R == true){
					if(var.size() != 0){
						PT t = var.front();
						var.pop_front() , var.push_back(t);
						if (t.P == 'D')
							Ahmed.DDA(t.x1 , t.y1 , t.x2 , t.y2 , selcolor);
						if (t.P == 'M')
							Ahmed.MidPoint(t.x1 , t.y1 , t.x2 , t.y2 , selcolor);
						if (t.P == 'C')
							Ahmed.drawCircle(t.x1 , t.y1 , Ahmed.Distance(t.x1 , t.y1 , t.x2 , t.y2), selcolor);
						if(t.P == 'Z')
							Ahmed.MIDPOINT_CARTISIEAN(t.x1, t.y1 , Ahmed.Distance(t.x1 , t.y1 , t.x2 , t.y2), selcolor);
					}
					clr() , BDDA = true , X1 = X2 = Y1 = Y2 = 0;
					EndPaint(hWnd, &ps);
					break;
				}
				if(MPC == true)
					Ahmed.drawCircle(X1 , Y1 , Ahmed.Distance(X1,Y1,X2,Y2), selcolor) , var.push_back(PT(X1,Y1,X2,Y2,'C'));
				if(BDDA == true)
					Ahmed.DDA(X1 , Y1 , X2 , Y2 , selcolor) ,var.push_back(PT(X1,Y1,X2,Y2,'D'));
				if (BMP == true)
					Ahmed.MidPoint(X1 , Y1 , X2 , Y2 , selcolor) ,var.push_back(PT(X1,Y1,X2,Y2,'M'));
				if(cartizen == true)
					Ahmed.MIDPOINT_CARTISIEAN(X1,Y1 , Ahmed.Distance(X1,Y1,X2,Y2) , selcolor) , var.push_back(PT(X1,Y1,X2,Y2,'Z'));
				EndPaint(hWnd, &ps) , isSecond = false;
				break;
			case WM_DESTROY:
				PostQuitMessage(0);
			break;
			default:
				return DefWindowProc(hWnd, message, wParam, lParam);
	}
コード例 #22
0
void MamdaQuoteToBookListenerImpl::removeHandlers()
{
    mHandlers.clear ();
}
コード例 #23
0
int build_bipartite_network(deque<deque<int> >  & member_matrix, const deque<int> & member_numbers, const deque<int> &num_seq) {
    
	
	
	// this function builds a bipartite network with num_seq and member_numbers which are the degree sequences. in member matrix links of the communities are stored
	// this means member_matrix has num_seq.size() rows and each row has num_seq[i] elements
	
	
	
	deque<set<int> > en_in;			// this is the Ein of the subgraph
	deque<set<int> > en_out;		// this is the Eout of the subgraph
	
	
	{
    set<int> first;
    for(int i=0; i<member_numbers.size(); i++) {
        en_in.push_back(first);
    }
	}
	
	{
    set<int> first;
    for(int i=0; i<num_seq.size(); i++) {
        en_out.push_back(first);
    }
	}
    
	
	
	multimap <int, int> degree_node_out;
	deque<pair<int, int> > degree_node_in;
	
	for(int i=0; i<num_seq.size(); i++)
		degree_node_out.insert(make_pair(num_seq[i], i));
	
	for(int i=0; i<member_numbers.size(); i++)
		degree_node_in.push_back(make_pair(member_numbers[i], i));
	
	
	sort(degree_node_in.begin(), degree_node_in.end());
	
	
	
	deque<pair<int, int> >::iterator itlast = degree_node_in.end();
	
	/*
     for (int i=0; i<degree_node_in.size(); i++)
     cout<<degree_node_in[i].first<<" "<<degree_node_in[i].second<<endl;
     */
	
	
	
	while (itlast != degree_node_in.begin()) {
		
		itlast--;
		
		
		multimap <int, int>::iterator itit= degree_node_out.end();
		deque <multimap<int, int>::iterator> erasenda;
		
		for (int i=0; i<itlast->first; i++) {
			
			if(itit!=degree_node_out.begin()) {
				
				itit--;
				
                
				en_in[itlast->second].insert(itit->second);
				en_out[itit->second].insert(itlast->second);
                
				erasenda.push_back(itit);
				
			}
			
			else
				return -1;
            
		}
		
		
		//cout<<"degree node out before"<<endl;
		//prints(degree_node_out);
		
		for (int i=0; i<erasenda.size(); i++) {
			
			
			if(erasenda[i]->first>1)
				degree_node_out.insert(make_pair(erasenda[i]->first - 1, erasenda[i]->second));
            
			
			degree_node_out.erase(erasenda[i]);
            
			
            
		}
		
		//cout<<"degree node out after"<<endl;
		//prints(degree_node_out);
		
	}
	
	
	// this is to randomize the subgraph -------------------------------------------------------------------
    
    
    deque<int> degree_list;
    for(int kk=0; kk<member_numbers.size(); kk++)
        for(int k2=0; k2<member_numbers[kk]; k2++)
            degree_list.push_back(kk); 
    
	
	for(int run=0; run<10; run++) for(int node_a=0; node_a<num_seq.size(); node_a++) for(int krm=0; krm<en_out[node_a].size(); krm++) {
        
        int random_mate=degree_list[irand(degree_list.size()-1)];
		
		if (en_out[node_a].find(random_mate)==en_out[node_a].end()) {
			
			deque <int> external_nodes;
			for (set<int>::iterator it_est=en_out[node_a].begin(); it_est!=en_out[node_a].end(); it_est++)
				external_nodes.push_back(*it_est);
            
            
			int	old_node=external_nodes[irand(external_nodes.size()-1)];
            
			
			deque <int> not_common;
			for (set<int>::iterator it_est=en_in[random_mate].begin(); it_est!=en_in[random_mate].end(); it_est++)
				if (en_in[old_node].find(*it_est)==en_in[old_node].end())
					not_common.push_back(*it_est);
            
			
			if (not_common.empty())
				break;
            
			int node_h=not_common[irand(not_common.size()-1)];
			
			
			en_out[node_a].insert(random_mate);
			en_out[node_a].erase(old_node);
			
			en_in[old_node].insert(node_h);
			en_in[old_node].erase(node_a);
			
			en_in[random_mate].insert(node_a);
			en_in[random_mate].erase(node_h);
			
			en_out[node_h].erase(random_mate);
			en_out[node_h].insert(old_node);
			
            
		}	
	}
    
	
	
	member_matrix.clear();
	deque <int> first;
	
	for (int i=0; i<en_out.size(); i++) { 
		
		member_matrix.push_back(first);
		for (set<int>::iterator its=en_out[i].begin(); its!=en_out[i].end(); its++)
			member_matrix[i].push_back(*its);
        
	}
	
	
	return 0;
    
    
}
コード例 #24
0
ファイル: UrgDevice.cpp プロジェクト: aldebaran/liburg
 void clear(void)
 {
   LockGuard guard(mutex_);
   data_buffer_.clear();
   intensity_data_.length_data.clear();
 }
コード例 #25
0
int build_subgraphs(deque<set<int> > & E, const deque<deque<int> > & member_matrix, deque<deque<int> > & member_list, 
                    deque<deque<int> > & link_list, const deque<int> & internal_degree_seq, const deque<int> & degree_seq, const bool excess, const bool defect) {
	
	
	
	E.clear();
	member_list.clear();
	link_list.clear();
	
	int num_nodes=degree_seq.size();
	
	//printm(member_matrix);
    
	
	
	
	{
    
    deque<int> first;
    for (int i=0; i<num_nodes; i++)
        member_list.push_back(first);
	
	}
	
	
	
	for (int i=0; i<member_matrix.size(); i++)
		for (int j=0; j<member_matrix[i].size(); j++)
			member_list[member_matrix[i][j]].push_back(i);
	
	
	//printm(member_list);
	
	for (int i=0; i<member_list.size(); i++) {
		
		deque<int> liin;
        
		
		for (int j=0; j<member_list[i].size(); j++) {
			
			compute_internal_degree_per_node(internal_degree_seq[i], member_list[i].size(), liin);
			liin.push_back(degree_seq[i] - internal_degree_seq[i]);
            
		}
		
		link_list.push_back(liin);
		
	}
    
	
	
    
	// now there is the check for the even node (it means that the internal degree of each group has to be even and we want to assure that, otherwise the degree_seq has to change) ----------------------------
    
	
	
	
	// ------------------------ this is done to check if the sum of the internal degree is an even number. if not, the program will change it in such a way to assure that. 
	
	
    
	for (int i=0; i<member_matrix.size(); i++) {
        
		
		int internal_cluster=0;
		for (int j=0; j<member_matrix[i].size(); j++) {
			
			int right_index= lower_bound(member_list[member_matrix[i][j]].begin(), member_list[member_matrix[i][j]].end(), i) - member_list[member_matrix[i][j]].begin();
			
            
			
			internal_cluster+=link_list[member_matrix[i][j]][right_index];
		}
		
		
		if(internal_cluster % 2 != 0) {
			
			
			
			bool default_flag=false;
			
			if(excess)
				default_flag=true;
			else if(defect)
				default_flag=false;
			else if (ran4()>0.5)
				default_flag=true;
			
			if(default_flag) {
				
				// if this does not work in a reasonable time the degree sequence will be changed
				
				for (int j=0; j<member_matrix[i].size(); j++) {		
					
					
					int random_mate=member_matrix[i][irand(member_matrix[i].size()-1)];
					
					int right_index= lower_bound(member_list[random_mate].begin(), member_list[random_mate].end(), i) - member_list[random_mate].begin();
					
					
					if ((link_list[random_mate][right_index]<member_matrix[i].size()-1) && (link_list[random_mate][link_list[random_mate].size()-1] > 0 )) {
						
						link_list[random_mate][right_index]++;
						link_list[random_mate][link_list[random_mate].size()-1]--;
                        
						break;
						
					}
                    
				}
                
                
			}
			
			
			else {
				
				for (int j=0; j<member_matrix[i].size(); j++) {
                    
					int random_mate=member_matrix[i][irand(member_matrix[i].size()-1)];
                    
					int right_index= lower_bound(member_list[random_mate].begin(), member_list[random_mate].end(), i) - member_list[random_mate].begin();
					
					if (link_list[random_mate][right_index] > 0 ) {
						
						link_list[random_mate][right_index]--;
						link_list[random_mate][link_list[random_mate].size()-1]++;
                        
						break;
						
					}
                    
				}
                
                
			}
			
			
			
            
		}
        
        
	}
	
	
	// ------------------------ this is done to check if the sum of the internal degree is an even number. if not, the program will change it in such a way to assure that. 
	
	
	
	
	{
	
    set<int> first;
    for(int i=0; i<num_nodes; i++)
        E.push_back(first);
	
	}
	
	for (int i=0; i<member_matrix.size(); i++) {
		
		
		deque<int> internal_degree_i;
		for (int j=0; j<member_matrix[i].size(); j++) {
            
            
			int right_index= lower_bound(member_list[member_matrix[i][j]].begin(), member_list[member_matrix[i][j]].end(), i) - member_list[member_matrix[i][j]].begin();
            
			internal_degree_i.push_back(link_list[member_matrix[i][j]][right_index]);
            
		}
		
		
		
		
		if(build_subgraph(E, member_matrix[i], internal_degree_i)==-1)
			return -1;
        
        
	}
    
    
    
    
	return 0;
	
}
コード例 #26
0
ファイル: Straights.cpp プロジェクト: Hamyli/Straights
int main(int argc, char* argv[]){
    //invite players
    Player *players [4];

    for(int i= 0; i<4; i++){
        cout << "Is player " << i+1 << " a human(h) or a computer(c)?" << endl << ">";
        string input;
        cin >> input;
        assert(input=="c" || input=="C" || input=="h" || input=="H");

        if(input=="c"||input=="C")
            players[i] = new Computer(i+1);
        else if(input=="h" || input=="H")
            players[i] = new Human(i+1);
    }

    createDeck();

    //seeding the random number 
    if(argc==2)
	srand48(atol(argv[1]));
    else
	srand48(0);

    //game loops while no one has more than 80 points
    while (players[0]->getTotalScore() < 80 && players[1]->getTotalScore() < 80 && players[2]->getTotalScore() < 80 && players[3]->getTotalScore() < 80)
    {
        shuffle();

        //reset tables
        tableC.clear();
        tableD.clear();
        tableH.clear();
        tableS.clear();
        int currentPlayer=0;
        //split the deck amongst the first four players
        for(int i = 0; i<CARD_COUNT; i++){
            players[i/13]->setHand(cards_[i]);
            if(cards_[i]->getSuit()==3 && cards_[i]->getRank()==6){
                currentPlayer=i/13;
            }
        }

        //gameplay starts
        cout << "A new round begins. It's player " << currentPlayer+1 << "'s turn to play." << endl;

        //loop for one round of the game
        for(int i = 0; i<52; i++)
        {
            players[currentPlayer]->turn(tableC, tableD, tableH, tableS);
            //human player turn
	    if(players[currentPlayer]->getptype() == "h")
            {
                Human * h = dynamic_cast<Human*>(players[currentPlayer]);
                Command c;
                bool acceptablePlayMade = false;
                while (!acceptablePlayMade)
                {
                    cout << ">";
                    cin >> c;
                    if(c.type == PLAY)
                    {
			//call play with respective table 
                        if(c.card.getSuit()==0)
                            acceptablePlayMade = h->play(c.card, tableC);
                        else if(c.card.getSuit()==1)
                            acceptablePlayMade = h->play(c.card, tableD);
                        else if(c.card.getSuit()==2)
                            acceptablePlayMade = h->play(c.card, tableH);
                        else if(c.card.getSuit()==3)
                            acceptablePlayMade = h->play(c.card, tableS);
                    }
                    else if(c.type == RAGEQUIT){
                        cout << "Player " << currentPlayer + 1 << " ragequits. A computer will now take over." << endl;
                        players[currentPlayer] = new Computer(h);
                        delete h;
                        acceptablePlayMade = true;
                        //decrement currentPlayer and i to restart this turn as computer
                        currentPlayer--;
                        i--;
                    }
                    else if(c.type == DECK){
                        for (int i = 0; i<CARD_COUNT; i++)
                        {
                            cout << *(cards_[i]);
                            if (i%13 == 12)
                                cout << endl;
                            else
                                cout << " ";
                        }
                    }
                    else if(c.type == DISCARD){
                        acceptablePlayMade = h->discard(c.card, tableC, tableD, tableH, tableS);
                    }
                    else if(c.type == QUIT){
                        return 0;
                    }
                }
            }
            currentPlayer = (++currentPlayer)%4;
        }
        //total scores
        for (int i = 0; i < 4; i++)
            players[i]->countRoundScore();
    }
コード例 #27
0
ファイル: monoid.hpp プロジェクト: jfromentin/Gomu
inline void
Reversing::clear(){
  to_reverse.clear();
}
コード例 #28
0
ファイル: ThemeManager.cpp プロジェクト: Ancaro/stepmania
void ThemeManager::LoadThemeMetrics( const RString &sThemeName_, const RString &sLanguage_ )
{
	if( g_pLoadedThemeData == NULL )
		g_pLoadedThemeData = new LoadedThemeData;

	// Don't delete and recreate LoadedThemeData.  There are references iniMetrics and iniStrings 
	// on the stack, so Clear them instead.
	g_pLoadedThemeData->ClearAll();
	g_vThemes.clear();

	RString sThemeName(sThemeName_);
	RString sLanguage(sLanguage_);

	m_sCurThemeName = sThemeName;
	m_sCurLanguage = sLanguage;

	bool bLoadedBase = false;
	while(1)
	{
		ASSERT_M( g_vThemes.size() < 20, "Circular theme fallback references detected." );

		g_vThemes.push_back( Theme() );
		Theme &t = g_vThemes.back();
		t.sThemeName = sThemeName;

		IniFile iniMetrics;
		IniFile iniStrings;
		iniMetrics.ReadFile( GetMetricsIniPath(sThemeName) );
		// Load optional language inis (probably mounted by a package) first so that they can be overridden by the current theme.
		{
			vector<RString> vs;
			GetOptionalLanguageIniPaths(vs,sThemeName,sLanguage);
			FOREACH_CONST(RString,vs,s)
				iniStrings.ReadFile( *s );
		}
		iniStrings.ReadFile( GetLanguageIniPath(sThemeName,SpecialFiles::BASE_LANGUAGE) );
		if( sLanguage.CompareNoCase(SpecialFiles::BASE_LANGUAGE) )
			iniStrings.ReadFile( GetLanguageIniPath(sThemeName,sLanguage) );

		bool bIsBaseTheme = !sThemeName.CompareNoCase(SpecialFiles::BASE_THEME_NAME);
		iniMetrics.GetValue( "Global", "IsBaseTheme", bIsBaseTheme );
		if( bIsBaseTheme )
			bLoadedBase = true;

		/* Read the fallback theme. If no fallback theme is specified, and we haven't
		 * already loaded it, fall back on SpecialFiles::BASE_THEME_NAME.
		 * That way, default theme fallbacks can be disabled with
		 * "FallbackTheme=". */
		RString sFallback;
		if( !iniMetrics.GetValue("Global","FallbackTheme",sFallback) )
		{
			if( sThemeName.CompareNoCase( SpecialFiles::BASE_THEME_NAME ) && !bLoadedBase )
				sFallback = SpecialFiles::BASE_THEME_NAME;
		}

		/* We actually want to load themes bottom-to-top, loading fallback themes
		 * first, so derived themes overwrite metrics in fallback themes. But, we
		 * need to load the derived theme first, to find out the name of the fallback
		 * theme.  Avoid having to load IniFile twice, merging the fallback theme
		 * into the derived theme that we've already loaded. */
		XmlFileUtil::MergeIniUnder( &iniMetrics, &g_pLoadedThemeData->iniMetrics );
		XmlFileUtil::MergeIniUnder( &iniStrings, &g_pLoadedThemeData->iniStrings );

		if( sFallback.empty() )
			break;
		sThemeName = sFallback;
	}

	// Overlay metrics from the command line.
	RString sMetric;
	for( int i = 0; GetCommandlineArgument( "metric", &sMetric, i ); ++i )
	{
		/* sMetric must be "foo::bar=baz". "foo" and "bar" never contain "=", so
		 * in "foo::bar=1+1=2", "baz" is always "1+1=2". Neither foo nor bar may
		 * be empty, but baz may be. */
		Regex re( "^([^=]+)::([^=]+)=(.*)$" );
		vector<RString> sBits;
		if( !re.Compare( sMetric, sBits ) )
			RageException::Throw( "Invalid argument \"--metric=%s\".", sMetric.c_str() );

		g_pLoadedThemeData->iniMetrics.SetValue( sBits[0], sBits[1], sBits[2] );
	}

	LOG->MapLog( "theme", "Theme: %s", m_sCurThemeName.c_str() );
	LOG->MapLog( "language", "Language: %s", m_sCurLanguage.c_str() );
}
コード例 #29
0
ファイル: 1566.cpp プロジェクト: fredwhite/Backup
int main(){
    int i,j;
    int u;
    
    int n,m;
    unsigned int k;
    int count;

    scanf("%d %d %u",&n,&m,&k);
    for(i=0;i<n;i++){
	scanf("%u",&l[i]);
    }
    
    count=0;
    insert(l[0]);
    for(i=1;i<m;i++){
	insert(l[i]);
	if((ma.back()-mi.back())==k){
	    count++;
	}
    }
    for(i=m,j=1;i<n;i++,j++){
	remove(l[i-m]);
	insert(l[i]);
	
	if((ma.back()-mi.back())==k){
	    count++;
	}
    }
    u=n-1;
    for(i=n-m+1;i<u;i++){
	remove(l[i-1]);

	if((ma.back()-mi.back())==k){
	    count++;
	}
    }

    ma.clear();
    mi.clear();

    printf("%d\n",count);

    insert(l[0]);
    for(i=1;i<m;i++){
	insert(l[i]);
	if((ma.back()-mi.back())==k){
	    printf("1 %d\n",i+1);
	}
    }
    for(i=m,j=1;i<n;i++,j++){
	remove(l[i-m]);
	insert(l[i]);
	if((ma.back()-mi.back())==k){
	    printf("%d %d\n",j+1,i+1);
	}
    }
    u=n-1;
    for(i=n-m+1;i<u;i++){
	remove(l[i-1]);
	if((ma.back()-mi.back())==k){
	    printf("%d %d\n",i+1,n);
	}
    }

    return 0;
}
コード例 #30
0
ファイル: cug1434(wa).cpp プロジェクト: defense81/acm-1
int main(){
    int n,x;
    while(scanf("%d",&n)!=EOF){
        q.clear();
        while(!q.empty()) q.pop_back();
        int mx=0;
        ans.clear();
        for(int i=0;i<n;i++) scanf("%d",&x),ans.push_back(x),mx=max(mx,x);
        int now=1;
        sort(ans.begin(),ans.end());
        int st=ans[0];
        for(int i=0;i<ans.size();i++){
            if(now){
                q.push_front(ans[i]);
            }
            else{
                q.push_back(ans[i]);
            }
            now=1-now;
        }
        int index=0;
        for(int i=0;i<q.size();i++){
            if(q[i]==st){
                index=i;
                break;
            }
        }

        ans.clear(); // 最小元素正序
        ans.push_back(q[index]);
        now=index+1;
        while(now%q.size()!=index) ans.push_back(q[now%q.size()]),now++;

        pnt.clear(); // 最小元素逆序
        for(int i=q.size()-1;i>=0;i--){
            if(q[i]==st){
                index=i;
                break;
            }
        }
        pnt.push_back(q[index]);
        now=index-1;
        while((now+q.size())%q.size()!=index) pnt.push_back(q[(now+q.size())%q.size()]),now--;

        int mi=0;
        for(int i=0;i<ans.size();i++){
            mi=max(abs(ans[i]-ans[(i+1)%ans.size()]),mi);
        }
        int largest_index=0;
        for(int i=0;i<ans.size();i++){
            if(ans[i]==mx) largest_index=i; // largest_index前的数据都是有序的
        }
        cnt.clear(),tmp.clear();
        tmp.assign(ans.begin(),ans.begin()+largest_index+1);
        int right=ans[0];
        for(int i=ans.size()-1;i>largest_index;i--){
            if(abs(right-ans[i-1])<=mi){
                tmp.push_back(ans[i]);
            }
            else{
                right=ans[i];
                cnt.push_back(ans[i]);
            }
        }
        sort(tmp.begin(),tmp.end());
        for(int i=cnt.size()-1;i>=0;i--) tmp.push_back(cnt[i]);


        largest_index=0;
        for(int i=0;i<pnt.size();i++){
            if(pnt[i]==mx) largest_index=i; // largest_index前的数据都是有序的
        }
        cnt.clear();
        knt.assign(pnt.begin(),pnt.begin()+largest_index+1);
        right=pnt[0];
        for(int i=pnt.size()-1;i>largest_index;i--){
            if(abs(right-pnt[i-1])<=mi){
                knt.push_back(pnt[i]);
            }
            else{
                right=pnt[i];
                cnt.push_back(pnt[i]);
            }
        }
        sort(knt.begin(),knt.end());
        for(int i=cnt.size()-1;i>=0;i--) knt.push_back(cnt[i]);

        bool ok=true;
        for(int i=0;i<tmp.size();i++){
            if(tmp[i]<knt[i]){
                ok=false;
                break;
            }
            else if(tmp[i]>knt[i]){
                ok=true;
                break;
            }
        }
        if(!ok){
            for(int i=0;i+1<tmp.size();i++) printf("%d ",tmp[i]);
                printf("%d\n",tmp[tmp.size()-1]);
        }
        else{
            for(int i=0;i+1<knt.size();i++) printf("%d ",knt[i]);
                printf("%d\n",knt[knt.size()-1]);
        }

    }
    return 0;
}