ARC075

在省选前一天听说正式选手线画到省二,有了别的女选手,慌的一批,然后刷了一个ARC来稍微找回一点代码感觉

最后还是挂分了,不开心

果然水平退化老年加重啊

原题链接

C - Bugged

直接做一个dp,找最大值时不找整十的位置即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int s[105];
int dp[100005];
void Solve() {
read(N);
dp[0] = 1;
for(int i = 1 ; i <= N ; ++i) {
read(s[i]);
for(int j = 100000 ; j >= 1 ; --j) {
if(j >= s[i]) dp[j] = dp[j] | dp[j - s[i]];
}
}
for(int j = 100000 ; j >= 0 ; --j) {
if(j && j % 10 == 0) continue;
if(dp[j]) {out(j);enter;return;}
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

D - Widespread

二分操作次数,相当于每个数集体减去\(mid * B\),然后分配\(mid\)个\(A - B\)给还未减到0的数

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int64 B,A;
int64 h[MAXN];
void Solve() {
read(N);read(A);read(B);
for(int i = 1 ; i <= N ; ++i) {
read(h[i]);
}
sort(h + 1,h + N + 1);
int64 L = 0,R = 1000000000;
while(L < R) {
int64 mid = (L + R) >> 1;
int64 rem = 0;
for(int i = 1 ; i <= N ; ++i) {
if(h[i] - mid * B > 0) rem += (h[i] - mid * B - 1) / (A - B) + 1;
}
if(rem <= mid) R = mid;
else L = mid + 1;
}
out(L);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

E - Meaningful Mean

每个数都减去K,合法区间即为和大于0的区间

记成前缀和转化成二维偏序的问题

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,K,tr[MAXN];
int64 a[MAXN],sum[MAXN],val[MAXN];
int lowbit(int x) {return x & (-x);}
void Insert(int x,int v) {
while(x <= N + 1) {
tr[x] += v;
x += lowbit(x);
}
}
int Query(int x) {
int res = 0;
while(x > 0) {
res += tr[x];
x -= lowbit(x);
}
return res;
}
void Solve() {
read(N);read(K);
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
sum[i] = sum[i - 1] + a[i] - K;
val[i] = sum[i];
}
val[N + 1] = 0;
sort(val + 1,val + N + 2);
int t = lower_bound(val + 1,val + N + 2,sum[0]) - val;
Insert(t,1);
int64 res = 0;
for(int i = 1 ; i <= N ; ++i) {
t = lower_bound(val + 1,val + N + 2,sum[i]) - val;
res += Query(t);
Insert(t,1);
}
out(res);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

F - Mirrored

如果长度固定为L,每个数位上的数是\(b_{i}\)那么相当于

\(rev(N) - N = \sum_{i = 0}^{L - 1} (10^{L - i - 1} - 10^{i})b_{i}\)

然后对称的位置可以合并一下

\(rev(N) - N = \sum_{i = 0}^{L / 2}(10^{L - i - 1} - 10^{i})(b_{i} - b_{L - i - 1})\)

然后我们就相当于对于\(0-\lfloor \frac{L}{2}\rfloor\)中的每一个\(10^{L - i - 1} - 10^{i}\)乘上一个\(-9\)到\(9\),组合出来的值是D,然后乘上这种方案的搭配数

然后发现对于一个

\(10^{L - i - 1} - 10^{i} > \sum_{j = i + 1}^{L / 2} (10^{L - j - 1} - 10^{j}) * 9\)

就是当前第i位决定完了,但和D差了大于\(10^{L - i - 1} - 10^{i}\)的时候,我们是无论如何也恢复不了的

所以当D确定时,合法的填法最多只有两个

对于固定的长度\(L\),最大是\(2L_{D}\)也就是D的十进制长度的二倍,最小是\(L_{D}\)

是二倍的原因是D是正数,我们如果要操作D必然要有在D大小以内的数加减,然后超过\(2L_{D}\)能加减的最小的数也超过了D,我们无法得到一个D

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int64 D; int Len(int64 D) {
int res = 0;
while(D) {
res++;
D /= 10;
}
return res;
}
int64 pw[20];
int64 v[20],d[20];
int up;
int64 dfs(int64 rem,int dep) {
if(dep == up) return !rem;
int64 t = rem / v[dep];
int64 res = 0;
if(abs(t - 1) <= 9 && abs(rem - (t - 1) * v[dep]) < v[dep]) {
int c = 0;
if(t - 1 >= 0 && !dep) c = 1;
res += (d[t - 1 + 9] - c) * dfs(rem - (t - 1) * v[dep],dep + 1);
}
if(abs(t) <= 9 && abs(rem - t * v[dep]) < v[dep]) {
int c = 0;
if(t >= 0 && !dep) c = 1;
res += (d[t + 9] - c) * dfs(rem - t * v[dep],dep + 1);
}
if(abs(t + 1) <= 9 && abs(rem - (t + 1) * v[dep]) < v[dep]) {
int c = 0;
if(t + 1 >= 0 && !dep) c = 1;
res += (d[t + 1 + 9] - c) * dfs(rem - (t + 1) * v[dep],dep + 1);
}
return res;
}
void Solve() {
read(D);
int Ld = Len(D);
int64 ans = 0;
pw[0] = 1;
for(int i = 1 ; i <= 18 ; ++i) pw[i] = pw[i - 1] * 10;
for(int i = 0 ; i <= 9 ; ++i) {
for(int j = 0 ; j <= 9 ; ++j) {
d[i - j + 9]++;
}
}
for(int i = Ld ; i <= 2 * Ld ; ++i) {
for(int j = 0 ; j <= i / 2 ; ++j) v[j] = pw[i - j - 1] - pw[j];
up = i / 2;
int64 tmp = dfs(D,0);
if(i & 1) tmp *= d[0 + 9];
ans += tmp;
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

【AtCoder】ARC075的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. Apollo-3.0本地编译

    Apollo-3.0本地编译 用docker编译所用的dev.x86_64.dockerfile文件(具体位置在apollo/docker/build)中有所有的依赖库或包, 还会执行一些shell脚 ...

  2. Alpha 冲刺 (2/10)

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:拿快递也不能耽搁了软工 团队部分 后敬甲(组长) 过去两天完成了哪些任务 文字描述 github代码管理规范 商家端订单 ...

  3. Redis高级特性介绍及实例分析

    转自:http://www.jianshu.com/p/af7043e6c8f9   Redis基础类型回顾 String Redis中最基本,也是最简单的数据类型.注意,VALUE既可以是简单的St ...

  4. linux服务器上配置多个svn仓库

    linux服务器上配置多个svn仓库 1.在指定目录建立仓库保存总目录,本文示例目录设定为:/usr/local/svn/svnrepos # mkdir -p /usr/local/svn/svnr ...

  5. use Swig to create C/C++ extension for Python

    SWIG is a software development tool that simplifies the task of interfacing different languages to C ...

  6. 【Shared Server Mode】测试调整shared_servers参数对数据库的影响

    本文来源于:secooler  的 <[Shared Server Mode]测试调整shared_servers参数对数据库的影响> 关于Shared Server模式的配置方法请参见文 ...

  7. Confluence 6 数据库支持的驱动

    数据库 驱动已捆绑? JDBC 驱动 备注 更多信息 PostgreSQL 9.4-1202 JDBC 41 driver download 我们推荐你使用 JDBC 4 的驱动. 如果你希望使用更新 ...

  8. phpstudy添加redis扩展

    操作系统   windows: 直接贴步骤记录下 一.      划重点,运行phpinfo(), 观察第四行 x86  好了记住这个 x86 三.    http://pecl.php.net/pa ...

  9. Django框架第一篇基础

    一个小问题: 什么是根目录:就是没有路径,只有域名..url(r'^$') 补充一张关于wsgiref模块的图片 一.MTV模型 Django的MTV分别代表: Model(模型):和数据库相关的,负 ...

  10. LeetCode(94):二叉树的中序遍历

    Medium! 题目描述: 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗 ...