20241010总结
number
从考虑使用多少个加和减入手,简单计算。
#include<iostream>
#define int long long
using namespace std;
inline int read(){register int x = 0, f = 1;register char c = getchar();while (c < '0' || c > '9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return x * f;}
inline void write(int x){if (x < 0) putchar('-'), x = -x;if (x > 9) write(x / 10);putchar(x % 10 + '0');}
int T, n, a, b, s;
int get(int x, int y){
if (x % y == 0) return x / y;
return x / y + 1;
}
signed main(){
freopen("number.in", "r", stdin);
freopen("number.out", "w", stdout);
T = read();
while (T--){
n = read(), a = read(), b = read(), s = read();
int x = s - n * b;
if (x >= 0){
cout << x << '\n';
continue;
}
cout << x + get(-x, a + b) * (a + b) << '\n';
}
return 0;
}
path
首先可以想到一个
#include<iostream>
#include<queue>
#include<vector>
#define int long long
using namespace std;
inline int read(){register int x = 0, f = 1;register char c = getchar();while (c < '0' || c > '9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return x * f;}
inline void write(int x){if (x < 0) putchar('-'), x = -x;if (x > 9) write(x / 10);putchar(x % 10 + '0');}
const int N = 5e5 + 10, M = 1e6 + 10;
int n, m, k;
int val[N], b[N];
struct edge{
int v, nxt;
}e[M << 1];
int head[N], cnt;
void add(int u, int v){
e[++cnt] = (edge){v, head[u]};
head[u] = cnt;
}
int dp[N];
struct node{
int d, u;
bool operator < (const node &b) const{
return d > b.d;
}
};
priority_queue<node> q;
void bfs(int s){
q.push((node){dp[s], s});
while (!q.empty()){
node t = q.top();q.pop();
int u = t.u;
if (t.d != dp[u]) continue;
for (int i = head[u]; i; i = e[i].nxt){
int v = e[i].v;
if (dp[v] > dp[u] + (b[dp[u] + 1] == val[v])){
dp[v] = dp[u] + (b[dp[u] + 1] == val[v]);
q.push((node){dp[v], v});
}
}
}
}
signed main(){
freopen("path.in", "r", stdin);
freopen("path.out", "w", stdout);
n = read(), m = read(), k = read();
for (int i = 1; i <= n; i++) val[i] = read();
for (int i = 1; i <= k; i++) b[i] = read();
for (int i = 1; i <= m; i++){
int u = read(), v = read();
add(u, v), add(v, u);
}
for (int i = 1; i <= n; i++) dp[i] = 0x7fffffff;
dp[1] = (val[1] == b[1] ? 1 : 0);
bfs(1);
for (int i = 1; i <= n; i++) cout << dp[i] << ' ';
return 0;
}
tree
考场时胡出来一个好像正确的做法,预处理所有距离,更改第一个上课地点,用树链剖分维护。
rope
神奇概率题,好像要用下降幂去做,先咕着,去学学。
本文作者:bryce_yyds
本文链接:https://www.cnblogs.com/bryceyyds/p/18468217
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话