构造模拟要分情况讨论感觉不是够本质,然后官解是因为只有四个量所以可以根据限制条件列两个方程,再枚举一下解就可以了。

const int maxn = 5000 + 5;
int n, c[maxn], a[maxn];
vector<int> zero, two, cl, ac, ans1, ans2; int main() {
cin >> n;
getchar();
rep(i, 1, n) {
char ch = getchar();
c[i] = ch - '0';
}
getchar();
rep(i, 1, n) {
char ch = getchar();
a[i] = ch - '0';
}
rep(i, 1, n) {
if (c[i] && a[i]) two.push_back(i);
else if (c[i]) cl.push_back(i);
else if (a[i]) ac.push_back(i);
else zero.push_back(i);
} for (int a = 0; a <= zero.size(); a++) {
int d = a - n / 2 + ac.size() + two.size();
if (d < 0 || d > two.size() || a + d > n / 2) continue;
int tmp = n / 2 - a - d;
for (int c = 0; c <= cl.size(); c++) {
if (tmp - c <= ac.size()) {
for (int i = 0; i < a; i++) cout << zero[i] << " ";
for (int i = 0; i < tmp - c; i++) cout << ac[i] << " ";
for (int i = 0; i < c; i++) cout << cl[i] << " ";
for (int i = 0; i < d; i++) cout << two[i] << " ";
return 0;
}
}
}
printf("-1\n");
return 0;
}

Codeforces 1138B(列方程枚举)的更多相关文章

  1. Codeforces 1138B Circus (构造方程+暴力)

    题意: 给你两个01串,要你选n/2个位置,使得选的位置在s1中"1"的数量等于未选的s2中"1"的数量 n<=5000,1s 思路: 设两个串中出现&q ...

  2. codeforces 895A Pizza Separation 枚举

    codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成0 ...

  3. Educational Codeforces Round 61 C 枚举 + 差分前缀和

    https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...

  4. Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)

    Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...

  5. CodeForces 617C【序枚举】

    题意: 有两个点喷水,有很多个点有花,给出坐标. 求使得每个花都可以被喷到,两个喷水的半径的平方的和最小是多少. 思路: 枚举其中一个喷水的最大半径. 坑: 这题我贪心的思路有很大问题.一开始也是想这 ...

  6. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  7. CodeForces 158DIce Sculptures(枚举)

    一个暴力的枚举,枚举组成正多边形需要对应覆盖原先的几条边,范围为(1,n/3),然后维护最大值就可以了,注意初始化为-inf. #include<stdio.h> #include< ...

  8. Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)

    The only difference between easy and hard versions is a number of elements in the array. You are giv ...

  9. The Golden Age CodeForces - 813B (数学+枚举)

    Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a  ...

随机推荐

  1. Linux下Redis C++操作的封装

    安装和启动Redis服务...略!很粗糙的版本,待改进... Redis Client C++示例代码...略! /** * Time: 14-3-10 * File: RedisCache.h * ...

  2. Android如何配置init.rc中的开机启动进程(service)【转】

    本文转载自:http://blog.csdn.net/qq_28899635/article/details/56289063 开篇:为什么写这篇文章 先说下我自己的情况,我是个普通的大四学生,之前在 ...

  3. opengl in medical imaging

    医学可视化 http://schorsch.efi.fh-nuernberg.de/roettger/index.php/Lectures/MedicalVisualization http://ww ...

  4. Java聊天室[长轮询]

    今天看到有人分享java实现的聊天室,想起很久以前还在热衷于java的时候也做过一个web聊天室,不拿出来晒晒,可能再也不为人知了,单纯是一个兴趣作品,稳定性不好,也没有考虑连接数和并发的问题,拿出来 ...

  5. typeof详解

    typeof operator 返回了表示对象类型的字符串 下表列出了typeof可能的返回值. Type Result Undefined "undefined" Null &q ...

  6. syslog格式

    转自:http://wly719.iteye.com/blog/1827394 1.syslog格式介绍 在Unix类操作系统上,syslog广泛 应用于系统日志.syslog日志消息既可以记录在本地 ...

  7. Chapter3——进入Android Dalvik虚拟机(二)

    Dalvik汇编语言基础 Dalvik虚拟机为自己设计了一套指令集,并制定了自己的指令格式和调用规范. 位描述约定如下: 每16位的字采用空格分隔开来 每个字母表示4位,每个字母按顺序从高字节开始,排 ...

  8. Android之styles.xml,以及自定义风格

    1.styles.xml 在现在的ADT创建的Project中,会有values,values-v11和values-v14三个文件夹,每个文件夹下都有一个styles.xml. API11是Andr ...

  9. Oracle中的关键字

    NVL和COALESCE的区别: nvl(COMMISSION_PCT,0)如果第一个参数为null,则返回第二个参数如果第一个参数为非null,则返回第一个参数 COALESCE(EXPR1,EXP ...

  10. 在浏览器上直接输入 http://www.bookEstore.com就可以访问工程问题

    关于在浏览器上直接输入 http://www.bookEstore.com就可以访问工程问题 1.在tomcat/conf/server.xml文件中配置一个虚拟主机 <Host name=&q ...