测试情况
| 题目 | 估分 | 实际 |
|---|---|---|
| 总分 |
今天没挂分!!!
A
题意
给定 NSC 商店和其他 家商店,每家商店的肉肠的价格为 元 克。
求这 家商店买 克香肠最少要花多少钱。
思路
模拟。每次更新最小值,最后通过 ,求出每一克肉肠的价格,最后乘上 即可。
时间复杂度为 。
AC code
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (1LL << 60LL)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = 2e5 + 10 , M = 2e5 + 10;
const int mod = 998244353;
int n , x , y , a , b , now , now2;
inline void solve(){
cin >> x >> y >> n;
while(n --) cin >> a >> b , now = a * y , now2 = b * x , x = ((now < now2) ? a : x) , y = ((now < now2) ? b : y);//更新最小值
cout << fixed << setprecision(2) << (db)(1.0 * x / y * 1000) << '\n';//求1000克肉肠的价格
}
int main(){
ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
solve();
return 0;
}B
题意
给定一个长度为 的字符串,其中 + 表示第 天的资产增加,- 表示第 天的资产减少,= 表示第 天资产不变。
- 如果第 天的净资产上涨,他会在当天开始时的净资产对应的行画
/。 - 如果第 天的净资产下跌,他会在当天开始时的净资产对应的行画
\。 - 如果第 天的净资产不变,他会在当天开始时的净资产对应的行画
-。
求矩阵大小最小的公司资产的变化示意图。
思路
用 记录当前所在行的资产值。
因为资产值可能有变化,所以我们需要知道最高行和最低行,才能确定矩阵范围。
每天根据符号,在数组的第 行第 列放字符,然后更新最高行和最低行。
最后从最高行到最低行输出矩阵即可。
Trick
由于 可能会变成负数,所以要将 初始为较大的数。
时间复杂度约为 。
AC code
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (1LL << 60LL)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = 2e5 + 10 , M = 2e5 + 10;
const int mod = 998244353;
ll n , x , y = 1145141919 , pos = 110;
string s;
char ch[N][N];
inline void solve(){
cin >> n >> s , s = ' ' + s , memset(ch , '.' , sizeof(ch));
for (int i = 1 ; i <= n ; i ++){
if (s[i] == '+') x = max(x , pos) , y = min(y , pos) , ch[pos ++][i] = '/';//资产上涨
else if (s[i] == '-') ch[-- pos][i] = '\\' , x = max(x , pos) , y = min(y , pos);//资产下跌
else if (s[i] == '=') x = max(x , pos) , y = min(y , pos) , ch[pos][i] = '_';//资产不变
}
for (int i = x ; i >= y ; i --){
for (int j = 1 ; j <= n ; j ++) cout << ch[i][j];
cout << '\n';
}
}
int main(){
ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
solve();
return 0;
}C
题意
给定一个 的立方体,给定起点坐标和终点坐标,求从起点到终点最少走多少步。
思路
BFS 板板题。
和二维的 BFS 差不多,区别就在于多了一维和不能斜着走。
时间复杂度为 。
AC code
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (1LL << 60LL)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = 2e5 + 10 , M = 2e5 + 10;
const int mod = 998244353;
const int dx[] = {1 , -1 , 0 , 0 , 0 , 0} , dy[] = {0 , 0 , 1 , -1 , 0 , 0} , dz[] = {0 , 0 , 0 , 0 , 1 , -1};
ll n , sx , sy , sz , ex , ey , ez , dis[N][N][N];
char a[N][N][N];
bool vis[N][N][N];
struct Node{
ll x , y , z;
};
queue<Node> q;
inline void bfs(){//bfs求[sx,sy,sz]到[ex,ey,ez]的最短距离
q.push({sx , sy , sz}) , dis[sx][sy][sz] = 0;
while(!q.empty()){
auto x = q.front();
q.pop();
for (int i = 0 ; i < 6 ; i ++){
ll nx = x.x + dx[i] , ny = x.y + dy[i] , nz = x.z + dz[i];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= n && nz >= 1 && nz <= n && !vis[nx][ny][nz]) dis[nx][ny][nz] = dis[x.x][x.y][x.z] + 1 , vis[nx][ny][nz] = 1 , q.push({nx , ny , nz});
}
}
}
inline void solve(){
cin >> n >> sx >> sy >> sz >> ex >> ey >> ez;
for (int k = 1 ; k <= n ; k ++) for (int i = 1 ; i <= n ; i ++) for (int j = 1 ; j <= n ; j ++) cin >> a[i][j][k] , vis[i][j][k] = (a[i][j][k] - '0') , dis[i][j][k] = INF;
bfs() , cout << ((dis[ex][ey][ez] == INF) ? -1 : dis[ex][ey][ez]) << '\n';
}
int main(){
ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
solve();
return 0;
}D
题意
给定 个学生在校的时间段 ,选择一段连续的上课时间 使得至少有 个学生在这段时间内全程在校,求该课能持续的最长时间。
思路
由于我们想让课能持续的时间最长,那么选择刚好 个学生肯定是最优的。因为如果选择了第 个学生,若该学生的上课时间段为 或大于时间段 。那么答案一定不会变得更优,因为最后的答案一定不会改变,一定为 。因此选择 个同学维持的时间一定是最长的。
将所有学生的时段按 升序排序,再用小根堆维护右端点。当学生总数达到 个时,用堆顶最小右端点计算区间长度并更新最大值:
最后 即为答案。
时间复杂度为 。
AC code
/*
writer:akaryan
*/
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define Int __int128
#define db double
#define ldb long double
#define inf (1 << 30)
#define INF (1LL << 60LL)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()
#define bug(x) cout << #x << " = " << x << '\n'
using namespace std;
const int N = 3e5 + 10 , M = 2e5 + 10;
const int mod = 998244353;
ll n , k , ans;
priority_queue<ll , vector<ll> , greater<ll>> q;//维护小根堆
struct Node{
ll l , r;
}a[N];
inline void solve(){
cin >> n >> k;
for (int i = 1 ; i <= n ; i ++) cin >> a[i].l >> a[i].r;
sort(a + 1 , a + n + 1 , [&](const Node &x , const Node &y){return x.l < y.l;});//按左端点排序
for (int i = 1 ; i <= n ; i ++){
q.push(a[i].r);
if (q.size() > k) q.pop();
if (q.size() == k && q.top() >= a[i].l) ans = max(ans , q.top() - a[i].l);
}
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
solve();
return 0;
}后记
帮 ggy 调题,调到我晚上 点半。/hq/hq/hq