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的更多相关文章

  1. 2015 Astar Contest - Round 3 题解

    1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...

  2. Contest Round #451 (Div. 2)F/Problemset 898F Restoring the Expression

    题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判 ...

  3. USACO 2023 January Contest, Bronze Problem 3. Moo Operations

    这道题目灰常简单,我们先从最简单的3个字符串开始 有以下几种情况: 可以看到,只有在中间是O的情况下才有可能变成MOO 辣么我们不妨在在s串中枚举这个中间 O 每枚举到一个就看看能不能用他的本身操作次 ...

  4. 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 ...

  5. Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd

    http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...

  6. Codeforces 240 F. TorCoder

    F. TorCoder time limit per test 3 seconds memory limit per test 256 megabytes input input.txt output ...

  7. cf499B-Lecture 【map】

    http://codeforces.com/problemset/problem/499/B B. Lecture     You have a new professor of graph theo ...

  8. Codeforces 240F. TorCoder 线段树

    线段树统计和维护某一区间内的字母个数.. . . F. TorCoder time limit per test 3 seconds memory limit per test 256 megabyt ...

  9. 物联网学生科协第三届H-star现场编程比赛

    问题 A: 剪纸片 时间限制: 1 Sec 内存限制: 128 MB 题目描写叙述 这是一道简单的题目,假如你身边有一张纸.一把剪刀.在H-star的比赛现场,你会这么做: 1. 将这张纸剪成两片(平 ...

  10. [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 ...

随机推荐

  1. Jenkins创建任务进行构建项目配置

    总体构建项目的操作步骤 分为Generna(总的描述).源码管理.构建触发器.构建环境.构建.构建后的操作 1.Dashboard-> new item > 新建一个任务,选择freest ...

  2. spring事务传递特性-REQUIRES_NEW和NESTED

    spring对于事务的实现的确是它的一大优点,节省了程序员不少时间. 关于事务,有许多可以聊的内容,例如实现方式.实现原理.传递特性等. 本文讨论传递特性中的REQUIRES_NEW,NESTED. ...

  3. springboot+security自定义登录-1-基础-自定义用户和登录界面

    为何学习spring security? 理由如下: 1)虽然可以不用,但难免部分客户又要求 2)某种程度上,security还是不错的,譬如csrf,oauth等等,省了一些功夫. 3)虽然spri ...

  4. RuoYi-Cloud从配置到运行

    前期准备工作 若依微服务版(RuoYi-Cloud)代码下载:https://gitee.com/y_project/RuoYi-Cloud 注册中心(nacos)下载:https://www.ali ...

  5. VMware 17 Exception 0xc0000094 解决

    VMWare16的虚拟机升级到17时, 可能会出现虚拟机可以正常使用, 但编辑设置就会出现vmui错误的现像. VMware Workstation unrecoverable error: (vmu ...

  6. Linux修改dmesg 显示大小

    背景 由于在调试的时候没有串口,而通过dmesg打印的内容发现其中有截断的现象. 因此为了方便调试.将有关的缓冲区加大. 原理 Linux内核中打印内核消息时用到了一个环形缓冲区. 这个缓冲区的大小由 ...

  7. NXP i.MX 8M Plus工业开发板硬件说明书( 四核ARM Cortex-A53 + 单核ARM Cortex-M7,主频1.6GHz)

    前  言 本文主要介绍创龙科技TLIMX8MP-EVM评估板硬件接口资源以及设计注意事项等内容. 创龙科技TLIMX8MP-EVM是一款基于NXP i.MX 8M Plus的四核ARM Cortex- ...

  8. sprak应用执行过程

  9. Java中的栈、堆和常量池

    Java程序是运行在JVM(Java虚拟机)上的,因此Java的内存分配是在JVM中进行的,JVM是内存分配的基础和前提. Java程序的运行会涉及以下的内存区域: 寄存器:JVM内部虚拟寄存器,存取 ...

  10. MySQL 并发控制(锁得使用)

    导读 并发问题:同一时刻进行读写,并发问题回引发数据不一致问题. 解决并发问题:MySQL采用了锁定机制去解决并发问题 锁的分类 MySQL使用两种锁机制去解决问题:共享锁和排他锁,也叫读锁或者写锁. ...