A Star

#include <cstdio>
using namespace std; int n; int main()
{
scanf("%d", &n);
printf("%d\n", 100 - n % 100);
return 0;
}

B uNrEaDaBlE sTrInG

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cctype>
using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) string str; bool check()
{
for(int i = 0; i < (int)str.size(); ++ i)
if(i % 2 && islower(str[i])) return 0;
else if(i % 2 == 0 && isupper(str[i])) return 0;
return 1;
} int main()
{
IOS;
cin >> str;
if(check()) puts("Yes");
else puts("No");
return 0;
}

C Kaprekar Number

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std; typedef long long LL;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) LL n, k; LL f(LL x)
{
vector<int> g1, g2;
while(x) g1.push_back(x % 10), g2.push_back(x % 10), x /= 10;
sort(g1.begin(), g1.end(), greater<int>());
sort(g2.begin(), g2.end());
LL res = 0;
for(int i = 0; i < (int)g1.size(); ++ i)
res = res * 10 + g1[i] - g2[i];
return res;
} int main()
{
IOS;
cin >> n >> k;
LL a0 = n;
for(int i = 1; i <= k; ++ i) a0 = f(a0);
cout << a0 << endl;
return 0;
}

D Base n

特判 \(X\) 只有一位的情况,无论基底是几,得到的数都是原数,判断原数和 \(M\) 的大小关系即可

对于其他情况,当基底越大,得到的值也就越大,具有单调性,可以二分基底

计算以 \(mid\) 为基底的数与 \(M\) 的大小关系时,直接计算答案会爆 \(long \; long\), 注意在过程中判断

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; typedef unsigned long long LL;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) LL m;
string s; int find()
{
int res = 0;
for(auto x : s) res = max(res, x - '0');
return res;
} bool check(LL mid)
{
LL res = 0;
for(auto x : s)
{
if(res > m / mid) return 0;
res = res * mid + x - '0';
if(res > m) return 0;
}
return 1;
} int main()
{
IOS;
cin >> s >> m;
int d = find();
if(s.size() == 1)
{
if((LL)d <= m) cout << "1" << endl;
else cout << "0" << endl;
return 0;
}
LL l = d + 1, res = 0, r = m;
while(l <= r)
{
LL mid = (l + r) >> 1;
if(check(mid))
{
res = mid;
l = mid + 1;
}
else r = mid - 1;
}
if(res) cout << res - d << endl;
else cout << "0" << endl;
return 0;
}

E Train

从 \(u\) 到达 \(v\) 的时间为 \(\left\lceil\ \dfrac{d[u]}{K_i}\right\rceil * K_i + T_i\), 建双向边跑 \(dijkstra\) 即可

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std; typedef long long LL;
const int M = 2e5 + 10;
const int N = 1e5 + 10;
const LL INF = 1e18; int n, m, S, T;
LL d[N];
struct Edge
{
int to, nxt, T, K;
}line[M];
int fist[N], idx;
bool st[N];
struct zt
{
int from;
LL d;
}; bool operator < (zt a, zt b)
{
return a.d > b.d;
} void add(int x, int y, int z, int w)
{
line[idx] = {y, fist[x], z, w};
fist[x] = idx ++;
} void heap_dijkstra()
{
for(int i = 1; i <= n; ++ i) d[i] = INF;
priority_queue<zt> q;
q.push({S, 0}), d[S] = 0;
while(!q.empty())
{
zt u = q.top(); q.pop();
if(st[u.from]) continue;
st[u.from] = 1;
for(int i = fist[u.from]; ~i; i = line[i].nxt)
{
int v = line[i].to;
LL tim = (d[u.from] + line[i].K - 1) / line[i].K * line[i].K + line[i].T;
if(d[v] > tim)
{
d[v] = tim;
q.push({v, d[v]});
}
}
}
} int main()
{
scanf("%d%d%d%d", &n, &m, &S, &T);
memset(fist, -1, sizeof fist);
for(int i = 1; i <= m; ++ i)
{
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
add(a, b, c, d);
add(b, a, c, d);
}
heap_dijkstra();
if(d[T] < INF) printf("%lld\n", d[T]);
else puts("-1");
return 0;
}

F Potion

令 \(\sum A_i\) 为从 \(n\) 个元素中选出 \(p\) 个元素的权值和

目标是使在满足\(p | (X - \sum A_i)\) 条件下最小化 \(\dfrac{X - \sum A_i}{p}\)

故对于每个 \(p\) ,求出在 \(\sum A_i\) mod \(p\) == \(X\) mod \(p\) 的条件下 \(\sum A_i\) 的最大值即可

