ACM2021辽宁省赛:CDEFGILM

C-传染病统计_

问题解析

一开始没注意到n只有8。。。当1e5的范围来写的。

这题就是说,所有相隔距离小于等于2的是一个集体,然后我们要选一个集体感染病毒,问最多的感染人数和最小的感染人数。

先对所有人进行升序排序(因为不知道给的输入是不是有序的)。然后遍历一遍数组,把相隔距离不超过2的都当作一个集体,如果B和A的距离超过2了,说明B是另一个集体,我们重新计算。在此过程中维护集体人数的最大值和最小值。

分别输出最小值和最大值即可。

时间复杂度:(T*nlogn);

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>#pragma GCC optimize(2)
#pragma GCC optimize(3)#define endl '\n'
#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 1e6 + 50;void solve()
{int n;cin >> n;vector<int>v(n);for (int i = 0; i < n; i++)cin >> v[i];sort(v.begin(), v.end());int mx = 0, mn = 1e9, len = 1;for (int i = 1; i < n; i++){if (v[i] - v[i - 1] <= 2)len++;else{mx = max(mx, len);mn = min(mn, len);len = 1;}}mx = max(mx, len);mn = min(mn, len);cout << mn << " " << mx << endl;
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t = 1;cin >> t;while (t--){solve();}return 0;
}

D-阿强与网格

问题解析

一开始下意识的想BFS,后来发现根本不用那么麻烦(而且也过不了)。

题目已经给定了我们每次操作所花成本,我们可以根据x和y的大小,与网格的形状直接计算得出结果,为了方便,我们认定n比m大:

  1. 如果网格是n *1的形状,此时显然只能用x的方式移动,成本为:*(n-1)x;
  2. 因为y走一步等于x走两步,所以如果x的两倍小于等于y,我们直接用x走,成本为:*(n+m-2)x

剩下的情况,我们显然是能用y走就用y走,问题是y该怎么走呢?

一开始想着先对角线移动到底部,然后剩下的用x平移过去:(红色路线)

后来发现,其实剩下的位置也是可以斜着走的:(蓝色路线)

只不过这么走有约束,即到了底边后,距离终点的距离如果是奇数,则会停在终点的前一格,而这时我们只能用x走了:(橙色路线)

那么对于其它的情况:我们先走m次y,如果距离终点的距离:n-m是奇数,我们走了(n-m-1)次y后,还要走一次x,成本为:m*y+(n-m-1) * y+x;如果n-m是偶数,我们直接全走y即可,成本为:m*y+(n-m) * y.

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>#pragma GCC optimize(2)
#pragma GCC optimize(3)#define endl '\n'
#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 4e5 + 50;void solve()
{int n, m, x, y,ans;cin >> n >> m >> x >> y;//为了方便,我们保证n比m大if(n<m)swap(n,m);if(m==1)ans=(n-1)*x;else if(x*2<=y)ans=(n+m-2)*x;else if(x<=y)ans=(m-1)*y+(n-m)*x;else {if((n-m)%2==1)ans=(n-2)*y+x;else ans=(n-1)*y;}cout<<ans<<endl;
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t = 1;cin >> t;while (t--){solve();}return 0;
}

E-生活大爆炸

问题解析

这道题主要思路就是我们高中就学过的组合数计算。

男生有n人,女生有m人,需要组成总人数为t的队伍,其中男生人数不能少于4人,女生人数不能少于1人。

那么可能的排列组合就是:4个男生和t-4名女生,5个男生和t-5名女生,……,t-1名男生和1名女生。

对于第一个组合来说,就是n个男生中随机选出4个,搭配上m个女生中随机选出t-4个,即:C(n,4)*C(m,t-4)。其余的以此类推,把所有的组合数相加即可。

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>#pragma GCC optimize(2)
#pragma GCC optimize(3)#define endl '\n'
#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 4e5 + 50;int C[70][70];
void init()
{for (int i = 0; i <= 70; i++)for (int j = 0; j <= i; j++) {if (!j)C[i][j] = 1;elseC[i][j] = C[i - 1][j - 1] + C[i - 1][j];}
}void solve()
{int n, m, t;cin >> n >> m >> t;init();int res = 0;for (int i = 4; i <= min(n, t - 1); i++){res += C[n][i] * C[m][t - i];}cout << res;
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t = 1;//cin >> t;while (t--){solve();}return 0;
}

