Esempio n. 1
0
template<> void Jsonize(JsonIO& io, Date& var)
{
	if(io.IsLoading()) {
		const Value& v = io.Get();
		if(IsNull(v)) {
			var = Null;
			return;
		}
		if(IsString(v)) {
			String text = v;
			if(text.GetCount() > 6) {
				Date d;
				d.year = ScanInt(text.Left(4));
				d.month = ScanInt(text.Mid(4, 2));
				d.day = ScanInt(text.Mid(6));
				if(d.IsValid()) {
					var = d;
					return;
				}
			}
		}
		throw JsonizeError("string expected for Date value");
	}
	else
		if(IsNull(var))
			io.Set(Null);
		else
			io.Set(Format("%04d%02d%02d", var.year, var.month, var.day));
}
Esempio n. 2
0
void Input(void) {
    n = ScanInt();
    for (int i = 1; i <= n; i++) {
        a[i].x = ScanInt(), a[i].y = ScanInt(), a[i].r = ScanInt();
        l = std::min(l, double(a[i].x - a[i].r));
        r = std::max(r, double(a[i].x + a[i].r));
    }
}
Esempio n. 3
0
	void Input(void) {
		n = ScanInt(); T.n = n;
		for (int i = 1, tmp; i <= n; i++) {
			a[i] = tmp = ScanInt();
			T.Push(i, tmp);
			Ans += T.SumMax(1, i - 1, tmp);
		}
	}
Esempio n. 4
0
	inline void Input(void) {
		n = ScanInt();
		for (int i = 1; i < n; i++) {
			int x = ScanInt(), y = ScanInt(), c = ScanInt() % 3;
			a[x] = new Edge(y, c, a[x]);
			a[y] = new Edge(x, c, a[y]);
		}
	}
Esempio n. 5
0
	inline void Input(void) {
		n = ScanInt(), m = ScanInt(), k = ScanInt();
		for (int i = 1; i <= m; i++) {
			int x = ScanInt(), y = ScanInt();
			a[x] = new Edge(y, a[x]);
			a[y] = new Edge(x, a[y]);
			a[x]->opt = a[y];
			a[y]->opt = a[x];
		}
	}
Esempio n. 6
0
	inline void Input(void) {
		n = ScanInt(), vmax = ScanInt(), v2 = ScanInt();ScanChr();
		int last = ScanInt();n--;
		for (int i = 1; i <= n; i++) {
			int d = ScanChr(), t = ScanInt();
			a[i].index = i, a[i].t = t - last, a[i].d = d;
			last = t;
		}
		std::sort(a + 1, a + n + 1);
	}
Esempio n. 7
0
	void Input(void) {
		n = ScanInt(), h = ScanInt(), delta = ScanInt();
		for (int i = 1; i <= n; i++) {
			int tmp = ScanInt();
			for (int j = 1; j <= tmp; j++) {
				int h = ScanInt();
				s[i][h]++;
			}
		}
	}
Esempio n. 8
0
	inline void solve(void) {
		int t = ScanInt();
		while (t--) {
			a.clear();
			int n = ScanInt();
			for (int i = 1; i <= n; i++) {
				int p = ScanInt();
				if (a.find(p) == a.end()) printf("%d ", p), a.insert(p);
			}
			puts("");
		}
	}
Esempio n. 9
0
	void Input(void) {
		n = ScanInt(), m = ScanInt();
		vs = n + m + 1, vt = vs + 1;
		for (int i = 1; i <= m; i++) {
			int x = ScanInt(), y = ScanInt();
			AddEdge(i, x + m, 1);
			AddEdge(i, y + m, 1);
			AddEdge(vs, i, 1);
		}
		for (int i = m + 1; i <= n + m; i++)
			AddEdge(i, vt, 0);
	}
Esempio n. 10
0
	void Input(void) {
		n = ScanInt(), m = ScanInt();
		for (int i = 1; i <= m; i++) {
			E[i].x = ScanInt(), E[i].y = ScanInt(), E[i].z = ScanInt();
			a[E[i].x] = new Edge(E[i].y, E[i].z, a[E[i].x]);
			a[E[i].y] = new Edge(E[i].x, E[i].z, a[E[i].y]);
			a[E[i].x]->opt = a[E[i].y];
			a[E[i].y]->opt = a[E[i].x];
			E[i].index = a[E[i].x]->index = a[E[i].y]->index = i;
		}
		std::sort(E + 1, E + m + 1, cmp);
	}
