SMU Spring 2023 Trial Contest Round 9
A. Wrong Subtraction
在k次操作里, 将n的最后一位数减1,如果是0就去掉,模拟一下就好了.
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long using namespace std; const int N = 2e3 + 10, mod = 1e9 +7; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
vector<int> a, b;
void solve()
{
string s;
cin >> s >> m;
while(m--){
if(s.back() != '0'){
s[s.size() - 1] --;
}
else
s.erase(s.size() - 1, 1);
}
cout << s << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
//cin >> Ke_scholar ;
while(Ke_scholar--)
solve();
return 0;
}
B. Two-gram
暴力枚举,每次取两个字母再循环找一遍,输出最多次数的即可.
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long using namespace std; const int N = 2e3 + 10, mod = 1e9 +7; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
vector<int> a, b;
void solve()
{
cin >> n;
string s;
cin >> s;
string ans ;
int maxx = 0;
for(int i = 0;i < s.size() - 1; i++){
string s1 = s.substr(i,2);
int x = 0;
for(int j = 0; j <s.size() - 1; j ++){
if(s.substr(j, 2) == s1)
x ++;
}
if(x > maxx){
maxx = x;
ans = s1;
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
//cin >> Ke_scholar ;
while(Ke_scholar--)
solve();
return 0;
}
C. Less or Equal
有个很坑的点,结束了看题解我才知道,k = 0 的时候分两种,如果最小的元素不是1的话应该输出1才对,害,我还以为0代表没有比较的,直接输出-1.
m == n 和 m == 0时特判一下,其余排个序再判断m前后是否相等的就行.
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long using namespace std; const int N = 2e3 + 10, mod = 1e9 +7; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
vector<int> a, b;
void solve()
{
cin >> n >> m;
for(int i = 0;i < n; i++){
int x;
cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
if(m == n){
cout << a.back() << endl;
return ;
}
if(m == 0){
if(a.front() != 1)
cout << 1 << endl;
else
cout << -1 << endl;
return ;
}
if(a[m] == a[m - 1]){
cout << -1 << endl;
}
else
cout << a[m - 1] << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
//cin >> Ke_scholar ;
while(Ke_scholar--)
solve();
return 0;
}
D. Divide by three, multiply by two
将能被3整除的数或者是两倍关系的数的下标建成一条单向边,然后dfs去搜一条到达n的线路即可,至于为什么不用a[i]的值去建边,因为数据太大会寄.像这种.
input
2
1000000000000000000 3000000000000000000
output
3000000000000000000 1000000000000000000
#include <bits/stdc++.h>
#define endl '\n'
#define int long long using namespace std;
const int N = 110; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
bool vis[N];
int arr[N];
vector<int> v[N];
int a[N],ans[N];
void dfs(int val,int x){
ans[x] = a[val];
if(x >= n){
for(int i = 1;i <= n; i++) {
cout << ans[i] << ' ';
}
return ;
}
for(auto i : v[val])
dfs(i, x + 1);
return ;
}
void solve()
{
cin >> n;
for(int i = 0; i < n ;i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
for(int j = 0;j < n;j ++){
if(i == j)
continue;
if(a[i] == a[j] * 3 || a[i] * 2 == a[j]){
v[i].push_back(j);
}
}
}
for(int i = 0;i < n; i++){
dfs(i, 1);
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
//cin >> Ke_scholar;
while(Ke_scholar--)
{
solve();
}
return 0;
}
E. Cyclic Components
将每条边的入度记录一下,两点的入度都是2的话就用并查集维护一下,判断是否成环.
#include <bits/stdc++.h>
#define endl '\n'
#define int long long using namespace std;
const int N = 2e5 + 10; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
bool vis[N];
int arr[N];
int ans;
vector<PII> edge;
int sum[N];
int fa[N];
int find(int x){
if(fa[x] == x)
return x;
return fa[x] = find(fa[x]);
}
void add(int x, int y){
int dx = find(x);
int dy = find(y);
if(dx != dy)
fa[dx] = dy;
else
ans ++;
}
void solve()
{
cin >> n >> m;
for(int i = 0; i < m; i++){
int x, y;
cin >> x >> y;
edge.push_back({x, y});
sum[x] ++;
sum[y] ++;
}
for(int i = 1; i <= n; i++)
fa[i] = i;
for(int i = 0;i < m; i++){
if(sum[edge[i].first] == 2 && sum[edge[i].second] == 2)
add(edge[i].first, edge[i].second);
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int Ke_scholar = 1;
//cin >> Ke_scholar;
while(Ke_scholar--)
{
solve();
}
return 0;
}
F. Consecutive Subsequence
用map做动态规划,记录最大的连续上升序列的结尾的值(记为maxid),然后从arr数组后面搜,如果等于maxid就放入ans里,maxid--,最后输出ans即可
#include <bits/stdc++.h>
#define endl '\n'
#define int long long using namespace std;
const int N = 2e5 + 10; //typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<int, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
bool vis[N];
int arr[N];
int ans;
int dp[N];
void solve()
{
cin >> n;
int maxx = 0, maxid;
for(int i = 1; i <= n; i++){
cin >> arr[i];
mp[arr[i]] = max(mp[arr[i]], mp[arr[i] - 1] + 1);
if(mp[arr[i]] > maxx) {
maxx = mp[arr[i]];
maxid = arr[i];
}
}
cout << maxx << endl;
vector<int> ams;
for(int i = n; i > 0; i--){
if(arr[i] == maxid){
ams.push_back(i);
maxid--;
}
}
for(int i = ams.size() - 1; i >= 0; i--)
cout << ams[i] << ' ';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
//cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
SMU Spring 2023 Trial Contest Round 9的更多相关文章
- 2015 Astar Contest - Round 3 题解
1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...
- Contest Round #451 (Div. 2)F/Problemset 898F Restoring the Expression
题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判 ...
- USACO 2023 January Contest, Bronze Problem 3. Moo Operations
这道题目灰常简单,我们先从最简单的3个字符串开始 有以下几种情况: 可以看到,只有在中间是O的情况下才有可能变成MOO 辣么我们不妨在在s串中枚举这个中间 O 每枚举到一个就看看能不能用他的本身操作次 ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd
http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...
- Codeforces 240 F. TorCoder
F. TorCoder time limit per test 3 seconds memory limit per test 256 megabytes input input.txt output ...
- cf499B-Lecture 【map】
http://codeforces.com/problemset/problem/499/B B. Lecture You have a new professor of graph theo ...
- Codeforces 240F. TorCoder 线段树
线段树统计和维护某一区间内的字母个数.. . . F. TorCoder time limit per test 3 seconds memory limit per test 256 megabyt ...
- 物联网学生科协第三届H-star现场编程比赛
问题 A: 剪纸片 时间限制: 1 Sec 内存限制: 128 MB 题目描写叙述 这是一道简单的题目,假如你身边有一张纸.一把剪刀.在H-star的比赛现场,你会这么做: 1. 将这张纸剪成两片(平 ...
- [cf contest 893(edu round 33)] F - Subtree Minimum Query
[cf contest 893(edu round 33)] F - Subtree Minimum Query time limit per test 6 seconds memory limit ...
随机推荐
- 卷积神经网络-AlexNet
AlexNet 一些前置知识 top-1 和top-5错误率 top-1错误率指的是在最后的n哥预测结果中,只有预测概率最大对应的类别是正确答案才算预测正确. top-5错误率指的是在最后的n个预测结 ...
- DAX 自动生成日期表-与订单表(业绩表)相同日期区间
日期表 = ADDCOLUMNS ( CALENDAR (MIN('业绩表'[日期]), MAX('业绩表'[日期])), //关键在于MIN函数和MAX函数的使用 "年度", Y ...
- InvocationTargetException和UndeclaredThrowableException异常介绍
今天来介绍了两个陌生又熟悉的异常类,熟悉是因为我们经常会遇到它们,陌生是好像又从来不知道它们是做什么的 假定读者已经清楚了Java的异常分类: 一是程序不能处理的错误(Error), 二是程序应该避免 ...
- Golang 切片作为函数参数传递的陷阱与解答
作者:林冠宏 / 指尖下的幽灵.转载者,请: 务必标明出处. GitHub : https://github.com/af913337456/ 出版的书籍: <1.0-区块链DApp开发实战&g ...
- [oeasy]python0085_[趣味拓展]字体样式_下划线_中划线_闪动效果_反相_取消效果
字体样式 回忆上次内容 \033 xm 可以改变字体样式 0m - 10m 之间设置的 都是字体效果 0m 复原 1m 变亮 2m 变暗 添加图片注释,不超过 140 字(可选) ...
- 学习笔记--区分Java中类与对象
区分Java中类与对象 你能接受 String 吗? 如果能,以下内容可进行类比 编写 User 类 public class User{ // 用户编号 // int 是一种基础数据类型 // id ...
- Python 阿里云OSS文件上传下载与文件删除及检索示例
阿里云OSS文件上传下载与文件删除及检索示例 实践环境 运行环境: Python 3.5.4 CentOS Linux release 7.4.1708 (Core)/Win10 需要安装以下类库: ...
- ABC348
A link 这道题就先输出整个的\(oox\),再输出剩一个两个的. 点击查看代码 #include<bits/stdc++.h> using namespace std; int n; ...
- VUE系列---深度解析 Vue 优化策略
在前端开发中,性能优化一直是一个重要的课题.Vue.js 提供了多种优化策略,帮助开发者构建高性能的应用.本文将深入解析以下几个优化策略: 使用 v-once.v-if 和 v-show 的区别和优化 ...
- mysql 参数调优
临时调整mysql内存,最好在项目开始的时候直接改配置不用临时设置 SET GLOBAL innodb_buffer_pool_size = 2147483648; 查询当前使用内存: SHOW VA ...