F-Capslock

问题解析

只要看第2到第n个字符是不是都是大写字母,如果是,遍历一遍数组把大写字母变成小写字母,把小写字母变成大写字母。如果不是,直接原样输出。

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>#pragma GCC optimize(2)
#pragma GCC optimize(3)#define endl '\n'
#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 1e6 + 50;void solve()
{string s;cin >> s;int n = s.size();bool flag = true;for (int i = 1; i < n; i++){if (!(s[i] >= 'A' && s[i] <= 'Z')){flag = false;break;}}if (!flag){cout << s << endl;return;}if (s[0] >= 'A' && s[0] <= 'Z'){s[0] += 32;}else s[0] -= 32;for (int i = 1; i < n; i++){s[i] += 32;}cout << s;
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t = 1;//cin >> t;while (t--){solve();}return 0;
}

G-字节类型

问题解析

可以用字符串来接收输入。

根据字符串的长度和转换成整数后的大小进行比较即可。

如果担心longlong会炸,就用unsigned long long来存储结果。字符串长度要是大于19,直接就是BigInteger。

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>#pragma GCC optimize(2)
#pragma GCC optimize(3)#define endl '\n'
#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 1e6 + 50;ull check(string s)
{ull num = 0;int n = s.size();for (int i = 0; i < n; i++){num *= 10;num += s[i] - '0';}return num;
}void solve()
{string s;cin >> s;int n = s.size();if (n > 19)cout << "BigInteger" << endl;else if (n <= 3){int num = stoi(s);if (num <= 127)cout << "byte" << endl;else cout << "short" << endl;}else if (n <= 5){int num = stoi(s);if (num <= 32767)cout << "short" << endl;else cout << "int" << endl;}else if (n <= 10){int num = stoi(s);if (num <= 2147483647)cout << "int" << endl;else cout << "long" << endl;}else if (n <= 19){ull num = check(s);if (num <= 9223372036854775807)cout << "long" << endl;else cout << "BigInteger" << endl;}
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t = 1;//cin >> t;while (t--){solve();}return 0;
}

I-完美主义

问题解析

开一个单点修改+区间查询的线段树。

  • st[k]表示,st[k]为true,表示当前区间是完美区间,反之不是;
  • right[k]表示当前区间最右边的元素;
  • left[k]表示当前区间最右边的元素;

对于一个区间,如果它的左右子区间的st都为true,且左区间的right小于等于右区间的left,那么当前区间也是一个true;反之是false。由此类推,我们每次更新时,只要维护区间的left和right,再根据他们的大小判断st的值,就可以快速得出当前区间是否是完美的。

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>#pragma GCC optimize(2)
#pragma GCC optimize(3)#define endl '\n'
#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 4e5 + 50;int myleft[4 * N], myright[4 * N], a[N];
bool st[4 * N];
void build_tree(int k, int l, int r)
{if (l == r){myleft[k] = a[l];myright[k] = a[l];st[k] = true;return;}int m = (l + r) / 2;build_tree(k + k, l, m);build_tree(k + k + 1, m + 1, r);if (myleft[k + k + 1] >= myright[k + k]){st[k] = st[k + k] && st[k + k + 1];}else st[k] = false;myleft[k] = myleft[k + k];myright[k] = myright[k + k + 1];
}void revise(int k, int l, int r, int x, int y)
{if (l == r){myleft[k] = y;myright[k] = y;return;}int m = (l + r) / 2;if (x <= m)revise(k + k, l, m, x, y);else revise(k + k + 1, m + 1, r, x, y);if (myleft[k + k + 1] >= myright[k + k]){st[k] = st[k + k] && st[k + k + 1];}else st[k] = false;myleft[k] = myleft[k + k];myright[k] = myright[k + k + 1];
}//对于pair<bool, pair<int, int>>,first表示这个区间的st。
//second。first是left;second。second是right
pair<bool, pair<int, int>> calc(int k, int l, int r, int x, int y)
{if (l == x && r == y)return { st[k],{myleft[k],myright[k]} };int m = (l + r) / 2;if (y <= m)return calc(k + k, l, m, x, y);elseif (x > m)return calc(k + k + 1, m + 1, r, x, y);else{auto ans1 = calc(k + k, l, m, x, m);auto ans2 = calc(k + k + 1, m + 1, r, m + 1, y);if (ans1.first == false || ans2.first == false){return { false,{-1,-1} };}else{if (ans1.second.second <= ans2.second.first){return { true,{ans1.second.first,ans2.second.second} };}else return { false,{-1,-1} };}}
}void solve()
{int n, m, t, x, y;cin >> n >> m;for (int i = 1; i <= n; i++)cin >> a[i];build_tree(1, 1, n);while (m--){cin >> t >> x >> y;if (t == 1){revise(1, 1, n, x, y);}else{if (calc(1, 1, n, x, y).first){cout << "Yes" << endl;}else cout << "No" << endl;}}
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t = 1;//cin >> t;while (t--){solve();}return 0;
}

