Codeforces Round #545 B. Circus
题面:
题目描述:
- 每个人只能在其中一组
- 两个组的人数相等(也就是把这些人分半)
- 在第一个组会扮演小丑的人的数量,等于在第二个组会表演杂技的数量
题目分析:
1.只会扮演小丑的人2.只会表演杂技的人3.既会扮演小丑,又会表演杂技的人4.什么都不会的人
第一种人:only_c第二种人:only_a第三种人:both_ca第四种人:not_ca
第一种人:c_num第二种人:a_num第三种人:b_num第四种人:n_num
c_num + a_num + b_num + n_num == n / 2 (第一组人的数量)c_num + b_num == (only_a - a_num) + (both_ca - b_num) (第一个组会扮演小丑的人的数量,等于第二个组会表演杂技的数量)
c_num = c_numa_num = only_a + both_ca - 2 * b_num - c_numb_num = b_numn_num = n / 2 - only_a - both_ca + b_num
1 #include <bits/stdc++.h>
2 using namespace std;
3 char clo[5005], acr[5005];
4 int type[5005];
5 int n;
6 int only_c, only_a, both_ca, not_ca;
7
8 bool in(int x, int l, int r){
9 if(l <= x && x <= r) return true;
10 return false;
11 }
12
13 int main(){
14 scanf("%d", &n);
15 scanf("%s%s", clo, acr);
16
17 for(int i = 0; i < n; i++){
18 if(clo[i] == '1' && acr[i] == '0') only_c++, type[i] = 1;
19 if(clo[i] == '0' && acr[i] == '1') only_a++, type[i] = 2;
20 if(clo[i] == '1' && acr[i] == '1') both_ca++, type[i] = 3;
21 if(clo[i] == '0' && acr[i] == '0') not_ca++, type[i] = 4;
22 }
23
24 int c_num, a_num, b_num, n_num;
25 int sus = 0;
26 for(c_num = 0; c_num <= only_c; c_num++){
27 for(b_num = 0; b_num <= both_ca; b_num++){
28 a_num = only_a + both_ca - 2 * b_num - c_num;
29 n_num = n / 2 - only_a - both_ca + b_num;
30 if(in(a_num, 0, only_a) && in(n_num, 0, not_ca)){
31 sus = 1;
32 break;
33 }
34 }
35 if(sus) break;
36 }
37
38 if(sus == 0) {
39 printf("-1");
40 return 0;
41 }
42
43 int c_cnt, a_cnt, b_cnt, n_cnt;
44 c_cnt = a_cnt = b_cnt = n_cnt = 0;
45 for(int i = 0; i < n; i++){
46 sus = 0;
47 if(type[i] == 1 && c_cnt < c_num)
48 c_cnt++, sus = 1;
49 if(type[i] == 2 && a_cnt < a_num)
50 a_cnt++, sus = 1;
51 if(type[i] == 3 && b_cnt < b_num)
52 b_cnt++, sus = 1;
53 if(type[i] == 4 && n_cnt < n_num)
54 n_cnt++, sus = 1;
55
56 if(sus) printf("%d ", i+1);
57 }
58 return 0;
59 }
不行,这个写的太丑,再继续写:
1 #include <bits/stdc++.h>
2 using namespace std;
3 char c[5005], a[5005];
4 int only_c, only_a, both_ca, not_ca;
5 int st[10][5005]; //栈?
6 int num[10]; //存n_num(num[0]),a_num(num[1]),c_num(num[2]),b_num(num[3])
7 int n;
8
9 bool in(int x, int l, int r){
10 if(l <= x && x <= r) return true;
11 return false;
12 }
13
14 int main(){
15 scanf("%d", &n);
16 scanf("%s%s", c+1, a+1);
17 for(int i = 1; i <= n; i++){
18 //预处理一下
19 c[i] -= '0', a[i] -= '0';
20 }
21
22 int t;
23 for(int i = 1; i <= n; i++){
24 t = c[i]*2 + a[i]; //二进制思想??
25 if(t == 0) st[t][not_ca++] = i;
26 if(t == 1) st[t][only_a++] = i;
27 if(t == 2) st[t][only_c++] = i;
28 if(t == 3) st[t][both_ca++] = i;
29 }
30
31 int sus = 0;
32 for(num[2] = 0; num[2] <= only_c; num[2]++){
33 for(num[3] = 0; num[3] <= both_ca; num[3]++){
34 num[1] = only_a + both_ca - 2*num[3] - num[2];
35 num[0] = n/2 - (num[1]+num[2]+num[3]); //算出num[1]后可以直接这样算num[0]
36 if(in(num[0], 0, not_ca) && in(num[1], 0, only_a)){
37 sus = 1;
38 break;
39 }
40 }
41 if(sus) break;
42 }
43
44 //找不到解
45 if(sus == 0) {
46 printf("-1");
47 return 0;
48 }
49
50 //输出答案
51 for(int i = 0; i < 4; i++){
52 for(int j = 0; j < num[i]; j++){
53 printf("%d ", st[i][j]);
54 }
55 }
56 return 0;
57 }
Codeforces Round #545 B. Circus的更多相关文章
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
- Codeforces Round #545 (Div. 1) 简要题解
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...
- Codeforces Round #545 (Div. 2)(B. Circus)
题目链接:http://codeforces.com/contest/1138/problem/B 题目大意:贼绕口的题目,就是给你两个字符串s1,s2,然后每一个人代表一列,第一列代表技能一每个人是 ...
- CodeForces Round #545 Div.2
A. Sushi for Two 代码: #include <bits/stdc++.h> using namespace std; ; ; int a[maxn], vis[maxn]; ...
- Codeforces Round #545 (Div. 2) D 贪心 + kmp
https://codeforces.com/contest/1138/problem/D 题意 两个01串s和t,s中字符能相互交换,问最多能得到多少个(可交叉)的t 题解 即将s中的01塞进t中, ...
- Codeforces Round #545 (Div. 2) D
链接:http://codeforces.com/contest/1138/problem/D 啊啊啊啊啊啊,自闭啊,比赛的时候判断条件 if(s1[i-1]=='0') aa++;写成了 if(s1 ...
- Codeforces Round #545 (Div. 2)(D. Camp Schedule)
题目链接:http://codeforces.com/contest/1138/problem/D 题目大意:给你两个字符串s1和s2(只包含0和1),对于s1中,你可以调换任意两个字符的位置.问你最 ...
- Codeforces Round #545 (Div. 2) 题解
题目链接 A. Sushi for Two 题意 在一个 01 序列中找出长为偶数的连续的一段使得它前一半和后一半内部分别相同,而前一半和后一半不同. \(2\le n\le 100\ 000\) 题 ...
- Codeforces Round #545 (Div. 2) E 强连通块 + dag上求最大路径 + 将状态看成点建图
https://codeforces.com/contest/1138/problem/E 题意 有n个城市(1e5),有m条单向边(1e5),每一周有d天(50),对于每个城市假如在某一天为1表示这 ...
随机推荐
- VS2010下如何查看类的内存布局
用VS2010查看类的内存布局,这里用两种方法 (1)MSVC有个隐藏的"/d1"开关,通过这个开关可以查看项目中类的内存布局情况. 修改项目属性,添加"/d1 repo ...
- JavaScript事件:事件处理模型(冒泡、捕获)、取消冒泡、阻止默认事件
(一)事件处理模型---事件冒泡.捕获 (1)事件冒泡 24 <body> 25 <div class="warpper"> 26 <div clas ...
- 洛谷p1637 三元上升子序列(树状数组
题目描述 Erwin最近对一种叫"thair"的东西巨感兴趣... 在含有n个整数的序列a1,a2......an中, 三个数被称作"thair"当且仅当i&l ...
- 5种设置ASP.NET Core应用程序URL的方法
默认情况下,ASP.NET Core应用程序监听以下URL: http://localhost:5000 https://localhost:5001 在这篇文章中,我展示了5种不同的方式来更改您的应 ...
- 机器学习(四):通俗理解支持向量机SVM及代码实践
上一篇文章我们介绍了使用逻辑回归来处理分类问题,本文我们讲一个更强大的分类模型.本文依旧侧重代码实践,你会发现我们解决问题的手段越来越丰富,问题处理起来越来越简单. 支持向量机(Support Vec ...
- rename github
rename GitHub github repo rename xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- style element & web components
style element & web components style.textContent style.setContent bug style.textContent const st ...
- bob and brad physical therapy knee exercise
bob and brad physical therapy knee exercise 鲍勃和布拉德物理治疗膝关节运动 https://bobandbrad.com/ youtube https:// ...
- The Filesystem Hierarchy Standard of Linux
The Filesystem Hierarchy Standard of Linux linux directory https://zhuanlan.zhihu.com/p/23862856 htt ...
- Mila Fletcher:日常理财应注意的五点
米拉·弗莱彻于2007年毕业于耶鲁大学,她是一名真正意义上的法学博士,在校期间获得了马歇尔奖学金,毕业后曾在美国多家知名律师事务所任职,目前就职于星盟全球投资公司,专注于帮助公司和客户提供法务咨询,他 ...