S+2 DP
A.小泽做披萨
简单的用状态压缩进行表示状态12345678910111213141516171819202122232425262728293031323334#define MAX 22int n, m, a, b;int mark[1 << MAX], idx[1 << MAX];bool DP[1 << MAX];signed main() { IOS; cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; --a, --b; mark[a] |= (1 << b); mark[b] |= (1 << a); } DP[0] = 1; for (int i = 1; i <= n; i++) { idx[1 < ...
TEST 1
A 不想走
求一下最短的距离就好了12345678signed main() { IOS; int a, b, x, y; cin >> a >> b >> x >> y; cout << min({abs(b - a), abs(a - x) + abs(y - b), abs(a - y) + abs(b - x)}) << endl; return 0;}
B 连续数求和
直接暴力就好了1234567891011121314151617181920212223242526272829303132333435int main() { int T; cin>>T; for(int i=1;i<=100000;i++) { a[i]=a[i-1]+i; } for(int i=1;i<=T;i++) { cin>>n; for(int j=2;j<=1000 ...
S+1 DP1
A. 多重背包问题 II
用优先队列维护可以做到n2的时间复杂度1234567891011121314151617181920212223242526272829303132333435363738signed main(){ IOS; // solve(); // return 0; int n, m; cin >> n >> m; //cout << n << ' ' << m << endl; for (int i = 1; i <= n; i++) { int v, w, s; cin >> v >> w >> s; //s = min(s, m / v); deque<int> q; //cout << "SS : " << v << ...
ABC basket
ABC375D123456789101112131415161718192021222324252627const int mod = 998244353;int mypow(int a, int b) { int res = 1; while (b) { if (b & 1) { res *= a; res %= mod; } b >>= 1; a *= a; a %= mod; } return res;}signed main(){ IOS; int n; cin >> n; int len = to_string(n).size(); int b = mypow(10, len); int res = n % mod * (mypow(b, n) - 1) % mod * (mypow(b - 1, mod ...
abc 374
A12345678910111213141516signed main(){ IOS; string a; cin >> a; int n = a.size(); if (a[n - 3] == 's' && a[n - 2] == 'a' && a[n - 1] == 'n') { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0;}
B12345678910111213141516171819signed main() { IOS; string a; string b; cin >> a >> b; ...
abc 373
A1234567891011121314signed main() { IOS; int ans = 0; for (int i = 1; i <= 12; i++) { string a; cin >> a; if (a.size() == i) { ans++; } } cout << ans << endl; return 0;}
B12345678910111213141516signed main() { IOS; string a; cin >> a; int ans = 0; vector<int> b(30); for (int i = 1; i <= a.size(); i++) { b[a[i] - 'A'] = i; } ...
abc372
A123456789101112signed main() { IOS; string a; cin >> a; for (int i = 0; i < a.size(); i++) { if (a[i] != '.') { cout << a[i]; } } return 0;}
B
普普通通的三进制
123456789101112131415161718192021222324252627282930signed main() { IOS; int x; cin >> x; int tmp = x; int tot = 0; int res = 0; while (x) { int idx = x % 3; while (idx--) { ...
String text
nowcode 151651234567891011121314151617181920212223242526272829303132333435363738394041void solve() { string s; cin >> s; int n = s.size(); s = " " + s; vector<int> nxt(n + 1); for (int i = 2; i <= n; i++) { nxt[i] = nxt[i - 1]; while (nxt[i] && s[nxt[i] + 1] != s[i]) { nxt[i] = nxt[nxt[i]]; } nxt[i] += (s[nxt[i] + 1] == s[i]); } int cnt = count(nxt.begin() + 1, nxt.end(), nxt[ ...
abc371
A
大的加1,第二的在中间
1234567891011121314151617181920212223242526signed main() { IOS; int tmp[3][2] = {{1, 2}, {1, 3}, {2, 3}}; vector<int> v(4, 0); for (int i = 0; i < 3; i++) { int op; char x; cin >> x; if (x == '<') { op = 1; } else { op = 0; } v[tmp[i][op]]++; } for (int i = 1; i <= 3; i++) { // ...