重庆市赛
summary: 第十一届重庆市大学生程序设计竟赛西南大学, 2023 年 12 月 17 日
A Yesterday Once More
2 seconds
256 megabytes
历经四年, 终于再次迎来重庆市大学生程序设计竟赛。在第十届重庆市大学生程序设计竟赛中, 狂小 P 想解锁快乐 C 的 iPhone, 但是他只知道解锁密码由四位阿拉伯数字'
现在给你一个长度为 10 的数组
四年前狂小 P 按照可能的密码从小到大逐一进行尝试, 在四年后的今天, 狂小 P 已经尝试到了
Input
第一行包含 10 个整数, 表示
第二行包含一个长度为 4 的字符电, 表示
(保证在给出的输入下,
Output
输出一个长度为
Examples
input 1
0 0 0 0 1 1 0 0 0 0
4445
ouput 1
4454
input 2
0 0 0 0 0 0 1 0 0 0
6666
ouput 2
-1
input 3
1 1 0 0 0 0 0 0 0 0
0001
output 3
0010
Code
比赛时,使用的是进制的做法,但是我需要 dfs 的写法.
gpt 4 dfs 写法
#include <bits/stdc++.h>
using namespace std;
int d[10], code[4];
int inc()
{
int i = 3;
while (i >= 0 && code[i] == 9)
code[i] = 0,i--;
if (i >= 0)
code[i]++;
return i;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr);
for (int i = 0; i < 10; i++)
cin >> d[i];
for (int i = 0; i < 4; i++)
{
char c;
cin >> c;
code[i] = c - '0';
}
while (1)
{
int i = inc();
if (i < 0)
{
cout << -1 << '\n';
break;
}
for (i = 0; i < 4; i++)
if (d[code[i]] == 0)
break;
if (i == 4)
{
for (i = 0; i < 4; i++)
cout << code[i];
cout << '\n';
break;
}
}
}
在这段代码中,首先输入 inc ()
函数是用来增加密码的,如果找不到符合要求的密码,那么返回 -1
。对于每个增加的密码,检查它的每一位是否都出现在
B 典
16109 和 B 题很像。
Time limit: 2 seconds
Memory limit: 256 megabytes
cxvdzxhb 喜欢平方数, 比如
cxvdzxhbx 现在得到了一个长度为
每次问
Input
第一行 2 个整数
第二行有
接下来
Output
对于每个询问, 输出一行一个整数, 表示答案, 由于答案可能非常大, 你需要对
Example
input
5 3
1 2 3 4 5
1 2
3 3
3 5
output
3
0
3
C 电路
2 seconds
256 megabytes
有一个电路, 由
Input
第一行包含两个正整数
接下来
接下来
Output
输出仅一个整数, 表示最小成本。
Example
input
5 4
4 1 100 100 100
2 100 1
3 100 100 1
5 100 100 100 1 1
2 100 1
1 2 5
1 3 5
1 4 10
1 5 5
output
55
D 搬空商店
Time limit: 2 seconds
Memory limit: 256 megabytes
某手游有
- 刷一次
副本, 你可以得到 个铜材料, 个特殊材料。 - 刷一次 B 副本, 你可以得到
个银材料, 个特殊材料。 - 刷一次
副本, 你可以得到 个金材料, 个特殊材料。 - 刷一次 D 副本, 你可以得到
个铜材料, 个银材料, 个金材料, 个特殊材料。
另外 5 个铜材料可以转换为 1 个银材料, 5 个银材料可以转换为 1 个金材料。
问最少刷多少次副本, 才能完美商店毕业, 同时你还想知道 ABCD 副本分别要刷多少次。如果有多个答案满足条件, 你想尽可能的少刷
Input
第一行 4 个整数
第二行 2 个整数
第三行 2 个整数
第四行 2 个整数
第五行 4 个整数
Output
输出一行, 包含五个整数, 第一个整数表示总刷本次数, 后面四个整数分别表示
Example
input
100 200 300 400
100 10
90 10
80 10
10 11 12 70
output
11 1 2 3 5
E Misreading
Time limit: 2 seconds
Memory limit: 256 megabytes
Given is a positive integer
can be represented as , where is a prime number and is a positive integer; divides ; is different from all integers chosen in previous operations.
Then, replace
Find the maximum number of times the operation can be applied.
The above problem is from D - Div Game
When lajiniunai first faced this problem, he read it wrong, changed the third condition to "
can be represented as , where is a prime number and is a positive integer; divides ; is different from all integers chosen in previous operations.
Now with others unchanging, find the maximum number of times the operation can be applied.
Input
The first line contains a positive integer
Output
For each test case, print one line containing a number showing the answer.
翻译版
对于给定的正整数
可表示为 ,其中 是一个质数, 是一个正整数; 整除 ; 与先前操作中选择的所有整数不同。
然后,用
找出可以执行此操作的最大次数。
当 lajiniunai 第一次面对这个问题时,他读错了题目,将第三个条件改成了“
现在在其他条件不变的情况下,找出可以执行此操作的最大次数。
输入
第一行包含一个正整数
输出
对于每个测试用例,打印一行包含一个数字,表示答案。
Example
input
10
1
2
3
4
5
6
7
8
9
10
output
0
1
1
1
1
1
1
2
1
1
F 交换
Time limit: 1 seconds
Memory limit: 256 megabytes
endereye 得到了一个只包含数字
个全新的字符串
中有些字符串只用至少
交换操作。他想知道这个
他不知道怎么计算这个答案,所以把问题交给了你。
Input
第一行一个整数
接下来
每组数据第一行,包含一个整数
第二行包含一个由数字
Output
每组数据输出仅包含一行,输出答案
Example
input
4
3
121
3
123
3
111
3
221
output
1
3
0
2
G word 文档
Time limit: 1 seconds
Memory limit: 256 megabytes
在 word 文档中, 有一个字符
- 全选: 选中文档中所有字符。
- 复制: 复制当前选中的字符到粘贴板。
- 粘贴: 将粘贴板的内容粘贴, 如果当前没有选中任意字符, 则内容会追加在原内容的后面。如果当前选中了一些字符, 那么这些字符会被当前粘贴的内容替换, 并且会取消选中状态。
你需要用最少的次数, 将文档中的字符数量变为恰好
Input
第一行包含一个正整数
接下来
Output
Example
input
3
1
9
998244353
output
0
10
998244355
Note
对于样例中的第二组数据, 变化过程如下:
字符外的方框表示被选中状态。总共
Code
群友的代码 (记忆化搜索)
#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> dp;
void dfs(int n)
{
dp[n] = n + 2;
for (int i = 2, m = sqrt(n); i <= m; i++)
{
if (n % i == 0)
{
if (dp.find(n / i) == dp.end())
dfs(n / i);
dp[n] = min(dp[n], dp[n / i] + 2 + i);
}
}
}
void solve()
{
int n;
cin >> n;
if (dp.find(n) != dp.end())
{
cout << dp[n] << '\n';
return;
}
if (n == 1)
{
cout << '0' << '\n';
return;
}
dfs(n);
cout << dp[n] << '\n';
}
int main()
{
ios::sync_with_stdio (false),cin.tie (nullptr);
int t = 1;
cin >> t;
while (t--)
solve();
}
H Hotpot
Time limit: 2 seconds
Memory limit: 256 megabytes
Chongqing hotpot is one of the most famous dishes around the world. People love its spicy taste.
There are
Every minute, HeartBlack will add one ingredient to hotpot or take out all well-cooked (ready-to-eat) ingredients in the hotpot (If there are no cooked ingredients, she will do nothing).
Given what HeartBlack does at the start of every minute.
For each time she takes out ingredient, you need to print the types of ingredients she takes out in increasing order (If she takes out nothing, print -1) in a line. Attention, if there are more than one ingredients of the same type, the output needs to be repeated. For example, if there are 3 ingredients of type 2 taken out, you should print "2 2 2 ".
Input
The first line contains two positive integers,
The second line contains
The next
If
If
Output
For each minute HeartBlack takes out, print the types of ingredients she takes out in increasing order in a line or print -1 when there are no cooked ingredients.
Example
input
3 6
1 2 3
0 2
1
0 3
0 2
0 1
1
output
-1
1 2 2 3
Note
Attention, if there are more than one ingredients of the same type, the output needs to be repeated. For
example, if there are
Code
用 set 解决,还并不知道是否正确。
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int>> b,cooked;//b代表等等待成熟的食物,cooked代表已经成熟的食物
int n, t, a[200010];
int main()
{
int k = 0;
cin >> n >> t;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int time = 1; time <= t; time++)
{
int op;
cin >> op;
if (!op)
{
int x;
cin >> x;
b.insert({x, time + a[x]});
}
else
{
for (auto it = b.begin(); it != b.end();)
{
if (time >= it->second)
{
cooked.insert({it->first,k++});
it = b.erase(it);
}
else
break;
}
if (cooked.empty())
{
cout << -1;
}
else
{
for (auto v : cooked)
cout << v.first << " ";
}
cout << '\n';
cooked.clear();
}
}
}
I 井盖
Time limit: 3 seconds
Memory limit: 256 megabytes
在路面上, 有
如果答案能表示为有理数的形式
Input
第一行包含一个整数
接下来
Output
输出一行一个整数, 表示答案。
Examples
input 1
3
0 0 1 2
1 0 1 3
0 2 1 4
output 1
41666667
input 2
4
0 0 1 2
2 0 1 2
0 2 1 2
2 2 1 2
output 2
750000006
Note
在第一个样例中, 坏掉一个或两个井盖被围住的面积都是 0 , 当坏掉了三个井盖的时候, 围住的面积是