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表示这 ...
随机推荐
- ArcGIS Mobile 自定义图层在绘制面时节点未绘制完全的问题
ArcGIS Mobile 自定义图层在绘制面时节点未绘制完全,如下图: 面的绘制代码如下: public void Draw(Display dis, Pen p1, Pen p2,Pen p3 , ...
- oslab oranges 一个操作系统的实现 实验二 认识保护模式
https://github.com/yyu/osfs00 实验目的: 理解x86架构下的段式内存管理 掌握实模式和保护模式下段式寻址的组织方式. 关键数据结构.代码组织方式 掌握实模式与保护模式的切 ...
- 牛客网多校第3场 C-shuffle card 【splay伸展树】
题目链接:戳这里 转自:戳这里 关于splay入门:戳这里 题意:给n个数,进行m次操作,每次都从n个数中取出连续的数放在最前面. 解题思路:splay的区间操作. 附代码: 1 #include&l ...
- C++中overload 、override、overwrite 之间的区别
Overload(重载):在C++程序中,可以将语义.功能相似的几个函数用同一个名字表示,但参数或返回值不同(包括类型.顺序不同),即函数重载.(1)相同的范围(在同一个类中):(2)函数名字相同:( ...
- Leetcode(7)-反转整数
给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 注意: 假 ...
- php 文件包含base64读取文件 preg_replace函数
解题部分题目来源攻防世界web高手进阶区1.拿到题目以后,发现是一个index.php的页面,并且设备-没有显示完全,此位置可疑.2.源代码中发现?page=index,出现page这个get参数,联 ...
- github & coding 2018
github & coding 2018 github & coding all in one https://github.com/topics/javascript react r ...
- js 实现前端路由的方法
js 实现前端路由的方法 前端路由原理 History API https://developer.mozilla.org/en-US/docs/Web/API/History_API https:/ ...
- NGK公链依靠技术创新推动数字经济产业发展
数字经济更让人们的生活发生了翻天覆地的变化.数字经济的发展要依靠技术的创新,发展出生态新模式.同时数字经济的发展要利用新技术对传统产业进行全面的的改造升级,释放数字对经济发展的放大.倍增作用.打造数字 ...
- MacOS下PHP7.1升级到PHP7.4.15
最近写SDK的时候需要用到object类型提示符,PHPStorm智能提示说需要PHP7.2以上才能支持这种类型提示. 我一查我本机的PHP是7.1.30版本,于是考虑升级一下PHP版本. 首先要尝试 ...