【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轮过后的最小 ...
随机推荐
- LOJ 6277-6280 数列分块入门 1-4
数列分块是莫队分块的前置技能,练习一下 1.loj6277 给出一个长为n的数列,以及n个操作,操作涉及区间加法,单点查值. 直接分块+tag即可 #include <bits/stdc++.h ...
- ubuntu安装 opencv-3.4.3
1 .官网(https://opencv.org/releases.html)下载下源码 opencv-3.4.3.zip 2.解压 unzip opencv-3.4.3.zip 3.cmake c ...
- Win7开机卡在Windows Update 35%的解决办法
一台Win7老机器,多年未清理,用DISM++清理后,开机重启一直卡在Windows Update 35%转圈圈数小时,无法进入系统. 强制按关机键,F8进入安全模式依然同样现象. 查阅MSDN后,有 ...
- EF数据迁移
在项目中使用Entity Framework的Code First模式,进行数据迁移时,Migration文件夹中存放的是每一次Entity的修改如何同步到数据的操作方法,每个文件中都只有Up和Dow ...
- python-GIL、死锁递归锁及线程补充
一.GIL介绍 GIL全称 Global Interpreter Lock ,中文解释为全局解释器锁.它并不是Python的特性,而是在实现python的主流Cpython解释器时所引入的一个概念,G ...
- C#的winform中控制TextBox中只能输入数字
C#的winform中控制TextBox中只能输入数字 private void textBox3_KeyPress(object sender, System.Windows.Forms.KeyPr ...
- springboot第一个项目【创建】
1.new project,不勾选create from archetype,直接选择 2.next下一步 在Maven依赖管理中,唯一标识一个依赖项是由该依赖项的三个属性构成的,分别是groupId ...
- 体验go语言的风骚式编程
最近想搞搞后台开发,话说注意力就转移到了公司用的golang.用Go做微服务比较方便,或许是因为golang强悍的语法吧,看到go的语法,自己已被深深的吸引.关于学习后台如何选择可以参考<做后台 ...
- python 排序 sort和sorted
当我们从数据库中获取一写数据后,一般对于列表的排序是经常会遇到的问题,今天总结一下python对于列表list排序的常用方法: 第一种:内建方法sort() 可以直接对列表进行排序 用法: list. ...
- Confluence 6 Windows 中以服务方式自动重启为服务手动安装 Confluence 分发包
在 Windows: 打开一个命令输入框,然后修改目录到 <CONFLUENCE-INSTALL>/bin 目录中.你需要以管理员权限运行这个命令行输入框(Run as administr ...