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. 关于java时间类型和格式化到微秒问题

    常规的问题此处略,因为网络上到处都是,这里主要讨论三个问题: 1.数据库的时间戳类型(含微秒)对应java的什么类型 java的常见时间类型比较多: java.util.Date java.sql.D ...

  2. Linux特殊权限之SBIT

    简单点,说话的方式简单点: 用于修饰目录 其他用户x位替换成t 作用:目录属主在该目录下创建的文件只有该属主能删除

  3. 使用Redis+SpringBoot实现定时任务测试

    Redis实现定时任务是基于对RedisKey值的监控 具体代码实现: 代码GitHub地址:https://github.com/Tom-shushu/Project 建一个SpringBoot项目 ...

  4. 怎样理解 Vue 的单向数据流?

    数据从父级组件传递给子组件,只能单向绑定. 子组件内部不能直接修改从父级传递过来的数据. 所有的 prop 都使得其父子 prop 之间形成了一个单向下行绑定:父级 prop 的更新会向下流动到子组件 ...

  5. C++ Cast And Go Cast

    C++ A static_cast can be used to explicitly convert between related pointer types, such as void* and ...

  6. react 拖拽组件 自由拖拽,垂直水平拖拽

    react拖拽组件 推荐几个不错的开源拖拽组件以及使用方法 第一个拖拽组件 antd的Tree组件 这个拖拽组件经常用于层级关系的拖拽组件 可以动态的增删改 (排序,添加子层级~父层级,修改等). i ...

  7. 简单万能队列状态机——WTYKAMC@2023

    WTYKAMC@2023框架 [简介] 这是一个基于队列的灵活状态机,可以满足队列元素先进先出,先进后出,后进后出,后进先出,可以清除队列中未执行完的状态,且有一个默认超时执行状态:通过超时时间可以改 ...

  8. 国内中文版的 Chātgpt,真的好赞。

    这个软件是「Chātgpt」,Chātgpt 中文版是国内刚上线的一款人工智能技术的语言处理工具软件,它不仅可以学习和理解人类的语言来和人对话,还能撰写邮件.文案.翻译.代码等功能. 不需要OpenA ...

  9. K8S 中的 CRI、OCI、CRI shim、containerd

    哈喽大家好,我是咸鱼. 好久没发文了,最近这段时间都在学 K8S.不知道大家是不是和咸鱼一样,刚开始学 K8S.Docker 的时候,往往被 CRI.OCI.CRI shim.containerd 这 ...

  10. Pandas库学习笔记(1)

    参考:菜鸟教程 pandas库使用了NumPy的大多数功能.建议您先阅读有关NumPy的教程,然后再继续本教程. Pandas 适用于处理以下类型的数据: 与 SQL 或 Excel 表类似的,含异构 ...