A. Subsequence Permutation

题意:

给定一个字符串,选择任意数量的字符调整位置,使得调整位置之后整个序列是从小到大的,要求调整的位置数量最小

输入

4
3
lol
10
codeforces
5
aaaaa
4
dcba

输出

2
6
0
4

思路

这个没什么好说的,定义一个字符串,从小到大排序之后判断是不是和原位置的字符相等就可,另外注意不要用之前的位置和当前的位置比较

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>using namespace std;typedef long long ll;
#define SSS                       \ios_base::sync_with_stdio(0); \cin.tie(0);                   \cout.tie(0);#define rep(i, a, b) for (int i = (a), i <= (b); i++)
#define per(i, a, b) for (int i = (a), i >= (b); i--)
#define pii pair<int, int>
#define pdd pair<double, double>
const int N = 1e5 + 10;
const int mod = 1e9 + 7;int main()
{SSS;int t;cin >> t;while (t--){int n;string s;cin >> n;cin >> s;string s1 = s;int cnt = 0;sort(s1.begin(), s1.end());for (int i = 0; i < s.size(); i++){if (s[i] != s1[i]){cnt++;}}cout << cnt << endl;}return 0;
}

B - Running for Gold

题意:

有n个选手要参加马拉松比赛,并且每个马拉松选手以前都参加过5场比赛,如果存在一个选手,在任意三场比赛中都比另一个选手的成绩好,那么这个选手就强,如果有选手比其他所有的选手都强,那么就认为这个选手可以在本次马拉松比赛中拿第一,求是否存在这样的选手,存在输出这个选手的下标,否则输出-1

输入

4
1
50000 1 50000 50000 50000
3
10 10 20 30 30
20 20 30 10 10
30 30 10 20 20
3
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
6
9 5 3 7 1
7 4 1 6 8
5 6 7 3 2
6 7 8 8 6
4 2 2 4 5
8 3 6 9 4

输出

1
-1
1
5

思路