L-神奇的回答

问题解析

大于18的输出18,小于等于18的原样输出。

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>#pragma GCC optimize(2)
#pragma GCC optimize(3)#define endl '\n'
#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 1e6 + 50;void solve()
{int n;cin >> n;if (n >= 18)cout << 18 << endl;else cout << n << endl;
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t = 1;cin >> t;while (t--){solve();}return 0;
}

M-比赛!

问题解析

拓扑排序。

根据每个人的回答,我们把它看成“A:BC”,转化成关系就是,B->A->C。我们以此来建图,同时记录每个点的入度。

建图之后来一遍拓扑排序,用一个字符串s来存储结果,因为入度为0的点,相当于它的前面没有别的选手,我们就可以把它加入到字符串的尾部。

如果拓扑排序后,所有的选手都在字符串里了,我们就把他输出;否则输出No Answer。

AC代码

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include <random>
#include<numeric>
#include<string>
#include<string.h>
#include<iterator>
#include<fstream>
#include<map>
#include<unordered_map>
#include<stack>
#include<list>
#include<queue>
#include<iomanip>
#include<bitset>#pragma GCC optimize(2)
#pragma GCC optimize(3)#define endl '\n'
#define int ll
#define PI acos(-1)
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PII;
const int N = 4e5 + 50;vector<char>graph[300];
unordered_map<char, int>mymap;
void solve()
{int n;cin >> n;string s;for (int i = 1; i <= n; i++){cin >> s;graph[s[2]].push_back(s[0]);graph[s[0]].push_back(s[3]);if (!mymap.count(s[2]))mymap[s[2]] = 0;mymap[s[0]]++;mymap[s[3]]++;}queue<char>que;string str;for (auto& i : mymap){if (i.second == 0){str += i.first;que.push(i.first);}}if (que.size() == 0){cout << "No Answer" << endl;return;}while (!que.empty()){auto t = que.front();que.pop();bool flag = false;for (auto i : graph[t]){mymap[i]--;if (mymap[i] == 0){str+=i;que.push(i);}}}if(mymap.size()!=str.size()){cout << "No Answer" << endl;}else cout << str << endl;
}signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t = 1;//cin >> t;while (t--){solve();}return 0;
}

ACM2021辽宁省赛:CDEFGILM相关推荐

  1. 2020年ICPC辽宁省赛- 最长回文串(Java)

    最长回文串 题目描述 算法分析 代码展示 题目描述 链接:ICPC辽宁省赛复现赛 题目描述: 回文串是反转后与自身完全相同的字符串 比如:"ABA","ACMMCA&qu ...

  2. [ACM]辽宁省赛2010 (HZNU 1081-1089)

    虽然退役了,但偶尔水几题醒醒脑还是不错的=_= 1085 Intermediary 暂时还没做 1081: Dinner 时间限制: 1 Sec   内存限制: 32 MB 提交: 5   解决: 3 ...

  3. 职教大赛正热华三通信实训室方案为辽宁省赛“加小灶”

    春暖花开,辽宁省职业院校技能大赛即将拉开帷幕.辽宁省教育厅.辽宁省职业院校技能大赛组委会特意邀请杭州华三通信技术有限公司(简称华三通信)进行高职组"计算机网络应用"赛项的赛前培训. ...

  4. 2015年辽宁省赛Interesting Tree

    题目描述 Recently, Miss Huang want to receive a Tree as her birthday gift! (What a interesting person!)  ...

  5. 辽宁省赛2010 G - NEW RDSP MODE I【思路题】(省赛选拔赛之个人赛9)

    题目链接:https://ac.2333.moe/Problem/view.xhtml?id=1225 比赛链接:https://vjudge.net/contest/157779#overview ...

  6. 2021辽宁省赛-I.完美主义-M.比赛

    I.完美主义 链接:完美主义 (nowcoder.com) 来源:牛客网 题目描述  阿强采摘了一些苹果,并把他们分堆排成了一行,从左往右编号为第 1 -

  7. 2021辽宁省赛——H制造游戏币

    题目链接 题意: n n n 个点构成若干条链,每个点有一个权值且可以选任意次,父节点的选择次数必须严格大于子结点,求最后权值总和为 T T T 的方案数 题解: 由于是严格大于,所以对于一条链,从叶 ...

  8. 全国计算机技术大赛获奖名单,【大科·数院】荣光数院,满载而归——2019年全国计算机设计大赛省赛成绩斐然...

    原标题:[大科·数院]荣光数院,满载而归--2019年全国计算机设计大赛省赛成绩斐然 2019年全国计算机设计大赛辽宁省决赛由辽宁省教育厅.辽宁省财政厅主办,沈阳师范大学承办,于2019年5月17日- ...

  9. 朴素高精度乘法的常数优化

    2015年辽宁省赛热身赛有一道高精度乘法 传送门:NEUOJ 1574 A*B 1574: A * B 时间限制: 10 Sec  内存限制: 128 MB 题目描述 Calculate $a \ti ...

最新文章

  1. JavaScript高级程序设计(第3版)非扫描版
  2. 图像处理与计算机视觉:基础,经典以及最近发展(5)计算机视觉
  3. linux命令速查手册_干货| 有了这个速查手册,还怕Linux命令记不住?
  4. OpenCV, 名校机器学习相关课程
  5. 基于.NET SingalR,LayIM2.0实现的web聊天室
  6. php_mysql注入load_file()IIS配置文件获取
  7. 剑指offer-二进制中1的个数
  8. 有mysql文件怎么运行不了_MySQL安装常见问题(找不到文件,系统服务无法启动...)...
  9. html资源文件记载进度条,HTML5矢量实现文件上传进度条
  10. 13 消息提示 notification 介绍
  11. mii-tool查看网卡状态
  12. 大数据实验数据集何处来?
  13. IE兼容/IE5兼容踩过的坑
  14. 黑莓手机刷linux,黑莓老机型ROM刷机资源
  15. 微信卡券开发-卡券核销
  16. 用java设置网页背景图片_JAVA设置背景图片
  17. Region Proposal by Guided Anchoring
  18. 六.爬虫--京东登录破解(二)
  19. 《平衡掌控者 游戏数值战斗设计》学习笔记(四)技能与装备设计
  20. DFS(深度优先遍历)

热门文章

  1. 4G LTE浪潮何时席卷全球?
  2. 虚拟服务器设置虚拟内存,vmware虚拟机关于内存的一项设置,可以提高你的虚拟机运行效能-虚拟内存怎么设置最好...
  3. JS HTML5仿微信朋友圈特效
  4. exsi rh2288hv5 驱动_华为RH2288H V5服务器windows 2012阵列卡驱动
  5. webpy使用说明(二)
  6. 利用计算机制作多媒体作品目标,多媒体创作工具功能有什么特点
  7. 杂谈:电商平台中的图片资源优化实战
  8. 2021年中国电池电解液行业出货量及龙头企业对比分析:江苏国泰vs新宙邦vs天赐材料[图]
  9. Java多线程面经整理
  10. [MFC] CList