A:

发现最优的方案一定是选 $ l $ 和 $ 2 * l $,题目保证有解,直接输出即可

#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie();
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> " << endl;
using namespace std; typedef unsigned long long ull;
typedef long long ll; template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
} template <typename T>
void print(T x) {
if(x < 0) putchar('-'), x = -x;
if(x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
} template <typename T>
void print(T x, char t) {
print(x); putchar(t);
} int T, l, r; int main() {
read(T);
while(T--) {
read(l); read(r);
print(l, ' '); print(2 * l, '\n');
}
return 0;
}

B:

情况 1:所有字母都相同,输出 $ n * (n - 1) / 2 $ 即可

情况 2:左边有连续 $ x $ 个字母相同,右边有 $ y $ 个,第一个字母和最后一个字符相同,输出 $ (x + 1) * (y + 1) $

情况 3:左边有连续 $ x $ 个字母相同,右边有 $ y $ 个,第一个字母和最后一个字符不同,输出 $ x + y + 2 - 1 $,最后的 $ -1 $ 是因为整个串被算了 $ 2 $ 次

#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie();
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> " << endl;
using namespace std; typedef unsigned long long ull;
typedef long long ll; template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
} template <typename T>
void print(T x) {
if(x < 0) putchar('-'), x = -x;
if(x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
} template <typename T>
void print(T x, char t) {
print(x); putchar(t);
} const int N = 2e5 + 5, md = 998244353; char c[N];
int cnt[23333];
int n, cut1 = -1, cut2 = -1; inline int mul(int x, int y) { return (ll)x * y % md; } int main() {
read(n); scanf("%s", c + 1);
for(register int i = 2; i <= n; i++) if(c[i] != c[i - 1]) { cut1 = i - 1; break; }
for(register int i = n - 1; i >= 1; i--) if(c[i] != c[i + 1]) { cut2 = i + 1; break; }
if(cut1 == -1) cout << (ll)n * (n - 1) / 2 % md << endl;
else if(c[1] == c[n]) cout << mul(cut1 + 1, n - cut2 + 2) << endl;
else cout << cut1 + 1 + n - cut2 + 2 - 1 << endl;
return 0;
}

C:

答案本质上是把一个圆切成答案份

那么圆心角确定了,就可以算出一个圆周角的大小,如果切成 360 份可以拼出任意角度,所以枚举这个角度即可

#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie();
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> " << endl;
using namespace std; typedef unsigned long long ull;
typedef long long ll; template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
} template <typename T>
void print(T x) {
if(x < 0) putchar('-'), x = -x;
if(x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
} template <typename T>
void print(T x, char t) {
print(x); putchar(t);
} int T; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() {
read(T); while(T--) {
int d; read(d); int ans = -1;
for(register int i = 3; i <= 23333; i++) {
if(d * i % 180 == 0 && d <= 180 - 360 / (double)i) {
ans = i; break;
}
}
print(ans, '\n');
}
return 0;
}

D:

$ f[i][j] $ 表示到了第 $ i $ 个字母,$ hard $ 已经匹配到了第 $ j $ 个字母的最小代价

直接 $ dp $ 即可

#include <bits/stdc++.h>
#define int long long
#define Fast_cin ios::sync_with_stdio(false), cin.tie();
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> " << endl;
using namespace std; typedef unsigned long long ull;
typedef long long ll; template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
} template <typename T>
void print(T x) {
if(x < 0) putchar('-'), x = -x;
if(x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
} template <typename T>
void print(T x, char t) {
print(x); putchar(t);
} const int N = 1e5 + 5; int f[N][5], w[N];
char c[N];
int n; int calc(char t) {
if(t == 'h') return 1;
if(t == 'a') return 2;
if(t == 'r') return 3;
if(t == 'd') return 4;
return 0;
} #undef int
int main() {
#define int long long
memset(f, -1, sizeof(f));
read(n); scanf("%s", c + 1);
for(register int i = 1; i <= n; i++) read(w[i]);
f[0][0] = 0;
for(register int i = 0; i < n; i++) {
int val = calc(c[i + 1]);
for(register int j = 0; j <= 3; j++) {
if(f[i][j] == -1) continue;
if(val == j + 1) {
if(f[i + 1][j + 1] == -1) f[i + 1][j + 1] = f[i][j];
else f[i + 1][j + 1] = min(f[i + 1][j + 1], f[i][j]);
if(f[i + 1][j] == -1) f[i + 1][j] = f[i][j] + w[i + 1];
else f[i + 1][j] = min(f[i + 1][j], f[i][j] + w[i + 1]);
} else {
if(f[i + 1][j] == -1) f[i + 1][j] = f[i][j];
else f[i + 1][j] = min(f[i + 1][j], f[i][j]);
}
}
}
int ans = f[n][0];
for(register int i = 0; i <= 3; i++) if(f[n][i] != -1) ans = min(ans, f[n][i]);
cout << ans << endl;
return 0;
}

E:

没写出来,先咕了

update:2019.1.2

去年不会这题,今年来补

$ n $ 为人数,总分为 $ s $,自己的下限 $ r $ , $ c $ 为组合数,枚举有多少个人跟自己得分相同,自己的得分 $ j $,对答案的贡献是 $ C[n - 1][i - 1] * \frac{1}{i} * calc(n - i, s - i * j, j) $

$ calc( n, s, big ) $ 表示有 $ n $ 个人,总分为 $ s $,每个人的得分都 $ < big $ 的方案数,这个可以通过容斥求出

总方案数可以用隔板法求出是 $ C[s - r + n - 1][n - 1] $,乘上这个的逆元即可

#include <bits/stdc++.h>
#define CIOS ios::sync_with_stdio(false);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> ";
using namespace std; typedef unsigned long long ull;
typedef long long ll; template <typename T>
inline void read(T &f) {
f = 0; T fu = 1; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); }
while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
} template <typename T>
void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
} template <typename T>
void print(T x, char t) {
print(x); putchar(t);
} const int N = 5005, md = 998244353; inline int mul(int x, int y) { return (ll)x * y % md; } inline int add(int x, int y) {
x += y;
if(x >= md) x -= md;
return x;
} inline int sub(int x, int y) {
x -= y;
if(x < 0) x += md;
return x;
} inline int fpow(int x, int y) {
int ans = 1;
while(y) {
if(y & 1) ans = mul(ans, x);
y >>= 1; x = mul(x, x);
}
return ans;
} int C[N + 105][105], inv[N];
int n, s, r, ans; int calc(int n, int s, int big) {
if(n == 0) return s == 0;
int ans = 0;
for(register int i = 0, opt = 1; i <= n && i * big <= s; i++, opt = md - opt)
ans = add(ans, mul(opt, mul(C[s - i * big + n - 1][n - 1], C[n][i])));
return ans;
} int main() {
read(n); read(s); read(r);
for(register int i = 0; i <= s + n; i++) {
C[i][0] = 1;
for(register int j = 1; j <= i && j <= n; j++)
C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
}
for(register int i = 1; i <= n; i++) inv[i] = fpow(i, md - 2);
for(register int i = 1; i <= n; i++) {
for(register int j = r; j <= s; j++) {
if(s - i * j < 0) break;
ans = add(ans, mul(mul(C[n - 1][i - 1], calc(n - i, s - i * j, j)), inv[i]));
}
}
print(mul(ans, fpow(C[s - r + n - 1][n - 1], md - 2)), '\n');
return 0;
} // Rotate Flower Round.