这题n<=50000, t<=1000,所以得想一个O(n)的做法,可以转换成打擂台的题,假设有选手A和B,A如果在任意三场比赛中强于B,那么B就必不可能是第一,那么我们可以按照这样模拟一个擂台,首先A上场,和B打,A或者B赢了的留下,作为当前的最强者继续和C打,那么到最后必定有一个人留下,这个人前面的必定都是被打下去的,这个人之后的都是被他打过的,然后对于这样的一个最强者,我们对他之前的选手进行遍历,寻找是否有比他强的,因为前面的人是被别人打下的,他自己不一定可以打下,如果存在这样的选手,就说明不存在可以拿第一的,否则输出当前选手下标

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>using namespace std;typedef long long ll;
#define SSS                       \ios_base::sync_with_stdio(0); \cin.tie(0);                   \cout.tie(0);
#define rep(i, a, b) for (int i = (a), i <= (b); i++)
#define per(i, a, b) for (int i = (a), i >= (b); i--)
#define pii pair<int, int>
#define pdd pair<double, double>
const int N = 5e4 + 10;
const int mod = 1e9 + 7;int r[10][N];
int main()
{SSS;int t;cin >> t;while (t--){int n;cin >> n;for (int i = 1; i <= n; i++){for (int j = 1; j <= 5; j++){cin >> r[j][i];}}int ans = 1; // 当前的最强者for (int i = 2; i <= n; i++){int cnt = 0;for (int j = 1; j <= 5; j++){if (r[j][ans] > r[j][i]){cnt++;}} // 如果有选手三项比赛的成绩大于当前的最强者就更新if (cnt >= 3){ans = i;}}int flag = 1; // 之后在遍历一遍,强者鉴定for (int i = 1; i <= n; i++){int cnt = 0;for (int j = 1; j <= 5; j++){if (r[j][ans] > r[j][i]){cnt++;}if (cnt >= 3){flag = 0;break;}}}if (flag){cout << ans << endl;}else{cout << -1 << endl;}}return 0;
}

C - Maximize the Intersections

题意:

大概就是有2n个点,给你k条已经连起来的边,求如果把剩下没连起来的边连起来,那么最终所有相交线的交点最多有多少个(没太看懂,但是按我理解是这么个意思)

输入

4
4 2
8 2
1 5
1 1
2 1
2 0
10 6
14 6
2 20
9 10
13 18
15 12
11 7

输出

4
0
1
14

思路:

如果我们想要交点最多,那么就要让每队点的小点尽可能的小,另一个大点要大于尽可能多的小点,然后看下图(其实自己画一画就出来了)


从cf题解里面扣的图,可以看出ad和bc连是最优的,得出一个结论,假设有2n个点要连,那么最优解是1 – n+1, 2 – n+2 , … , n-1 – 2n

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>using namespace std;typedef long long ll;
#define SSS                       \ios_base::sync_with_stdio(0); \cin.tie(0);                   \cout.tie(0);#define rb(i, a, b) for (int i = (a), i <= (b); i++)
#define re(i, a, b) for (int i = (a), i >= (b); i--)
#define pii pair<int, int>
const int N = 110;
const int mod = 1e9 + 7;pii a[N];
int used[500];
int main()
{SSS;int t;cin >> t;while (t--){int n, k;cin >> n >> k;n = n * 2;for (int i = 1; i <= n; i++){used[i] = i;a[i].first = 0;a[i].second = 0;}for (int i = 1; i <= k; i++){cin >> a[i].first >> a[i].second;if (a[i].first > a[i].second){int temp = a[i].first;a[i].first = a[i].second;a[i].second = temp;}used[a[i].first] = 1000;used[a[i].second] = 1000;}sort(used + 1, used + n + 1);// for (int i = 1; i <= n; i++)// {//     cout << used[i] << " ";// }int mid = (n - k * 2) / 2;// cout << mid << endl;for (int i = k + 1; i <= k + mid; i++){a[i].first = used[i - k];a[i].second = used[mid + i - k];}sort(a + 1, a + n / 2 + 1);// cout << endl;// for (int i = 1; i <= n / 2; i++)// {//     cout << a[i].first << " " << a[i].second << endl;// }// cout << endl;int cnt = 0;for (int i = 1; i <= n/2-1; i++){for (int j = i + 1; a[j].first < a[i].second && j <=n/2; j++){if (a[j].second > a[i].second){cnt++;// cout << endl;// cout << i << " " << j << endl;// cout << a[i].first << " " << a[i].second << endl;// cout << a[j].first << " " << a[j].second << endl;// cout << endl;}}}cout << cnt << endl;}return 0;
}

D. Array Differentiation

题意

给定一个序列a,是否存在一个序列b,对于任意一个a,都有ai = bj + bk

输入

5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258

输出

YES
YES
NO
YES
YES

思路

对于序列a和b,我们可以首先求出序列a的所有子集,若序列a的所有子集存在重复的,那么就势必存在一种序列b使得序列a成立

假设序列a的子集有c[i],c[j],c[k],c[l],若c[j] = c[k],则c[j]和c[k]对应的集合可视作一个集合,即序列a至少会少一个数,而一个数量为n的序列是可以被n+1个对应序列所表示的,比如a序列1 2 3 4 5对应的b序列可以为0 1 2 3 4 5,而少一个数则说明对应的序列也可以-1,即至多可以用n个数来表示,所以条件成立

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>using namespace std;typedef long long ll;
#define SSS                       \ios_base::sync_with_stdio(0); \cin.tie(0);                   \cout.tie(0);
#define caseT \int t;    \cin >> t; \while (t--)
#define rep(i, a, b) for (int i = (a), i <= (b); i++)
#define per(i, a, b) for (int i = (a), i >= (b); i--)
#define pii pair<int, int>
#define pdd pair<double, double>
const int N = 100 + 10;
const int mod = 1e9 + 7;int gcd(int a, int b)
{return b == 0 ? a : gcd(b, a % b);
}int lcm(int a, int b)
{return a * b / gcd(a, b);
}int lowbit(int x)
{return x & -x;
}
int a[N], b[N];int main()
{SSS;int t;cin >> t;while (t--){int n;map<int, int> mp;cin >> n;for (int i = 0; i < n; i++){cin >> a[i];}for (int i = 0; i < (1 << n); i++){int sum = 0;for (int j = 0; j < n; j++){if (i & (1 << j))sum += a[j];}mp[sum]++;}// for (auto i = mp.begin(); i != mp.end(); i++)// {//     cout << i->first << " ";// }// cout << endl;// cout << mp.size() << " " << (1 << n) << endl;if (mp.size() != (1 << n)){puts("YES");}else{puts("NO");}}return 0;
}

Codeforces Global Round 15 ABCD相关推荐

  1. Codeforces Global Round 11 ABCD题解

    真阴间啊 , 不仅时长阴间, 题目也有点emmmmm 打的不顺利,没有按预想在15分钟内把AB题写出来 ((。・∀・)ノ゙害) 开局码了发A WA2 人傻了 开始质疑自己了 先搁着吧 然后又码了一个半 ...

  2. Codeforces Global Round 15 (A-D)没有C

    A 太简单,写完删了 B 我写的繁了,但是意思是这么个意思,就遍历打擂台一样,找到最后的胜者,然后在遍历一遍找是不是最厉害的 #include <bits/stdc++.h> using ...

  3. Codeforces Global Round 1 晕阙记

    Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...

  4. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  5. Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集

    传送门 文章目录 题意: 思路: 题意: 给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai​,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau​+av​≥x ...

  6. Codeforces Global Round 1

    Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...

  7. 【Codeforces Global Round 23】B. Rebellion

    Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...

  8. Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)

    题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...

  9. codeforces global round 23

    constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...

最新文章

  1. eclipse——jsp字体设置
  2. [YTU]_2627 (职工工资统计)
  3. JavaScript DOM 向文档添加新的元素
  4. 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys
  5. 服务器缺少storportSYS文件,Windows操作系统蓝屏日志分析方法
  6. python获取小王的ip地址_用Python获取本机的IP地址
  7. 查看计算机本机IP地址,本机ip地址查询
  8. 思科 Spanning Tree Protocol(STP)生成树
  9. 七分之一在线评论都有假,人工智能救一把?
  10. java两周考核期被辞退_试用期被辞退,会影响一整年,或整个职场生涯
  11. mongodb添加多条数据_mongodb一次能插入多少数据
  12. 启辰r30近光灯远光灯保险盒,近光灯故障处理
  13. 计算机操作系统重装,手把手教你电脑怎样重装系统
  14. 第六章 网络学习相关技巧1(最优路径梯度)
  15. 富勒烯|Fullerene C60 富勒石 CAS:131159-39-2 |瑞禧
  16. Amdahl定律(最直观理解)
  17. Hessian矩阵\海塞矩阵\海森矩阵
  18. QQ音乐7.0换新上线: 轻简风带来全新听歌体验
  19. JAVA 基础学习第一天
  20. MES上线的实施流程

热门文章

  1. 青藤《关键信息基础设施增强保护安全实践》论文入选中国科技核心期刊
  2. 历数马化腾早年的赚钱经历。
  3. 概率,递推,找规律,高精度(FXTZ II,hdu 4043)
  4. uniapp开发小程序使用腾讯云IM(初始化配置,登录,监听,加群)
  5. 用批处理自动设置IE代理
  6. [Java进阶]学习笔记2:毫秒值的概念和作用
  7. 12件可能改变未来大事:人造生命到致命病毒
  8. tty线路规程(discipline)设置
  9. 获取枚举常量的描述值Description
  10. 解决浏览器滚动条导致的页面闪烁问题