int main() { int T; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%d%d", x+i, y+i); for(int j=0; j<i; j++) e[cnt++] = (edge) { i, j, abs(x[i]-x[j]) + abs(y[i]-y[j]) }; } sort(e, e+cnt); for(int i=0, j = 0; i<cnt && j!=n-1; i++) { int a = findr(e[i].a), b = findr(e[i].b); if(a != b) { ans += e[i].dis; uni(a, b); j++; } } printf("%d\n", cnt); } return 0; }
void caseaf(void) { int i, k; Tchar j; lgf++; if (skip() || !(i = getrq()) || skip()) return; k = 0; j = getch(); if (!isalpha(cbits(j))) { ch = j; while ((j = cbits(getch())) >= '0' && j <= '9') k++; } if (!k) k = j; numtabp[findr(i)].fmt = k; /* was k & BYTEMASK */ }
void casemk(void) { register int i, j; struct numtab *np; if (dip != d) j = dip->dnl; else j = numtab[NL].val; if (skip(0)) { dip->mkline = j; return; } if ((i = getrq(1)) == 0) return; np = findr(i); np->val = j; prwatchn(np); }
int main(){ int i,j,k,l,test,t=1; // freopen("in.txt","r",stdin); while(scanf("%d",&n)==1){ if(n<3) break; nd=n; scanf("%lf",&area); findap(); findr(); areain=apothem*pi; double ans1=area-areain; areaout=r*pi; double ans2=areaout-area; printf("Case %d: %.5lf %.5lf\n",t++,ans2,ans1); } return 0; }
/* * .nr request; if tracing, don't check optional * 2nd argument because tbl generates .in 1.5n */ void casenr(void) { int i, j; int savtr = trace; lgf++; skip(); if ((i = findr(getrq())) == -1) goto rtn; skip(); j = inumb(&numtabp[i].val); if (nonumb) goto rtn; numtabp[i].val = j; skip(); trace = 0; j = atoi0(); /* BUG??? */ trace = savtr; if (nonumb) goto rtn; numtabp[i].inc = j; rtn: return; }
Tchar getch(void) { int k; Tchar i, j; g0: if (ch) { i = ch; if (cbits(i) == '\n') nlflg++; ch = 0; return(i); } if (nlflg) return('\n'); i = getch0(); if (ismot(i)) return(i); k = cbits(i); if (k >= sizeof(gchtab)/sizeof(gchtab[0]) || gchtab[k] == 0) /* nothing special */ return(i); if (k != ESC) { if (k == '\n') { nlflg++; if (ip == 0) numtabp[CD].val++; /* line number */ return(k); } if (k == FLSS) { copyf++; raw++; i = getch0(); if (!fi) flss = i; copyf--; raw--; goto g0; } if (k == RPT) { setrpt(); goto g0; } if (!copyf) { if (k == 'f' && lg && !lgf) { i = getlg(i); return(i); } if (k == fc || k == tabch || k == ldrch) { if ((i = setfield(k)) == 0) goto g0; else return(i); } if (k == '\b') { i = makem(-width(' ' | chbits)); return(i); } } return(i); } k = cbits(j = getch0()); if (ismot(j)) return(j); switch (k) { case 'n': /* number register */ setn(); goto g0; case '$': /* argument indicator */ seta(); goto g0; case '*': /* string indicator */ setstr(); goto g0; case '{': /* LEFT */ i = LEFT; goto gx; case '}': /* RIGHT */ i = RIGHT; goto gx; case '"': /* comment */ while (cbits(i = getch0()) != '\n') ; if (ip == 0) numtabp[CD].val++; /* line number */ nlflg++; return(i); /* experiment: put it here instead of copy mode */ case '(': /* special char name \(xx */ case 'C': /* \C'...' */ if ((i = setch(k)) == 0) goto g0; goto gx; case ESC: /* double backslash */ i = eschar; goto gx; case 'e': /* printable version of current eschar */ i = PRESC; goto gx; case '\n': /* concealed newline */ numtabp[CD].val++; goto g0; case ' ': /* unpaddable space */ i = UNPAD; goto gx; case '\'': /* \(aa */ i = ACUTE; goto gx; case '`': /* \(ga */ i = GRAVE; goto gx; case '_': /* \(ul */ i = UNDERLINE; goto gx; case '-': /* current font minus */ i = MINUS; goto gx; case '&': /* filler */ i = FILLER; goto gx; case 'c': /* to be continued */ i = CONT; goto gx; case '!': /* transparent indicator */ i = XPAR; goto gx; case 't': /* tab */ i = '\t'; return(i); case 'a': /* leader (SOH) */ /* old: *pbp++ = LEADER; goto g0; */ i = LEADER; return i; case '%': /* ohc */ i = OHC; return(i); case 'g': /* return format of a number register */ setaf(); /* should this really be in copy mode??? */ goto g0; case '.': /* . */ i = '.'; gx: setsfbits(i, sfbits(j)); return(i); } if (copyf) { *pbp++ = j; return(eschar); } switch (k) { case 'f': /* font indicator */ setfont(0); goto g0; case 's': /* size indicator */ setps(); goto g0; case 'v': /* vert mot */ numerr.type = numerr.escarg = 0; numerr.esc = k; if (i = vmot()) { return(i); } goto g0; case 'h': /* horiz mot */ numerr.type = numerr.escarg = 0; numerr.esc = k; if (i = hmot()) return(i); goto g0; case '|': /* narrow space */ if (NROFF) goto g0; return(makem((int)(EM)/6)); case '^': /* half narrow space */ if (NROFF) goto g0; return(makem((int)(EM)/12)); case 'w': /* width function */ setwd(); goto g0; case 'p': /* spread */ spread++; goto g0; case 'N': /* absolute character number */ numerr.type = numerr.escarg = 0; numerr.esc = k; if ((i = setabs()) == 0) goto g0; return i; case 'H': /* character height */ numerr.type = numerr.escarg = 0; numerr.esc = k; return(setht()); case 'S': /* slant */ numerr.type = numerr.escarg = 0; numerr.esc = k; return(setslant()); case 'z': /* zero with char */ return(setz()); case 'l': /* hor line */ numerr.type = numerr.escarg = 0; numerr.esc = k; setline(); goto g0; case 'L': /* vert line */ numerr.type = numerr.escarg = 0; numerr.esc = k; setvline(); goto g0; case 'D': /* drawing function */ numerr.type = numerr.escarg = 0; numerr.esc = k; setdraw(); goto g0; case 'X': /* \X'...' for copy through */ setxon(); goto g0; case 'b': /* bracket */ setbra(); goto g0; case 'o': /* overstrike */ setov(); goto g0; case 'k': /* mark hor place */ if ((k = findr(getsn())) != -1) { numtabp[k].val = numtabp[HP].val; } goto g0; case '0': /* number space */ return(makem(width('0' | chbits))); case 'x': /* extra line space */ numerr.type = numerr.escarg = 0; numerr.esc = k; if (i = xlss()) return(i); goto g0; case 'u': /* half em up */ case 'r': /* full em up */ case 'd': /* half em down */ return(sethl(k)); default: return(j); } /* NOTREACHED */ }
void setn(void) { int i, j, f; Tchar ii; Uchar *p; char buf[NTM]; /* for \n(.S */ f = nform = 0; if ((i = cbits(ii = getach())) == '+') f = 1; else if (i == '-') f = -1; else if (ii) /* don't put it back if it's already back (thanks to jaap) */ ch = ii; if (falsef) f = 0; if ((i = getsn()) == 0) return; p = unpair(i); if (p[0] == '.') switch (p[1]) { case 's': i = pts; break; case 'v': i = lss; break; case 'f': i = font; break; case 'p': i = pl; break; case 't': i = findt1(); break; case 'o': i = po; break; case 'l': i = ll; break; case 'i': i = in; break; case '$': i = frame->nargs; break; case 'A': i = ascii; break; case 'c': i = numtabp[CD].val; break; case 'n': i = lastl; break; case 'a': i = ralss; break; case 'h': i = dip->hnl; break; case 'd': if (dip != d) i = dip->dnl; else i = numtabp[NL].val; break; case 'u': i = fi; break; case 'j': i = ad + 2 * admod; break; case 'w': i = widthp; break; case 'x': i = nel; break; case 'y': i = un; break; case 'T': i = dotT; break; /* -Tterm used in nroff */ case 'V': i = VERT; break; case 'H': i = HOR; break; case 'k': i = ne; break; case 'P': i = print; break; case 'L': i = ls; break; case 'R': /* maximal # of regs that can be addressed */ i = 255*256 - regcnt; break; case 'z': p = unpair(dip->curd); *pbp++ = p[1]; /* watch order */ *pbp++ = p[0]; return; case 'b': i = bdtab[font]; break; case 'F': cpushback(cfname[ifi]); return; case 'S': buf[0] = j = 0; for( i = 0; tabtab[i] != 0 && i < NTAB; i++) { if (i > 0) buf[j++] = ' '; sprintf(&buf[j], "%d", tabtab[i] & TABMASK); j = strlen(buf); if ( tabtab[i] & RTAB) sprintf(&buf[j], "uR"); else if (tabtab[i] & CTAB) sprintf(&buf[j], "uC"); else sprintf(&buf[j], "uL"); j += 2; } cpushback(buf); return; default: goto s0; } else { s0: if ((j = findr(i)) == -1) i = 0; else { i = numtabp[j].val = numtabp[j].val + numtabp[j].inc * f; nform = numtabp[j].fmt; } } setn1(i, nform, (Tchar) 0); }
void casetl(void) { int j; int w[3]; Tchar buf[LNSIZE]; Tchar *tp; Tchar i, delim; /* * bug fix * * if .tl is the first thing in the file, the p1 * doesn't come out, also the pagenumber will be 0 * * tends too confuse the device filter (and the user as well) */ if (dip == d && numtabp[NL].val == -1) newline(1); dip->nls = 0; skip(); if (ismot(delim = getch())) { ch = delim; delim = '\''; } else delim = cbits(delim); tp = buf; numtabp[HP].val = 0; w[0] = w[1] = w[2] = 0; j = 0; while (cbits(i = getch()) != '\n') { if (cbits(i) == cbits(delim)) { if (j < 3) w[j] = numtabp[HP].val; numtabp[HP].val = 0; if (w[j] != 0) *tp++ = WORDSP; j++; *tp++ = 0; } else { if (cbits(i) == pagech) { setn1(numtabp[PN].val, numtabp[findr('%')].fmt, i&SFMASK); continue; } numtabp[HP].val += width(i); if (tp < &buf[LNSIZE-10]) { if (cbits(i) == ' ' && *tp != WORDSP) *tp++ = WORDSP; *tp++ = i; } else { ERROR "Overflow in casetl" WARN; } } } if (j<3) w[j] = numtabp[HP].val; *tp++ = 0; *tp++ = 0; *tp = 0; tp = buf; if (NROFF) horiz(po); while (i = *tp++) pchar(i); if (w[1] || w[2]) horiz(j = quant((lt - w[1]) / 2 - w[0], HOR)); while (i = *tp++) pchar(i); if (w[2]) { horiz(lt - w[0] - w[1] - w[2] - j); while (i = *tp++) pchar(i); } newline(0); if (dip != d) { if (dip->dnl > dip->hnl) dip->hnl = dip->dnl; } else { if (numtabp[NL].val > dip->hnl) dip->hnl = numtabp[NL].val; } }