Esempio n. 11
0
	inline void Input(void) {
		n = ScanInt();
		for (int i = 1; i <= n; i++) {
			int t = ScanInt(); memset(vis, 0, sizeof vis); vis[i] = true;
			for (int j = 1; j <= t; j++) {
				int x = ScanInt(); E[i].push_back(x);
				a[i * 2] = new Edge(x * 2 - 1, a[i * 2]);
				vis[x] = true;
				//printf("%d -> %d;\n", i * 2, x * 2 - 1);
			}
			for (int j = 1; j <= n; j++) if (!vis[j]) a[i * 2 - 1] = new Edge(j * 2, a[i * 2 - 1]);//, printf("%d -> %d;\n", i * 2 - 1, j * 2);
		}
	}
Esempio n. 12
0
	inline void Input(void) {
		n = ScanInt(), m = ScanInt(), k = ScanInt(), s = ScanInt(), t = ScanInt();
		while (m--) {
			int x = ScanInt(), y = ScanInt(), z = ScanInt();
			a[x] = new Edge(y, z, a[x]);
			a[y] = new Edge(x, z, a[y]);
		}
	}
Esempio n. 13
0
void RegisterExample(const char *name, ScatterDemo* (*ctrl)(), String fileName)
{
	Example& x = Examples().Add();
	x.name = name;
	x.ctrl = ctrl;
	x.index = ScanInt(GetFileName(fileName).Mid(3, 2));
}
Esempio n. 14
0
ProductVersion::ProductVersion(String const &s)
{
	Vector<String>sv = Split(s, '.', false);
	if(sv.GetCount() > 0)
		major = ScanInt(sv[0]);
	else
		major = 0;
	if(sv.GetCount() > 1)
		minor = ScanInt(sv[1]);
	else
		minor = 0;
	if(sv.GetCount() > 2)
		devel = ScanInt(sv[2]);
	else
		devel = 0;
}
Esempio n. 15
0
inline Time VfkReadTime(const char *p, void *endptr)
{
	int fields[6];
	ZeroArray(fields);
	int nfld = 0;
	for(;;)
		if(IsDigit(*p)) {
			int v = ScanInt(p, &p);
			if(IsNull(v) || v < 0)
				return Null;
			fields[nfld++] = v;
			if(nfld >= 6)
				break;
		}
		else if(*p == ' ' || *p == ':' || *p == '.')
			p++;
		else
			break;
	if(endptr)
		*(const char **)endptr = p;
	if(nfld < 3)
		return Null;
	if(fields[0] >= 1 && fields[0] <= 31
	&& fields[1] >= 1 && fields[1] <= 12
	&& fields[2] >= 1900 && fields[2] <= 2900
	&& fields[3] >= 0 && fields[3] <= 23
	&& fields[4] >= 0 && fields[4] <= 59
	&& fields[5] >= 0 && fields[5] <= 59) {
		Time dt(fields[2], fields[1], fields[0], fields[3], fields[4], fields[5]);
		if(dt.IsValid())
			return dt;
	}
	return Null;
}
Esempio n. 16
0
	void solve(void) {
		n = ScanInt();
		T.push_back(Node(ScanInt(), 1)); ScanInt();
		int Ans = 0;
		for (int i = 2; i <= n; i++) {
			int l = ScanInt(), r = ScanInt();
			while (!T.empty() && T.front().low > r) T.pop_front();
			if (!T.empty()) {
				int Now = i - T.front().pos + 1;
				Ans = std::max(Ans, Now);
			}
			int pos = i;
			while (!T.empty() && T.back().low < l) pos = T.back().pos, T.pop_back();
			T.push_back(Node(l, pos));
		}
		printf("%d\n", Ans);
	}