问题转化为求 \(i\) 个数中取出 \(j\) 个且和的余数为 \(k\) 的最大和

令\(f[i][j][k]\) 为前 \(i\) 个数中选择 \(j\) 个且和的余数为 \(k\) 的最大和

\(f[i][j][k] = max(f[i - 1][j][k], f[i - 1][j - 1][(k - a_i) \% p] + a_i)\)

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long LL;
const int N = 100 + 20;
const LL INF = 1e18; LL f[N][N][N], m;
int n, a[N]; int main()
{
IOS;
cin >> n >> m;
for(int i = 1; i <= n; ++ i) cin >> a[i];
LL ans = INF;
for(int p = 1; p <= n; ++ p)
{
memset(f, -0x3f, sizeof f);
f[0][0][0] = 0;
for(int i = 1; i <= n; ++ i)
{
f[i][0][0] = 0;
for(int j = 1; j <= p; ++ j)
for(int k = 0; k < p; ++ k)
f[i][j][k] = max(f[i - 1][j][k], f[i - 1][j - 1][((k - a[i]) % p + p) % p] + a[i]);
}
if(f[n][p][m % p] >= 0) ans = min(ans, (m - f[n][p][m % p]) / p);
}
cout << ans << endl;
return 0;
}

AtCoder Beginner Contest 192的更多相关文章

  1. AtCoder Beginner Contest 192 F - Potion

    题目链接 点我跳转 题目大意 给定 \(N\) 个物品和一个 \(X\) ,第 \(i\) 个物品的重量为 \(ai\),你可以从中选择任意个物品(不能不选) 假定选择了 \(S\) 个物品,物品的总 ...

  2. AtCoder Beginner Contest 100 2018/06/16

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

  3. AtCoder Beginner Contest 052

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

  4. AtCoder Beginner Contest 053 ABCD题

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

  5. AtCoder Beginner Contest 136

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

  6. AtCoder Beginner Contest 137 F

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

  7. AtCoder Beginner Contest 076

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

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

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

  9. AtCoder Beginner Contest 064 D - Insertion

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

随机推荐

  1. [Python] Uvicorn+FastAPI快速搞定Restful API开发

    目录 安装模块 运行代码 运行命令 快速文档 安装模块 # 一个现代的,快速(高性能)python web框架 pip install fastapi # 主要用于加载和提供应用程序的服务器. pip ...

  2. Chapter Zero 0.2.1 执行运算与判断的CPU

    目录 执行运算与判断的CPU CPU效能比较的指标 CPU的工作频率:外频与倍频 32位与64位的CPU与总线[宽度] CPU的等级 超线程(Hyper-Threading,HT) 网上摘下几张主板图 ...

  3. C++ new delete malloc free

    title: C++ new delete malloc free date: 2020-03-10 categories: c++ tags: 语法 C++的new delete malloc fr ...

  4. linux多线程模拟银行家算法

    题外话: 这应该是最近有点难度的作业了,起码比之前的理发师,读写,哲学家问题要难. 但是做好程序的结构,自顶向下,就还是不难的. 银行家算法简介:                 代码: init() ...

  5. JavaScript调试技巧之console.log()

    与alert()函数类似,console.log()也可以接受变量并将其与别的字符串进行拼接: 代码如下: //Use variable var name = "Bob"; con ...

  6. 计蒜客 第四场 C 商汤科技的行人检测(中等)平面几何好题

    商汤科技近日推出的 SenseVideo 能够对视频监控中的对象进行识别与分析,包括行人检测等.在行人检测问题中,最重要的就是对行人移动的检测.由于往往是在视频监控数据中检测行人,我们将图像上的行人抽 ...

  7. Spring(二) Mini版Spring的实现

    实现思路 先来介绍一下 Mini 版本的 Spring 基本实现思路,如下图所示: 自定义配置 配置 application.properties 文件 为了解析方便,我们用 application. ...

  8. CVE-2019-13272:Linux本地内核提权漏洞复现

    0x00 简介 2019年07月20日,Linux正式修复了一个本地内核提权漏洞.通过此漏洞,攻击者可将普通权限用户提升为Root权限. 0x01 漏洞概述 当调用PTRACE_TRACEME时,pt ...

  9. Linux内核实现透视---软中断&Tasklet

    软中断 首先明确一个概念软中断(不是软件中断int n).总来来说软中断就是内核在启动时为每一个内核创建了一个特殊的进程,这个进程会不停的poll检查是否有软中断需要执行,如果需要执行则调用注册的接口 ...

  10. Gif2mp4 by Python

    参考链接 目的: $ .gif \rightarrow .mp4 $ 解决: pip install MoviePy import moviepy.editor as mp clip = mp.Vid ...