It is the year 95 ACM (After the Crash of Microsoft). After many years of peace, a war has broken out. Your nation, the island of Evergreen Macros And Confusing Shortcuts (EMACS), is defending itself against the railway empire ruled by Visually Impaired Machinists (VIM).
这就是ACM的题目里面十分常见的一个景象——扩充缩写。这件事情是这么干的:已知一个缩写,比如ACM,我们找出一些词汇,让它们表达出一个含义,并且它的缩写是ACM,就像上文做的那样——After the Crash of Microsoft.
classV : public vector<int> { public: int index; int num, count; V(int idx = 0) :index(idx), num(-1), count(0) {
} booloperator < (const V &b) const { if (count != b.count){ return count > b.count; } else{ return index < b.index; } } }; intdfs(vector<V> &vs, V &v, int c){ v.num = c; int low = c; for (int u : v) { if (vs[u].num < 0) { int t = dfs(vs, vs[u], c + 1); low = min(low, t); if (v.num <= t) v.count++; } else low = min(low, vs[u].num); } return low; } voidsolve(int n, int m){ vector<V> vs; for (int i = 0; i < n; i++){ vs.push_back(V(i)); } int x, y; while (cin >> x >> y){ if (x < 0 && y < 0) break; vs[x].push_back(y); vs[y].push_back(x); } for (vector<V>::iterator it = vs.begin(); it != vs.end(); it++){ if ((*it).num < 0){ dfs(vs, *it, 0); if ((*it).count > 0){ (*it).count--; } } } sort(vs.begin(), vs.end()); for (int i = 0; i < m; i++){ cout << vs[i].index << ' ' << vs[i].count + 1 << 'n'; } } intmain(int agrc, char *agrv[]){ ios::sync_with_stdio(false); int n, m; while (cin >> n >> m, n m){ solve(n, m); cout << 'n'; } }
structBIT{ ll *vs; int N; BIT(int n){ N = n + 1; vs = new ll[N](); } ~BIT(){ delete[] vs; } voidadd(int k, ll a){ for (int i = k + 1; i<N; i += i&-i){ vs[i] += a; } } ll sum(int s, int t){ if (s>0) returnsum(0, t) - sum(0, s); ll res = 0; for (int i = t; i>0; i -= i&-i) res += vs[i]; return res; } }; structSeg{ BIT *dif, *pre; Seg(int n){ dif = newBIT(n); pre = newBIT(n); ll *is = new ll[n]; for (int i = 0; i<n; i++){ cin >> is[i]; } dif->add(0, is[0]); pre->add(0, 0); for (int i = 1; i<n; i++){ ll x = is[i] - is[i - 1]; pre->add(i, x*i); dif->add(i, x); } delete[] is; } ~Seg(){ delete dif; delete pre; } voidupdate(int s, int t, ll v){ dif->add(s, v); dif->add(t, -v); pre->add(s, v*s); pre->add(t, -v*t); } ll query(int s, int t){ if (s>0) returnquery(0, t) - query(0, s); ll ps = pre->sum(0, t); ll ds = dif->sum(0, t); return ds*t - ps; } }; voidsolve(int n, int m, int q){ Seg seg(n); int l = 0; for (int i = 0; i < q; i++){ int query; cin >> query; l = query - 1; cout << seg.query(l, l + m) << 'n'; seg.update(l, l + m, -1); } } intmain(int agrc, char *agrv[]){ int n, m, q; while (cin >> n >> m >> q){ solve(n, m, q); } }
//以下代码从标准输入流中读取空格分隔的两个数 a b string[] tempInput = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int a = int.Parse(tempInput[0]); int b = int.Parse(tempInput[1]);