2024.10.14校测
T1
题目描述
为了庆祝大佬
输入格式
第一行两个整数
输出格式
一行一个整数代表答案。
输入样例
15 5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1
输出样例
6
数据规模
对于
对于
完整代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9, M = 1e6 + 9;
struct Edge{
int v, w, nex;
} e[M << 2];
int head[N], ecnt;
void addEdge(int u, int v, int w){
e[++ecnt] = Edge{v, w, head[u]};
head[u] = ecnt;
}
int dis[N], tot[N], n, m;
queue <int> q;
bool inq[N];
bool spfa(int s){
dis[s] = 0;
q.push(s);
inq[s] = true;
while(!q.empty()){
int u = q.front();
q.pop();
inq[u] = false;
for(int i = head[u]; i; i = e[i].nex){
int v = e[i].v;
if(dis[u] + e[i].w > dis[v]){
dis[v] = dis[u] + e[i].w;
if(!inq[v]){
tot[v]++;
if(tot[v] == n + 1)
return false;
q.push(v);
inq[v] = true;
}
}
}
}
return true;
}
int l[M], r[M], c[M], tmp[N];
int main(){
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
scanf("%lld%lld", &n, &m);
memset(dis, -0x3f, sizeof(dis));
for(int i = 1; i <= m; i++){
scanf("%lld%lld%lld", &l[i], &r[i], &c[i]);
addEdge(l[i] - 1, r[i], c[i]);
}
for(int i = 0; i < n; i++){
addEdge(i, i + 1, 0);
addEdge(i + 1, i, -1);
}
bool flag = spfa(0);
printf("%lld", dis[n]);
return 0;
}
T2
题目描述
在实验室中,
输入格式
第一行包含两个整数
接下来
一个测量结果被格式化为 ! a b w
,表示第
一个询问被格式化为 ? a b
,表示询问第
输出格式
对于每个询问输出一行,如果能回答问题,则输出问题的答案,你可以认为答案的绝对值不超过 UNKNOWN
,表示不能回答问题。
输入样例
4 7
! 1 2 100
? 2 3
! 2 3 100
? 2 3
? 1 3
! 4 3 150
? 4 1
输出样例
UNKNOWN
100
200
-50
数据规模
对于
对于
完整代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 9;
int fa[N], dis[N];
int find(int x){
if(fa[x] == x)
return x;
int rt = find(fa[x]);
dis[x] += dis[fa[x]];
fa[x] = rt;
return rt;
}
int n, m;
signed main(){
freopen("b.in", "r", stdin);
freopen("b.out", "w", stdout);
for(int i = 0; i < N; i++)
fa[i] = i;
scanf("%lld%lld", &n, &m);
for(int i = 1; i <= m; i++){
char opt[2];
int x, y, w;
scanf("%s", opt);
if(opt[0] == '!'){
scanf("%lld%lld%lld", &x, &y, &w);
int fx = find(x);
int fy = find(y);
if(fx != fy){
fa[fx] = fy;
dis[fx] = dis[y] - dis[x] + w;
}
} else {
scanf("%lld%lld", &x, &y);
if(find(x) != find(y))
printf("UNKNOWN\n");
else
printf("%lld\n", dis[x] - dis[y]);
}
}
return 0;
}
T3
题目描述
一条单向的铁路线上,依次有编号为
输入格式
第一行包含
接下来
输出格式
一行一个整数,表示车站最少划分的级别数。
输入样例
9 3
4 1 3 5 6
3 3 5 6
3 1 5 9
输出样例
3
数据规模
对于
对于
对于
T4
题目描述
酒吧里有
输入格式
第一行两个整数
第二行
输出格式
一行一个整数,表示至少需要购买的鸡尾酒杯数。如果无法满足条件,输出 -1
。
输入样例
50 2
100 25
输出样例
3
样例解释
购买
数据规模
对于
对于
本文来自博客园,作者:JPGOJCZX,转载请注明原文链接:https://www.cnblogs.com/JPGOJCZX/p/18467927
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】