Codeforces 1138B(列方程枚举)
构造模拟要分情况讨论感觉不是够本质,然后官解是因为只有四个量所以可以根据限制条件列两个方程,再枚举一下解就可以了。
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(列方程枚举)的更多相关文章
- Codeforces 1138B Circus (构造方程+暴力)
题意: 给你两个01串,要你选n/2个位置,使得选的位置在s1中"1"的数量等于未选的s2中"1"的数量 n<=5000,1s 思路: 设两个串中出现&q ...
- codeforces 895A Pizza Separation 枚举
codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成0 ...
- Educational Codeforces Round 61 C 枚举 + 差分前缀和
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- CodeForces 617C【序枚举】
题意: 有两个点喷水,有很多个点有花,给出坐标. 求使得每个花都可以被喷到,两个喷水的半径的平方的和最小是多少. 思路: 枚举其中一个喷水的最大半径. 坑: 这题我贪心的思路有很大问题.一开始也是想这 ...
- codeforces 613B B. Skills(枚举+二分+贪心)
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- CodeForces 158DIce Sculptures(枚举)
一个暴力的枚举,枚举组成正多边形需要对应覆盖原先的几条边,范围为(1,n/3),然后维护最大值就可以了,注意初始化为-inf. #include<stdio.h> #include< ...
- 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 ...
- 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 ...
随机推荐
- 最简单ajax,$.post()用法
最简单的ajax,$.post()用法 $.post("action.php",{'email':$('#email').val(),'address':$('#address') ...
- source insight 快捷键
source insight 返回上一视图 快捷键:ALT+, 浏览项目符号:F7 全局浏览查找某个名称开头的函数或结构体等
- WPF-悬浮在底部的导航
先用Rectangle代替导航按钮,这个导航会悬浮在界面的底部,当鼠标移进导航按钮上的时候,按钮会放大,移出后恢复正常. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 ...
- bootstrap学习大纲
bootstrap 学习分三部分,分别是 css样式,css组件,js插件. 下面介绍三部分分别要学习的内容: 1.css样式:栅格系统,排版,代码,表格,表单,按钮,图片,辅助类,响应式工具. 2. ...
- w3C盒子模型和IE的盒子模型
W3C 盒子模型的范围包括 margin.border.padding.content,并且 content 部分不包含其他部分IE 盒子模型的范围也包括 margin.border.padding. ...
- 洛谷P4009汽车加油行驶问题——网络流24题(最短路)
题目:https://www.luogu.org/problemnew/show/P4009 网络流24题中不是网络流的最短路题: 把每个点拆成各个油量上的点,根据要求连边即可: 注意:点数最大为10 ...
- Azure ARM (22) Azure Policy入门
<Windows Azure Platform 系列文章目录> 我们知道,在Azure服务层级中,分为以下几个层次: 1.企业合同 2.订阅 3.资源组 4.资源 我们使用的Azure资源 ...
- android开发中怎么通过Log函数输出当前行号和当前函数名
public class Debug { public static int line(Exception e) { StackTraceElement[] trace = e.getStackTra ...
- 4.js屏蔽浏览器鼠标右键菜单
document.oncontextmenu = function(){return false;} 参考链接:js 屏蔽浏览器事件汇总
- OpenFileDialog无法弹出的解决方法
今天在写一个socket通信的winform小程序,由于socket的receive方法会阻塞线程,所以就使用了多线程解决.但在新建的线程中创建OpenFileDialog并调用其ShowDialog ...