Esempio n. 17
0
inline void Work(void) {
    int m = ScanInt();
    while (m--) {
        register int l = ScanInt(), r = ScanInt();
        register int h = r - l + 1, tmp = h;
        while (tmp != 1) {
            register int f = fac[tmp], p = 1;
            while (fac[tmp] == f) {
                tmp /= f;
                register int next_p = p * f;
                if (Equal(l, r - h / next_p, l + h / next_p, r)) p = next_p;
            }
            h /= p;
        }
        printf("%d\n", h);
    }
}
Esempio n. 18
0
// do setup work here
Options::Options()
{
	CtrlLayout(*this,"Options");
	Icon(OptionsImg::Options());

	// set callback for the save button
	btnSave <<= THISBACK(onbtnSave);

	// get the values from the config file
	VectorMap<String, String> cfg = LoadIniFile(cfgfile);
	int dontsplash = ScanInt(cfg.Get("Splash", Null));
	int savewinpos = ScanInt(cfg.Get("SaveWinPos", Null));

    // set option controls with current value from config file
	optSplash = dontsplash;
	optSaveWinPos = savewinpos;
}
Esempio n. 19
0
	inline void Work(void) {
		bool last = get(1);
		int k = ScanInt();
		for (int i = 1; i <= (k << 1); i++) {
			int nx = ScanInt(), ny = ScanInt();
			std::swap(a[px][py], a[nx][ny]);
			px = nx, py = ny;
			bool now = get((i&1) ? 2 : 1);
			if (i&1) now ^= 1;
			if ((i&1) && last && !now)
				ret.push_back(i);
			last = now;
		}
		printf("%ld\n",ret.size());
		for (std::vector<int>::iterator it = ret.begin(); it != ret.end(); ++it)
			printf("%d\n",(*it + 1) >> 1);
	}
Esempio n. 20
0
	inline void Input(void) {
		n = ScanInt(), l = ScanInt(), m = ScanInt();
		int tmp[MAXN][MAXL] = {0};
		scanf("\n");pow[0] = 1;
		for (int i = 1; i <= l; i++) pow[i] = pow[i - 1] * Base;
		for (int i = 1; i <= n; i++) {
			Int64 &h = hash[i];
			for (int j = 1; j <= l; j++) {
				a[i][j] = tmp[i][j] = ScanChr();
				h = h * Base + a[i][j];
			}
			if (T[h] == 0) T[h] = ++cnt;
		}
		Int64 H[MAXN]; memcpy(H, hash, sizeof hash);
		for (int i = 1; i <= m; i++) {
			int l1 = ScanInt(), p1 = ScanInt(), l2 = ScanInt(), p2 = ScanInt();
			Int64 delta1 = (Int64) (tmp[l1][p1] - tmp[l2][p2]) * pow[l - p2], 
			      delta2 = (Int64) (tmp[l2][p2] - tmp[l1][p1]) * pow[l - p1];
			std::swap(tmp[l1][p1], tmp[l2][p2]);
			H[l1] += delta2, H[l2] += delta1;
			if (T[H[l1]] == 0) T[H[l1]] = ++cnt;
			if (T[H[l2]] == 0) T[H[l2]] = ++cnt;
			List[i].l1 = l1, List[i].l2 = l2, List[i].p1 = p1, List[i].p2 = p2;
		}
	}
Esempio n. 21
0
	inline void Work(void) {
		for (int i = 1; i <= m; i++) {
			int x = ScanInt(), y = ScanInt();
			if (circle[x] != circle[y]) {
				puts("-1 -1");
				continue;
			}
			if (root[x] == root[y]) {
				int t = Lca(x, y);
				printf("%d %d\n", deep[x] - deep[t], deep[y] - deep[t]);
				continue;
			}
			int l1 = pos[root[y]] - pos[root[x]], l2 = pos[root[x]] - pos[root[y]];
			if (pos[root[x]] > pos[root[y]]) l1 += len[circle[x]]; 
			if (pos[root[x]] < pos[root[y]]) l2 += len[circle[x]];
			Out(x, y, l1, l2);
		}
	}
