Exemplo n.º 1
0
int main() {
	int test, n, i, f;
	fread(buff, 1, 16000000, stdin);
	test = nextint();
	while(test--) {
		n = nextint();
		for(i = 1; i <= n; i++) {
			if(*nextstr() == 'c')
				a[i] = nextint();
			else
				a[i] = 0;
			ok[i] = 1;
		}
		for(i = n; i; i--)
			if(a[i] && ok[i])
				ok[a[i]] = 0;
		for(f = 0, i = 1; i <= n; i++)
			f += ok[i];
		printf("%d\n", f);
		for(i = 1, f = 0; i <= n; i++) {
			if(ok[i]) {
				if(f++) printf(" ");
				printf("%d", i);
			}
		}
		printf("\n");
	}
	return 0;
}
Exemplo n.º 2
0
int main() {
	int test, a, b, g;
	fread(buff, 1, 14000000, stdin);
	sieve();
	test = nextint();
	while(test--) {
		a = nextint(), b = nextint();
		g = gcd(a, b);
		printf("%d\n", cntdiv(g));
	}
	return 0;
}
Exemplo n.º 3
0
int main() {
	int test, cs, slen, plen;
	//freopen("in.txt", "r", stdin);
	fread_unlocked(buff, 1, 0x800000, stdin); ptr = buff;
	nextint(test);
	for(cs = 1; cs <= test; cs++) {
		nextstr(str,slen);
		nextstr(pattern,plen);
		if(plen > slen) {
			printf("Case %d: 0\n", cs);
			continue;
		}
		computeOverlap(plen);
		printf("Case %d: %d\n", cs, kmpMatcher(plen, slen));
	}
	return 0;
}
Exemplo n.º 4
0
void Meta::postscript(FILE *out)
{	Active=0;
	char *p=Start;
	double c,r,c1,r1,cc[16],hue;
	int col,st,width,n,i,j,co[16];
	PSGraph	*ps=new PSGraph(out,ops->width(),ops->height());
	for (i=0; i<16; i++)
		for (j=0; j<3; j++)
			ps->setcolor(i,getcolor(i,0),getcolor(i,1),getcolor(i,2));
	ps->setfillcolors(fillcolor1,fillcolor2);
	ps->setscreenlines(gscreenlines);
	ps->setusecolor(usecolors);
	ps->init();
	while (p<End) {
		int command=nextcommand(p);
	    	switch(command) {
			case 1 :
				ps->clear();
				break;
			case 2 :
				c=nextlong(p);
				r=nextlong(p);
				c1=nextlong(p);
				r1=nextlong(p);
				ps->clip(c,r,c1,r1);
				break;
         	case 10 :
				c=nextlong(p);
				r=nextlong(p);
				c1=nextlong(p);
				r1=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				width=nextint(p);
				ps->line(c,r,c1,r1,col,st,width);
				break;
			case 20 :
				c=nextlong(p);
				r=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				ps->marker(c,r,col,st);
				break;
			case 30 :
				n=nextint(p);
				for (i=0; i<n; i++)
				{	cc[2*i]=nextlong(p);
					cc[2*i+1]=nextlong(p);
					co[i]=nextint(p);
				}
				st=nextint(p);
				ps->fill(cc,st,n,co);
				break;
			case 31 :
				for (i=0; i<8; i++) cc[i]=nextlong(p);
				hue=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				ps->fillh(cc,hue,col,st);
				break;
			case 32 :
				c=nextlong(p);
				r=nextlong(p);
				c1=nextlong(p);
				r1=nextlong(p);
				hue=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				ps->bar(c,r,c1,r1,hue,col,st);
				break;
			case 33 :
				c=nextlong(p);
				r=nextlong(p);
				c1=nextlong(p);
				r1=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				ps->bar1(c,r,c1,r1,col,st);
				break;
			case 40 :
				c=nextlong(p);
				r=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				ps->text(c,r,p,col,st);
				p+=strlen(p)+1;
				break;
			case 41 :
				c=nextlong(p);
				r=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				ps->vtext(c,r,p,col,st);
				p+=strlen(p)+1;
				break;
			case 42 :
				c=nextlong(p);
				r=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				ps->vutext(c,r,p,col,st);
				p+=strlen(p)+1;
				break;
			case 50 :
				nextlong(p);
				break;
			default :
            			Active=1;
				delete ps;
				return;
		}
	}
	delete ps;
	Active=1;
}
Exemplo n.º 5
0
void Meta::replay (void *ps, int clip)
/* Redraw the graphics as noted in notespace */
{	Active=0;
	char *p=Start;
	double c,r,c1,r1,cc[16],hue;
	int col,st,width,n,i,co[16];
	while (p<End)
	{   int command=nextcommand(p);
    	switch(command)
		{	case 1 :
				gclear(p);
				break;
			case 2 :
				c=nextlong(p);
				r=nextlong(p);
				c1=nextlong(p);
				r1=nextlong(p);
				if (clip) gclip(ps,c,r,c1,r1);
				break;
         	case 10 :
				c=nextlong(p);
				r=nextlong(p);
				c1=nextlong(p);
				r1=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				width=nextint(p);
				gline(ps,c,r,c1,r1,col,st,width);
				break;
			case 20 :
				c=nextlong(p);
				r=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				gmarker(ps,c,r,col,st);
				break;
			case 30 :
				n=nextint(p);
				for (i=0; i<n; i++)
				{	cc[2*i]=nextlong(p);
					cc[2*i+1]=nextlong(p);
					co[i]=nextint(p);
				}
				st=nextint(p);
				gfill(ps,cc,st,n,co);
				break;
			case 31 :
				for (i=0; i<8; i++) cc[i]=nextlong(p);
				hue=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				gfillh(ps,cc,hue,col,st);
				break;
			case 32 :
				c=nextlong(p);
				r=nextlong(p);
				c1=nextlong(p);
				r1=nextlong(p);
				hue=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				gbar(ps,c,r,c1,r1,hue,col,st);
				break;
			case 33 :
				c=nextlong(p);
				r=nextlong(p);
				c1=nextlong(p);
				r1=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				gbar1(ps,c,r,c1,r1,col,st);
				break;
			case 40 :
				c=nextlong(p);
				r=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				gtext(ps,c,r,p,col,st);
				p+=strlen(p)+1;
				break;
			case 41 :
				c=nextlong(p);
				r=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				gvtext(ps,c,r,p,col,st);
				p+=strlen(p)+1;
				break;
			case 42 :
				c=nextlong(p);
				r=nextlong(p);
				col=nextint(p);
				st=nextint(p);
				gvutext(ps,c,r,p,col,st);
				p+=strlen(p)+1;
				break;
			case 50 :
				nextlong(p);
				break;
			default :
            	Active=1;
				return;
		}
	}
	Active=1;
}