F:

分别计算 $ -1 $ 和 $ -1 $ 的贡献,$ -1 $ 和数字的贡献,数字和数字的贡献

第一个用 $ dp $ 求出,第二个用前缀和求出,第三个用树状数组求出

$ sb $ 的我能用前缀和的地方写了树状数组

#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie();
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> " << endl;
using namespace std; typedef unsigned long long ull;
typedef long long ll; template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
} template <typename T>
void print(T x) {
if(x < 0) putchar('-'), x = -x;
if(x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
} template <typename T>
void print(T x, char t) {
print(x); putchar(t);
} const int N = 2e5 + 5, md = 998244353; inline int mul(int x, int y) { return (ll)x * y % md; } inline int add(int x, int y) {
x += y;
if(x >= md) x -= md;
return x;
} inline int sqr(int x) { return mul(x, x); } inline int fpow(int x, int y) {
int ans = 1;
while(y) {
if(y & 1) ans = mul(ans, x);
y >>= 1; x = sqr(x);
}
return ans;
} int a[N], s[N], f[N], fac[N];
int n, inv2 = (md + 1) / 2, ans1; inline int lowbit(int x) { return x & -x; } void change(int x, int y) {
for(register int i = x; i <= n; i += lowbit(i))
f[i] += y;
} int query(int x) {
int ans = 0;
for(register int i = x; i; i -= lowbit(i))
ans += f[i];
return ans;
} int main() {
read(n); fac[0] = 1;
for(register int i = 1; i <= n; i++) read(a[i]), fac[i] = mul(fac[i - 1], i), s[i] = 1;
for(register int i = n; i >= 1; i--) {
if(a[i] == -1) continue;
ans1 = add(ans1, query(a[i]));
change(a[i], 1);
}
memset(f, 0, sizeof(f));
for(register int i = 1; i <= n; i++) {
if(a[i] != -1) s[a[i]] = 0;
}
for(register int i = 1; i <= n; i++) s[i] += s[i - 1];
ans1 = mul(ans1, fac[s[n]]);
for(register int i = 1; i <= s[n]; i++) f[i] = add(f[i - 1], mul(mul(fac[s[n]], fpow(i, md - 2)), mul(i - 1, mul(i, inv2))));
ans1 = add(ans1, f[s[n]]); memset(f, 0, sizeof(f));
for(register int i = 1; i <= n; i++) if(a[i] == -1) change(i, 1);
for(register int i = 1; i <= n; i++) {
if(a[i] == -1) continue;
int val = mul(s[a[i]], query(n) - query(i));
val = add(val, mul(s[n] - s[a[i]], query(i)));
val = mul(val, fac[s[n] - 1]);
ans1 = add(ans1, val);
}
print(mul(ans1, fpow(fac[s[n]], md - 2)), '\n');
return 0;
}

G:

看到背包问题就会想到卷积,因为背包的转移和卷积的形式相同

对于最开始的 $ k $ 个数构造生成函数,计算 $ n / 2 $ 次幂,每一位的平方加起来就是答案啦

#pragma GCC target("avx")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie();
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> " << endl;
using namespace std; typedef unsigned long long ull;
typedef long long ll; template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
} template <typename T>
void print(T x) {
if(x < 0) putchar('-'), x = -x;
if(x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
} template <typename T>
void print(T x, char t) {
print(x); putchar(t);
} const int P = 998244353; inline int add(int x, int y) {
x += y;
if(x >= P) x -= P;
return x;
} inline int sub(int x, int y) {
x -= y;
if(x < 0) x += P;
return x;
} inline int mul(int x, int y) {
return (ll)x * y % P;
} inline int fpow(int x, int y) {
int ans = 1;
while(y) {
if(y & 1) ans = mul(ans, x);
y >>= 1; x = mul(x, x);
}
return ans;
} namespace ntt {
int base = 1, root = -1, maxbase = -1;
vector <int> roots = {0, 1}, rev = {0, 1}; void init() {
int tmp = P - 1; maxbase = 0;
while(!(tmp & 1)) {
tmp >>= 1;
maxbase++;
}
root = 2;
while(1) {
if(fpow(root, 1 << maxbase) == 1 && fpow(root, 1 << (maxbase - 1)) != 1) break;
root++;
}
} void ensure_base(int nbase) {
if(maxbase == -1) init();
if(nbase <= base) return;
assert(nbase <= maxbase);
rev.resize(1 << nbase);
for(register int i = 1; i < (1 << nbase); i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (nbase - 1));
roots.resize(1 << nbase);
while(base < nbase) {
int z = fpow(root, 1 << (maxbase - base - 1));
for(register int i = (1 << (base - 1)); i < (1 << base); i++) {
roots[i << 1] = roots[i];
roots[i << 1 | 1] = mul(roots[i], z);
}
base++;
}
} void dft(vector <int> &a) {
int n = a.size(), zeros = __builtin_ctz(n);
ensure_base(zeros);
int shift = base - zeros;
for(register int i = 0; i < n; i++) if(i < (rev[i] >> shift)) swap(a[i], a[rev[i] >> shift]);
for(register int mid = 1; mid < n; mid <<= 1) {
for(register int i = 0; i < n; i += (mid << 1)) {
for(register int j = 0; j < mid; j++) {
int x = a[i + j], y = mul(a[i + j + mid], roots[mid + j]);
a[i + j] = add(x, y); a[i + j + mid] = sub(x, y);
}
}
}
} vector <int> pmul(vector <int> a, vector <int> b, bool is_sqr = false) {
int need = a.size() + b.size() - 1, nbase = 0;
while((1 << nbase) < need) nbase++;
ensure_base(nbase); int size = 1 << nbase;
a.resize(size); dft(a); if(!is_sqr) b.resize(size), dft(b); else b = a;
int inv = fpow(size, P - 2);
for(register int i = 0; i < size; i++) a[i] = mul(a[i], mul(b[i], inv));
reverse(a.begin() + 1, a.end()); dft(a); a.resize(need); return a;
} vector <int> psqr(vector <int> a) { return pmul(a, a, 1); } vector <int> inv(vector <int> a, int size) {
if(size == 1) return vector <int> { fpow(a[0], P - 2) };
vector <int> b = inv(a, size >> 1); a = pmul(a, psqr(b)); b.resize(size);
for(register int i = 0; i < size; i++) b[i] = sub(add(b[i], b[i]), a[i]);
return b;
} vector <int> pinv(vector <int> a) {
int nbase = 0; while((1 << nbase) < a.size()) nbase++;
return inv(a, 1 << nbase);
}
}
using ntt::pmul;
using ntt::psqr; vector <int> wxw, ans;
int n, k, sum; int main() {
read(n); read(k); wxw.resize(10);
for(register int i = 1; i <= k; i++) {
int t; read(t); wxw[t] = 1;
}
n >>= 1; ans = wxw; n--;
while(n) {
if(n & 1) ans = pmul(ans, wxw);
n >>= 1; wxw = psqr(wxw);
}
for(register int i = 0; i < ans.size(); i++) sum = add(sum, mul(ans[i], ans[i]));
cout << sum << endl;
return 0;
}

codeforces 1096 题解的更多相关文章

  1. codeforces#536题解

    CodeForces#536 A. Lunar New Year and Cross Counting Description: Lunar New Year is approaching, and ...

  2. codeforces 1093 题解

    12.18 update:补充了 $ F $ 题的题解 A 题: 题目保证一定有解,就可以考虑用 $ 2 $ 和 $ 3 $ 来凑出这个数 $ n $ 如果 $ n $ 是偶数,我们用 $ n / 2 ...

  3. Codeforces Numbers 题解

    这题只需要会10转P进制就行了. PS:答案需要约分,可以直接用c++自带函数__gcd(x,y). 洛谷网址 Codeforces网址 Code(C++): #include<bits/std ...

  4. Codeforces 691E题解 DP+矩阵快速幂

    题面 传送门:http://codeforces.com/problemset/problem/691/E E. Xor-sequences time limit per test3 seconds ...

  5. Codeforces 833B 题解(DP+线段树)

    题面 传送门:http://codeforces.com/problemset/problem/833/B B. The Bakery time limit per test2.5 seconds m ...

  6. Codeforces 840C 题解(DP+组合数学)

    题面 传送门:http://codeforces.com/problemset/problem/840/C C. On the Bench time limit per test2 seconds m ...

  7. Codeforces 515C 题解(贪心+数论)(思维题)

    题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...

  8. Codeforces 475D 题解(二分查找+ST表)

    题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...

  9. CodeForces CF875C题解

    题解 非常有意思的\(2-SAT\)的题. 听学长讲完之后感觉确实容易想到\(2-SAT\),顺理成章. 显然,对于两个串,对咱们来说有意义的显然是两个串中第一个不同的数字.那么,我们假设两个串分别是 ...

随机推荐

  1. CentOS Linux最常用命令及快捷键整理

    最近一直在对CentOS系统进行各种体验,为方便自己也方便他人,整理了Linux常用命令及快捷键,不过其实大多和DOS是一样的,只是命令的表达上可能有点儿不一样. 常用Linux命令: 文件和目录: ...

  2. cf520B-Two Buttons 【BFS】

    http://codeforces.com/contest/520/problem/B Two Buttons Vasya has found a strange device. On the fro ...

  3. Python3 abs() 函数

    Python3 abs() 函数  Python3 数字 描述 abs() 函数返回数字的绝对值. 语法 以下是 abs() 方法的语法: abs( x ) 参数 x -- 数值表达式,可以是整数,浮 ...

  4. Unity Editor(一)OnInspectorGUI的重写与面板的创建

    http://blog.csdn.net/husheng0/article/details/52568027

  5. OGNL特殊符号的使用

    ---------------------siwuxie095 # 的使用 1.使用 # 获取 context 中的数据 「值栈分为 root 和 context 两部分」 2.如:向 Request ...

  6. __imp___vsnprintf

    unresolved external symbol __imp___vsnprintf 解决方案找到了. 在vs2015工程选项,链接器附加依赖项里面添加legacy_stdio_definitio ...

  7. Brophp Nginx 虚拟主机的配置

    默认情况下,Nginx 不支持 pathinfo 配置,通过查看了 Thinkphp Nginx 的配置情况,对虚拟主机配置修改如下: server {     listen 80;     list ...

  8. [Selenium]Grid模式下运行时打印出当前Case在哪台node机器上运行

    当Case在本地运行成功,在Grid模式下运行失败时,我们需要在Grid模式下进行调试,同时登录远程的node去查看运行的情况. Hub是随机将case分配到某台node上运行的,怎样知道当前的cas ...

  9. [原创]解读2017 OWASP Top10漏洞体系(含接口安全)

    2017年4月初,OWASP发布了关于Top10的征求意见版. 争议最大的是A7攻击检测与防范不足. 但我主要是按照日常的渗透漏洞进行解读分析的. 解读完毕后,首发t00ls原创文章. https:/ ...

  10. 从Objective-C到Swift,你必须会的(四)DLog

    调试的时候打断点太慢,所以输出log就是一个很好的选择了.断点,一行一行的按,太麻烦了.从log里一条一条的看,很快就可以找到到哪个函数的哪个地方这个代码就没执行了.这里不详细讨论调试技巧的事.不过大 ...