A I Scream

int main()
{
IOS;
int a, b;
cin >> a >> b;
if(a + b >= 15 && b >= 8) puts("1");
else if(a + b >= 10 && b >= 3) puts("2");
else if(a + b >= 3) puts("3");
else puts("4");
return 0;
}

B

int n;
int a[N], b[N]; int main()
{
scanf("%d", &n);
int res = INF;
for(int i = 1; i <= n; ++ i)
{
scanf("%d%d", &a[i], &b[i]);
res = min(res, a[i] + b[i]);
}
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= n; ++ j)
if(i != j) res = min(max(a[i], b[j]), res);
printf("%d\n", res);
return 0;
}

C Squared Error

\(\sum\limits_{i=2}^N\sum\limits_{j=1}^{i-1}(A_i-A_j)^2\) = \(\sum\limits_{i=1}^NA_i^2 * (N - 1) - \sum\limits_{i=2}^NA_i\sum\limits_{j=1}^{i - 1}2 * A_j\)

用前缀和优化后复杂度 \(O(n)\)

int n;
int a[N], sum[N]; int main()
{
scanf("%d", &n);
LL res = 0;
for(int i = 1; i <= n; ++ i)
{
scanf("%d", &a[i]);
res += (LL)a[i] * a[i] * (n - 1);
res -= (LL)sum[i - 1] * a[i] * 2;
sum[i] = sum[i - 1] + a[i];
}
printf("%lld\n", res);
return 0;
}

D Journey

令当前已经访问过的顶点集合为 \(S\), 下一次能使得 \(|S|\) 增加 \(1\) 的概率为 \(\dfrac{N - |S|}{N}\), 首中即停止,符合几何分布,已知几何分布的期望是 \(\dfrac{1}{p}\), 故期望是 \(\sum\limits_{i = 1}^{n - 1}\dfrac{N}{N - i}\)

int n;

int main()
{
cin >> n;
double res = 0;
for(int i = 1; i < n; ++ i) res += (double)n / i; printf("%.10lf\n", res);
return 0;
}

E Mex Min Editorial

对于相同的两个数 \(x\),如果它们之间的距离大于 \(M\),则代表有一段长度为 \(M\) 的区间中没有 \(x\), \(x\)则可以作为答案

为了处理边界情况,在 \(0\) 和 \(n + 1\) 的位置上放置每一个数

int n, m;
int last[N]; int main()
{
scanf("%d%d", &n, &m);
int res = INF; for(int i = 1; i <= n; ++ i)
{
int x;
scanf("%d", &x);
if(i - last[x] > m) res = min(x, res);
last[x] = i;
}
for(int i = 0; i <= n; ++ i)
if(n + 1 - last[i] > m)
res = min(i, res);
printf("%d\n", res);
return 0;
}

F Digits Paradise in Hexadecimal

令 \(f[i][j]\) 为前 \(i\) 位选了 \(j\) 种的方案数,且选出的方案都严格小于上界

当上一位未达到上界时:

\(f[i + 1][j] += f[i][j] * j\)

\(f[i + 1][j + 1] += f[i][j] * (16 - j)\)

因为要处理前导零,所以从 \(0\) 转移要特殊处理:

\(f[i + 1][1] += f[i][0] * 15\)

\(f[i + 1][0] += f[i][0]\)

再统计上一位达到上界时,当前位取 \(0\) ~ \(v[i] - 1\) 的贡献

最后特判掉所有位都取到上界是否符合题意

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; #define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0) const int P = 1e9 + 7;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int N = 3e6 + 10; int main()
{
IOS;
int n;
string str;
vector<int> v;
cin >> str >> n; for(auto x : str)
if(x >= '0' && x <= '9') v.push_back((int)(x - '0'));
else v.push_back((int)(10 + x - 'A')); vector<vector<int> > f(str.size() + 1, vector<int>(18, 0)); int state = 0;
for(int i = 0; i < (int)str.size(); ++ i)
{
for(int j = 1; j <= 16; ++ j)
{
f[i + 1][j] = (f[i + 1][j] + (LL)f[i][j] * j % P) % P;
f[i + 1][j + 1] = (f[i + 1][j + 1] + (LL)f[i][j] * (16 - j) % P) % P;
}
f[i + 1][1] = (f[i + 1][1] + (LL)f[i][0] * 15 % P) % P;
f[i + 1][0] = (f[i + 1][0] + f[i][0]) % P;
for(int j = 0; j < v[i]; ++ j)
{
int nstate = state;
if(i || j) nstate |= (1 << j);
f[i + 1][__builtin_popcount(nstate)] += 1;
}
state |= (1 << v[i]);
} int res = f[str.size()][n] + (__builtin_popcount(state) == n);
cout << res << endl; return 0;
}

AtCoder Beginner Contest 194的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  2. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

随机推荐

  1. 自己动手实现springboot运行时执行java源码(运行时编译、加载、注册bean、调用)

    看来断点.单步调试还不够硬核,根本没多少人看,这次再来个硬核的.依然是由于apaas平台越来越流行了,如果apaas平台选择了java语言作为平台内的业务代码,那么不仅仅面临着IDE外的断点.单步调试 ...

  2. 浅谈Webpack模块打包工具三

    Source Map 生产代码与开发代码完全不同,如果需要调试应用的话会非常的麻烦,错误信息无法定位,Soutce Map就会逆向得到源代码, 须在打包之后的代码文件的末尾位置例如添加//# sour ...

  3. SSM框架整合(Spring + SpringMVC + MyBatis)

    搭建环境 使用Spring(业务层)整合其他的框架SpringMVC(表现层)和MyBatis(持久层) Spring框架 创建数据库表 CREATE DATABASE ssm; USE ssm; C ...

  4. codeforces 858A

    A. k-rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. 内存耗尽后Redis会发生什么

    前言 作为一台服务器来说,内存并不是无限的,所以总会存在内存耗尽的情况,那么当 Redis 服务器的内存耗尽后,如果继续执行请求命令,Redis 会如何处理呢? 内存回收 使用Redis 服务时,很多 ...

  6. Right in the Center (js string algorithm)

    Right in the Center (js string algorithm) codewars https://www.codewars.com/kata/5f5da7a415fbdc0001a ...

  7. 从长度为 M 的无序数组中,找出N个最小的数

    从长度为 M 的无序数组中,找出 N个最小的数 在一组长度为 n 的无序的数组中,取最小的 m个数(m < n), 要求时间复杂度 O(m * n) 网易有道面试题 const minTopK ...

  8. javascript nested object merge

    javascript nested object merge deep copy Object reference type function namespace(oNamespace, sPacka ...

  9. how to overwrite css !important style

    how to overwrite css !important style css !important bug how to override css !important style https: ...

  10. 1月加密货币交易所访问量破3亿!NGK生态星空计划、NGK生态所带来双重利好!

    据最新数据显示,2021年一月份,加密货币交易所网站的访问量急剧上升.约有3.44亿访问者涌入了加密货币交易所,超过2020年12月的1.96亿访问者总数,创2018年1月以来新高. 加密货币交易所网 ...