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

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. 深入浅出剖析C语言函数指针与回调函数(一)【转】

    本文转载自:http://blog.csdn.net/morixinguan/article/details/65494239 关于静态库和动态库的使用和制作方法. http://blog.csdn. ...

  2. Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举

    题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seco ...

  3. c/c++通用内存泄漏检测框架GMFD(General Memory Fault Detection Framework)

    http://qa.baidu.com/blog/?p=171 1 背景: x86平台有完善的用户态检测内存工具比如valgrind等,可以监控程序运行中详细的内存信息,从而精确定位内存问题.然而随着 ...

  4. codeforces 702D D. Road to Post Office(数学)

    题目链接: D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input ...

  5. 组合优化学习笔记<之>从贪心算法到子集系统再到拟阵

    贪心算法是用的比较多的一种优化算法,因为它过程简洁优美,而且结果有效.有些优化问题如最大权森林(MWF)是可以用贪心问题求解的,由于最小支撑树(MST)问题与MWF是等价的,所以MST也是可以用贪心算 ...

  6. mysql 数据库电脑间迁移

    应用实例: database1(简称DB1)保存在PC1中的MySQL中,需要将DB1迁移到PC2中的MySQL中 环境: win7 MySQL5.7.13 参考: http://stackoverf ...

  7. HihoCoder1576 子树中的最小权值( dfs序 +线段树 || 树剖)

    给定一棵N个节点的树,编号1~N.其中1号节点是根,并且第i个节点的权值是Vi. 针对这棵树,小Hi会询问小Ho一系列问题.每次小Hi会指定一个节点x,询问小Ho以x为根的子树中,最小的权值是多少.为 ...

  8. camera调试命令

    问题:adb install -r Camera.apk 2864 KB/s (7603465 bytes in 2.592s)Failure [INSTALL_FAILED_UPDATE_INCOM ...

  9. SIM卡(单卡)配置

    SIM卡相关配置 1.GPIO90--->BPI8 GPIO91--->BPI9 GPIO92--->BPI10 2.ProjectConfig.mk:MTK_PROTOCOL1_R ...

  10. css3 实现瀑布流

    掌握点: 1.column-count 把div中的文本分为多少列 2.column-width 规定列宽 3.column-gap 规定列间隙 4.break-inside: avoid; 避免元素 ...