Esempio n. 22
0
double ScanDoubleT(const T *p, const T **endptr, bool accept_comma)
{
	const T *begin = p;
	while(*p && (byte)*p <= ' ')
		p++;
	bool neg = false;
	if(endptr)
		*endptr = p;
	if(*p == '+' || *p == '-')
		neg = (*p++ == '-');
	if((byte)(*p - '0') >= 10 && !((*p == '.' || accept_comma && *p == ',') && (byte)(p[1] - '0') < 10)) {
		if(endptr) *endptr = begin;
		return Null;
	}
	double mantissa = 0;
	T c;
	int exp = 0;
	while((byte)(*p - '0') < 10)
		if((c = *p++) != '0') {
			if(exp) { mantissa *= ipow10(exp); exp = 0; }
			mantissa = 10 * mantissa + c - '0';
		}
		else
			exp++;
	int raise = exp;
	if(*p == '.' || accept_comma && *p == ',') // decimal part
		while((byte)((c = *++p) - '0') < 10) {
			if(c != '0') {
				if(raise) {
					mantissa *= ipow10(raise);
					exp -= raise;
					raise = 0;
				}
				exp--;
				mantissa = 10 * mantissa + c - '0';
				if(!IsFin(mantissa))
					return Null;
			}
			else
				raise++;
		}
	if(*p == 'E' || *p == 'e') { // exponent
		int vexp = ScanInt(p + 1, &p);
		if(IsNull(vexp))
			return Null;
		exp += vexp;
	}
	if(endptr) *endptr = p;
	if(exp) {
		double e = ipow10(tabs(exp));
		mantissa = (exp > 0 ? mantissa * e : mantissa / e);
	}
	if(!IsFin(mantissa))
		return Null;
	return neg ? -mantissa : mantissa;
}
Esempio n. 23
0
void VfkStream::ScanHeader(const char *b, Table& table)
{
	int colid = 0;
	while(*b && *b != '\n') {
		if(IsAlpha(*b)) {
			const char *id = b;
			while(IsIdent(*++b))
				;
			Column col;
			col.name = String(id, b);
			try {
				while(*b == ' ')
					b++;
				col.vtype = ERROR_V;
				col.width = Null;
				switch(*b++) {
					case 'N': {
						col.vtype = DOUBLE_V;
						break;
					}
					case 'T': {
						col.vtype = STRING_V;
						if(!IsDigit(*b))
							throw Exc("missing string width");
						col.width = ScanInt(b, &b);
						break;
					}
					case 'D': {
						col.vtype = TIME_V;
						break;
					}
					default: {
						throw Exc(NFormat("invalid data type '%c'", *--b));
					}
				}
				if(colid < table.columns.GetCount()) {
					const Column& old = table.columns[colid];
					if(old.name != col.name)
						throw Exc(NFormat("column name mismatch (%s / %s)", old.name, col.name));
					if(old.vtype != col.vtype)
						throw Exc(NFormat("column type mismatch (%d / %d)", old.vtype, col.vtype));
					if(old.width != col.width)
						throw Exc(NFormat("column width mismatch (%~d / %~d)", old.width, col.width));
				}
				else
					table.AddColumn(col);
				colid++;
			}
			catch(Exc e) {
				throw Exc(NFormat("column '%s': %s", colid, e));
			}
		}
		else
			b++;
	}
}
Esempio n. 24
0
	void Work(void) {
		int Q = ScanInt();
		for (int i = 1; i <= Q; i++) {
			printf("%d\n", Ans);
			int l = ScanInt(), r = ScanInt();
			if (l > r) std::swap(l, r);
			int dr = (T.Sum(l + 1, r - 1, a[r])) - (T.SumMax(l + 1, r - 1, a[r]));
			int dl = (T.SumMax(l + 1, r - 1, a[l]) - (T.Sum(l + 1, r - 1, a[l])));
			Ans += dr + dl;
			if (a[l] > a[r]) Ans--;
			if (a[l] < a[r]) Ans++;
			T.Erase(l, a[l]);
			T.Erase(r, a[r]);
			std::swap(a[l], a[r]);
			T.Push(l, a[l]);
			T.Push(r, a[r]);
		}
		printf("%d\n", Ans);
	}
Esempio n. 25
0
	inline void solve(void) {
		n = ScanInt();
		for (int i = 1; i <= n; i++) a[i] = ScanInt();
		sort(a + 1, a + n + 1); n = unique(a + 1, a + n + 1) - a - 1;
		int Ans = 0; 
		for (int i = 1; i <= n; i++) {
			int t = 0;
			for (int j = 1; j * j <= a[i]; j++) if (a[i] % j == 0) {
				if (j != 1) t = max(fac[j], t);
				t = max(fac[a[i] / j], t);
			}
			f[i] = t + 1;
			for (int j = 1; j * j<= a[i]; j++) if (a[i] % j == 0) {
				if (j != 1) fac[j] = max(fac[j], f[i]);
				fac[a[i] / j] = max(fac[a[i] / j], f[i]);
			}
			Ans = max(Ans, f[i]);
		}
		printf("%d\n", Ans);
	}
