int n,m,K,ID[maxn+5],val[maxn+5],ans[maxn+5][maxn+5]; char pic[maxn+5][maxn+5]; vector<int> e[maxn+5]; int ti,vis[maxn+5],who[maxn+5];
#define ID(x,y) (((x)<<1)-(y)) boolcheck(int i,int j){ bool fl=true; for (int k=1;k<=n;k++) if (pic[k][i]!=pic[k][j]) {fl=false;break;} if (fl) return i<j; for (int k=1;k<=n;k++) if (pic[k][i]<pic[k][j]) returnfalse; returntrue; } boolFind(int x){ if (vis[x]==ti) returnfalse; vis[x]=ti; for (auto y:e[x]) if (!who[y] || Find(who[y])) {who[y]=x;returntrue;} returnfalse; } voidDFS(int i){ ID[i]=ID[0];val[i]=++val[0]; if (who[i]){ for (int j=1;j<=n;j++) if (pic[j][i]>pic[j][who[i]]) ans[j][ID[0]]=val[i]; DFS(who[i]); } else { for (int j=1;j<=n;j++) if (pic[j][i]=='1') ans[j][ID[0]]=val[i]; } } intmain(){ scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%s",pic[i]+1); for (int i=1;i<=m;i++) for (int j=1;j<=m;j++) if (check(i,j)) e[j].push_back(i); K=m; for (int i=1;i<=m;i++) ti++,K-=Find(i); ti++; for (int i=1;i<=m;i++) vis[who[i]]=ti; printf("%d\n",K); for (int i=1;i<=n;i++) for (int j=1;j<=K;j++) ans[i][j]=1; for (int i=1;i<=m;i++) if (vis[i]<ti) ID[0]++,val[0]=1,DFS(i); for (int i=1;i<=m;i++) printf("%d",ID[i]),i<m?putchar(' '):puts(""); for (int i=1;i<=m;i++) printf("%d",val[i]),i<m?putchar(' '):puts(""); for (int i=1;i<=n;i++) for (int j=1;j<=K;j++) printf("%d",ans[i][j]),j<K?putchar(' '):puts(""); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 1007
char s[N];
inlinevoidwork(){ int n = rd(); scanf("%s", s + 1); for (int t = 1, i = 1; i <= n; ++t) { if (t & 1) ++i; else { if (s[i] != s[i + 1]) {puts("NO"); return;} i += 2; } } puts("YES"); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 200007
int a[N];
inlinevoidwork(){ int n = rd(), m = rd(); for (int i = 1; i <= n; ++i) a[i] = rd(); sort(a + 1, a + 1 + n); ll ans = 0; int l = 1, r = n; for (; l < r; ++l) { while (a[r] + a[l] > m && r > l) {ans += a[r] + 1; --r;} if (r > l) ans += a[r--]; elsebreak; ans += a[l] + 1; while (a[r] + a[l] > m && r > l) {ans += a[r] + 1; --r;} if (r > l) --ans; else {++l; break;} } if (l <= r) ans += a[l] + 1; printf("%lld\n", ans); }
intmain(){ work(); return0; }
E - Exchange
签到。
1 2 3 4 5 6 7 8 9 10 11 12 13
#include<cstdio> usingnamespacestd;
int te,A,B,C;
intmain(){ for (scanf("%d",&te);te;te--){ scanf("%d%d%d",&A,&B,&C); if (B<=C) printf("%d\n",(A+B-1)/B); elseputs("1"); } return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 5007
structnode {double x, w, c;} sol[N];
double f[N], ans;
intmain(){ int n = rd(), k = rd(); for (int i = 1; i <= n; ++i) {sol[i].x = rd(); sol[i].w = rd(); sol[i].c = rd();} sort(sol + 1, sol + 1 + n, [&](const node &a, const node &b){return a.x < b.x;}); for (int i = 1; i <= n; ++i) { f[i] = -sol[i].w; // the first one for (int j = 1; j < i; ++j) // the previous one is j f[i] = max(f[i], f[j] + (sol[i].c + sol[j].c) * (sol[i].x - sol[j].x) * k / 200.0 - sol[i].w); ans = max(ans, f[i]); } printf("%.15lf\n", ans); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 2007
int deg[N], Deg[N], p[N];
vector<int> e[N];
priority_queue<pii> q;
intmain(){ int n = rd(), m = rd(); for (int i = 1; i <= n; ++i) p[i] = rd(); for (int i = 1; i <= m; ++i) { int a = rd(), b = rd(); ++Deg[a]; e[b].push_back(a); } for (int i = 1; i <= n; ++i) { while (!q.empty()) q.pop(); for (int j = 1; j <= n; ++j) { deg[j] = Deg[j]; if (!deg[j] && j != i) q.push({p[j], j}); } int res = n; while (!q.empty()) { int u = q.top().second; q.pop(); if (p[u] < res) break; --res; for (auto v : e[u]) { --deg[v]; if (!deg[v] && v != i) q.push({p[v], v}); } } printf("%d ", res); }
intmain(){ scanf("%d",&n); int MIN=2e9; for (int i=1;i<=n;i++) for (int j=1,x;j<=n;j++){ scanf("%d",&x); ans+=x; if (i+j==n+1) MIN=min(MIN,x); } printf("%lld\n",ans-MIN); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 200007
inlineinttrans(){ staticchar s[20]; scanf("%s", s + 1); if (s[1] == 'M') return0; if (s[1] == 'T' && s[2] == 'u') return1; if (s[1] == 'W') return2; if (s[1] == 'T' && s[2] == 'h') return3; if (s[1] == 'F') return4; return (s[2] == 'a' ? 5 : 6); }
intmain(){ int n = rd(), m = rd(), k = rd(); for (int i = 1; i <= n; ++i) for (int t = rd(); t; --t) workday[i].push_back(trans()); for (int i = 1; i <= m; ++i) holiday.push(rd()); for (int i = 1; i <= k; ++i) { for (int t = rd(); t; --t) order[i].push(rd()); int u = order[i].front(); order[i].pop(); work[u].push(i); for (auto d : workday[u]) s[d].insert(u); } for (int i = 0, cnt = 1, K = k; K; ++cnt, i = (i == 6 ? 0 : i + 1)) { if (!holiday.empty() && cnt == holiday.front()) {holiday.pop(); continue;} addwork.clear(); for (int j = 0; j < 7; ++j) {add[j].clear(); del[j].clear();} for (auto x : s[i]) { int id = work[x].top(); work[x].pop(); if (work[x].empty()) for (auto d : workday[x]) del[d].insert(x); if (order[id].empty()) {--K; ans[id] = cnt;} else { int nxt = order[id].front(); order[id].pop(); addwork.push_back(make_pair(nxt, id)); for (auto d : workday[nxt]) add[d].insert(nxt); } } for (int j = 0; j < 7; ++j) for (auto x : del[j]) s[j].erase(x); for (int j = 0; j < 7; ++j) for (auto x : add[j]) s[j].insert(x); for (auto [x, id] : addwork) work[x].push(id); } for (int i = 1; i <= k; ++i) printf("%d ", ans[i]); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 1007
char s[N];
inlinevoidwork(){ int n = rd(); int ans = 1e9; int lim = sqrt(n); for (int i = 1; i <= lim; ++i) if (n % i == 0) { if (n / i > 1) ans = min(ans, i * (n / i - 1)); if (i > 1) ans = min(ans, (n / i) * (i - 1)); } printf("%d %d\n", ans, n - ans); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 500007 #define pb push_back
char s[N];
deque<int> a;
inlinevoidwork(){ a.clear(); scanf("%s", s + 1); int n = strlen(s + 1); int k = rd(); a.pb(s[1] - '0'); for (int i = 2; i <= n; ++i) { int x = s[i] - '0'; if (!k) {a.pb(x); continue;} if (x) { while (!a.empty() && k && a.back() > x) {a.pop_back(); --k;} if (!a.empty() && a.back() == 0 && k >= a.size() && x < a.front()) {k -= a.size(); a.clear();} a.push_back(x); } else { while (a.size() > 1 && k && a.back() > 0) {a.pop_back(); --k;} a.push_back(x); } } for (; k; --k) a.pop_back(); for (auto x : a) printf("%d", x); puts(""); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }