Codeforces Round #620 (Div. 2) (A~D)
比赛链接:Here
A题挺水的就不写了
1304B - Longest Palindrome
题意:
- 输入 \(m\) 个长度为 \(n\) 的字符串,问这些字符串能组成的最长回文串有多长。
思路:
- 贪心的思想,我们只需要用当前字符串以及寻找该字符串的反向串是否存在,如果存在的话,就把该字符串与它的反向串添加进答案串的首尾。
- 注意中间的那个字符串,如果我们输入的字符串中有回文串,且该串的反向串也不存在的话,可以把该串单独放在答案串的中间。
string s[110];
map<string, int>mp;
bool check(string s) {
int n = s.size();
for (int i = 0, j = n - 1; i <= n / 2; ++i, j--)
if (s[i] != s[j]) return 0;
return 1;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m; cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> s[i], mp[s[i]] = 1;
string ans, z, t;
bool f = 0;
for (int i = 0; i < n; ++i) {
if (check(s[i])) z = s[i], f = 1;
else {
reverse(s[i].begin(), s[i].end());
string tmp = s[i];
reverse(s[i].begin(), s[i].end());
if (mp[tmp] == 1) {
t += tmp;
mp[tmp] = 0;
}
}
mp[s[i]] = 0;
}
ans += t;
reverse(t.begin(), t.end());
if (f) ans += z;
ans += t;
cout << int(ans.size()) << "\n";
if (int(ans.size()))cout << ans << "\n";
}
1304C - Air Conditioner
题意:
- 输入 \(n\),再输入 \(n\) 个顾客的信息,分别为客人来的时间,客人需要的温度范围,每分钟可以进行一次三种操作之一:升温,降温和不变。问能否满足所有客人的需求。
思路:
一开始写复杂了,这道题本质就是暴力模拟,要满足所有客人的需求,那么就用当前客人与下一个客人的时间差来取温度的最大(r)和最小值(l),当下一个客人来时再判断这个客人的需求是否在这个[l,r]之内。
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
ll n, m;
cin >> n >> m;
ll t = 0, l = m, r = m;
bool f = 1;
while (n--) {
ll ti, x, y;
cin >> ti >> x >> y;
l = l - (ti - t), r = r + (ti - t);
t = ti;
l = max(l, x), r = min(r, y);
if (l > r) f = 0;
}
cout << (f ? "YES\n" : "NO\n");
}
}
1304D - Shortest and Longest LIS
题意:
- 给定一个 \(n\) ,与构造规则,要求构造出符合构造规则的LIS最小和最大的串
思路:
原本想试试DP,写状态转移发现最短序列的话,对于一串大于号,我们把当前未使用过的比较大的数尽可能的放在左边。最长序列就是反过来,尽可能的放未使用过的小的数放在左边即可
简单来说就是贪心
const int N = 2e5 + 10;
ll a[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n; string s;
cin >> n >> s;
int nn = n, lst = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '>' || i == n - 1) {
for (int j = i; j >= lst; j--)a[j] = nn--;
lst = i + 1;
}
}
for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
nn = 1, lst = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '<' || i == n - 1) {
for (int j = i; j >= lst; j--) a[j] = nn++;
lst = i + 1;
}
}
for (int i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1];
}
}
E,F不会做....明明挺多人都过了QAQ
Codeforces Round #620 (Div. 2) (A~D)的更多相关文章
- Codeforces Round #316 (Div. 2) (ABC题)
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...
- Codeforces Round #240 (Div. 2)(A -- D)
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- Codeforces Round #395 (Div. 2)(未完)
2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...
- B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...
- 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)
题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #671 (Div. 2) (A~E)
Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...
- Codeforces Round #620 (Div. 2)
Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳 ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
随机推荐
- BS页面设计 | 寻梦环游记电影介绍
- Maven安装与配置【idea2022版本】
一.maven下载 https://maven.apache.org/download.cgi 下载完毕后解压,注意解压路径不要有中文 二.环境变量 在环境变量Path里面新建(自己的maven的bi ...
- 自研、好用的ORM 读写分离功能使用
Fast Framework 作者 Mr-zhong 代码改变世界.... 一.前言 Fast Framework 基于NET6.0 封装的轻量级 ORM 框架 支持多种数据库 SqlServer O ...
- [AGC59C] Guessing Permutation for as Long as Possible
Problem Statement A teacher has a hidden permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\cdots,N)$. Y ...
- 34. 干货系列从零用Rust编写负载均衡及代理,异步测试在Rust中的实现
wmproxy wmproxy已用Rust实现http/https代理, socks5代理, 反向代理, 静态文件服务器,四层TCP/UDP转发,七层负载均衡,内网穿透,后续将实现websocket代 ...
- lower_bound() upper_bound()函数
转自http://blog.csdn.net/niushuai666/article/details/6734403 函数lower_bound()在first和last中的前闭后开区间进行二分查找, ...
- postman——下载与安装
一.postman是什么? 那么,Postman是个什么东东呢?Postman的官网上这么介绍它:"Modern software is built on APIs,Postman help ...
- shell中 << EOF 和 EOF 使用
转载请注明出处: EOF(End of File)在Shell中通常用于指示输入的结束,并在脚本或命令中进行多行输入.它允许用户指定一个特定的分界符来表示输入的结束,通常用于创建临时文件.重定向输入或 ...
- R6900 R7000刷梅林 AImesh组网
本文作者: Colin本文链接: https://www.colinjiang.com/archives/netgear-r6900-flash-merlin-rom.html 然后开始讲正题,刷梅林 ...
- springboot整合hibernate(非JPA)(一)
springboot整合hibernate(非JPA)(一) springboot整合hibernate,非jpa,若是jpa就简单了,但是公司项目只有hibernate,并要求支持多数据库,因此记录 ...