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 ...
随机推荐
- iOS登陆界面切换到注册界面并返回的UI设计(简易向)
功能实现 从登陆界面进入注册界面 从注册界面返回登陆界面 功能实现思路 在网上搜了搜发现各位大神用的是navigation,但个人感觉没(zhen)大(ting)必(bu)要(dong).所以在这里提 ...
- 基于 JuiceFS 构建高校 AI 存储方案:高并发、系统稳定、运维简单
中山大学的 iSEE 实验室(Intelligence Science and System) Lab)在进行深度学习任务时,需要处理大量小文件读取.在高并发读写场景下,原先使用的 NFS 性能较低, ...
- Bike Sharing Analysis(二)- 假设检验方法
假设检验 假设检验是推论统计学(inferential statistics)的一个分支,也就是对一个较小的.有代表性的数据组(例如样本集合)进行分析与评估,并依此推断出一个大型的数据组(例如人口)的 ...
- 背包dp——01背包
01背包是背包dp的基础的重点,重点的基础!!! 题意概要:有 n 个物品和一个容量为 W 的背包,每个物品有重量 w_{i} 和价值 v_{i} 两种属性,要求选若干物品放入背包使背包中物品的总价值 ...
- 『vulnhub系列』BEELZEBUB- 1
『vulnhub系列』BEELZEBUB- 1 下载地址: https://www.vulnhub.com/entry/beelzebub-1,742/ 信息搜集: 使用nmap扫描存活主机,发现主机 ...
- CF1137C 题解
考虑把每个点进行拆成 \(d\) 个点表示星期几走到这个点,那么原图上的边 \((u,v)\) 就被拆成\((pos_{u,i},pos_{v,i+1})\) 表示星期的变化. 然后考虑进行缩点,在一 ...
- SpringBoot学习篇
什么是SpringBoot?为什么要用SpringBoot 用来简化spring应用的初始搭建以及开发过程 使用特定的方式来进行配置(properties或yml文件) 创建独立的spring引用程序 ...
- [无线隔离]同一WIFI下两主机无法互联
问题描述 在公司WIFI下想进行两台主机之间的数据传输,却发现虽在同一网段且防火墙关闭也无法ping通. 在一台主机下查看ARP表,发现没有对方的IP与MAC记录. 使用Wireshark抓包,发现虽 ...
- IDEA新手使用教程之使用技巧总结【详解】
IDEA是一款功能强悍.非常好用的Java开发工具,近几年编程开发人员对IDEA情有独钟. 一.IDEA的下载 IDEA下载地址:https://www.jetbrains.com/idea/down ...
- Django查询特定条件的数据并插入其他表格模型
要将特定 wk_nu 值对应的数据批量插入到 MPS005D3Model 中,你可以执行以下步骤: 确定要插入的 wk_nu 值. 获取与该 wk_nu 相关的数据. 将获取的数据逐一创建为 MPS0 ...