Esempio n. 26
0
inline void Input(void) {
    n = ScanInt();
    pow1[0] = pow2[0] = 1;
    for (int i = 1; i <= n; i++) {
        int t;
        while (!islower(t = getchar()));
        pow1[i] = pow1[i - 1] * base1 % mod1;
        pow2[i] = pow2[i - 1] * base2 % mod2;
        sum1[i] = (sum1[i - 1] * base1 + t) % mod1;
        sum2[i] = (sum2[i - 1] * base2 + t) % mod2;
    }
}
Esempio n. 27
0
template<> void Jsonize(JsonIO& io, Time& var)
{
	if(io.IsLoading()) {
		const Value& v = io.Get();
		if(IsNull(v)) {
			var = Null;
			return;
		}
		if(IsString(v)) {
			String text = v;
			if(text.GetCount() > 15) {
				Time tm;
				tm.year = ScanInt(text.Left(4));
				tm.month = ScanInt(text.Mid(4, 2));
				tm.day = ScanInt(text.Mid(6, 2));
				tm.hour = ScanInt(text.Mid(9, 2));
				tm.minute = ScanInt(text.Mid(12, 2));
				tm.second = ScanInt(text.Mid(15));
				if(tm.IsValid()) {
					var = tm;
					return;
				}
			}
		}
		throw JsonizeError("string expected for Time value");
	}
	else
		if(IsNull(var))
			io.Set(Null);
		else
			io.Set(Format("%04d%02d%02d`T%02d:%02d:%02d",
				          var.year, var.month, var.day, var.hour, var.minute, var.second));
}
Esempio n. 28
0
	inline void solve(void) {
		k = ScanInt(); int N = 0;
		for (int i = 1; i <= k; i++) {
			t = ScanInt();
			for (int j = 1; j <= t; j++) a[++N].second = i, a[N].first = ScanInt();
		}
		sort(a + 1, a + N + 1);
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= k; j++) if (j != a[i].second)
				prev[i] = max(prev[i], hash[j]);
			hash[a[i].second] = i;
			if (a[prev[prev[i]]].second == a[i].second) pprev[i] = pprev[prev[i]]; else pprev[i] = prev[prev[i]];
		}
		memset(hash, 60, sizeof hash);
		for (int i = N; i >= 1; i--) {
			next[i] = N + 1; nnext[i] = N + 1;
			for (int j = 1; j <= k; j++) if (j != a[i].second)
				next[i] = min(next[i], hash[j]);
			hash[a[i].second] = i;
			if (a[next[next[i]]].second == a[i].second) nnext[i] = nnext[next[i]]; else nnext[i] = next[next[i]];
		}
		bool ok = false;
		for (int i = 1; i <= N; i++) if (next[i] <= N && prev[i]) {
			int lll = pprev[i], l = prev[i], r = next[i], rrr = nnext[i];
			if (a[l].second != a[r].second && a[l].first + a[i].first > a[r].first) {
				O(l, i, r);
				ok = true; break;
			} else
			if (lll && a[lll].first + a[i].first > a[r].first) {
				O(lll, i, r);
				ok = true; break;
			} else
			if (rrr <= N && a[l].first + a[i].first > a[rrr].first) {
				O(l, i, rrr);
				ok = true; break;
			}
		}
		if (!ok) puts("NIE");
	}
Esempio n. 29
0
	inline void Input(void) {
		n = ScanInt(), m = ScanInt();
		for (int i = 1; i <= n; i++) h[i] = ScanInt();
		while (m--) {
			int x = ScanInt(), y = ScanInt(), z = ScanInt();
			if (x[h] >= y[h]) a[x] = new Edge(y, z, a[x]);
			if (y[h] >= x[h]) a[y] = new Edge(x, z, a[y]);
		}
	}
Esempio n. 30
0
	inline void Input(void) {
		n = ScanInt();
		for (int i = 1; i < n; i++) {
			int x = ScanInt(), y = ScanInt();Int64 z = ScanInt();
			a[x] = new Edge(y, z, a[x]);
			a[y] = new Edge(x, z, a[y]);
		}
		for (int i = 2; i <= n; i++) 
			w[i] = ScanInt(), v[i] = ScanInt();
	}