【AtCoder】ARC075
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的更多相关文章
- 【AtCoder】ARC092 D - Two Sequences
[题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
- 【AtCoder】ARC 081 E - Don't Be a Subsequence
[题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...
- 【AtCoder】AGC022 F - Leftmost Ball 计数DP
[题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...
- 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT
[题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...
- 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分
[题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...
- 【AtCoder】ARC095 E - Symmetric Grid 模拟
[题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...
- 【Atcoder】AGC022 C - Remainder Game 搜索
[题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...
- 【Atcoder】AGC 020 B - Ice Rink Game 递推
[题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...
随机推荐
- ansible笔记(3):ansible模块的基本使用
ansible笔记():ansible模块的基本使用 在前文的基础上,我们已经知道,当我们使用ansible完成实际任务时,需要依靠ansible的各个模块,比如,我们想要去ping某主机,则需要使用 ...
- 持续集成之④:GitLab触发jenkins构建项目
持续集成之④:GitLab触发jenkins构建项目 一:目的为在公司的测试环境当中一旦开发向gitlab仓库提交成功代码,gitlab通知jenkins进行构建项目.代码质量测试然后部署至测试环境, ...
- 在Centos7 上安装SVN
https://blog.csdn.net/crossangles_2017/article/details/78553266 1.安装 使用yum安装非常简单: yum install subver ...
- SQL Server 之 子查询与嵌套查询
当由where子句指定的搜索条件指向另一张表时,就需要使用子查询或嵌套查询. 1 子查询 子查询是一个嵌套在select.insert.update或delete语句或其他子查询中的查询.任何允许使用 ...
- [转] 为什么说 Java 程序员必须掌握 Spring Boot ?
Spring Boot 2.0 的推出又激起了一阵学习 Spring Boot 热,那么, Spring Boot 诞生的背景是什么?Spring 企业又是基于什么样的考虑创建 Spring Boot ...
- swift 实践- 02 -- 自定义cell 的简单使用
import UIKit class MyTableViewCell: UITableViewCell { var imageV: UIImageView? var titleLabel: UILab ...
- web的分页方法
web分页的三种方式,闲来无事总结一下. 1.使用前端表格插件进行分页 例如用bootstrap的拓展table组件,注意设置其分页属性时设置为"client", 即是 sideP ...
- jquery 获取和设置 select下拉框的值
获取Select : 获取select 选中的 text : $("#ddlRegType").find("option:selected").text(); ...
- MySQL之IDE工具介绍及数据备份
一.IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https://pan.baidu.com/s/1bpo5mqj 二.MySQL数据备份 # ...
- 《剑指offer》 调整数组顺序使得奇数在偶数前面
本题来自<剑指offer> 调整数组顺序使得奇数在偶数前面 题目: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分, ...