Codeforces 401C Team(贪心+暴力)
来源:互联网 发布:淘宝二手进口功放 编辑:程序博客网 时间:2024/04/25 22:11
题目链接:Codeforces 401C Team
题目大意:有n个0和m个1,要求将这些0和1排成一列,保证不会有两个0相邻,不会有连续的三个1,输出方案,不能满足的话输出-1.
解题思路:肯定能确定的是,1最少要分成n-1份,最多分成n+1份,三种情况统统考虑一下即可,注意细节。
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int n, m;inline bool judge (int k) {if (k == 0) return false;int x = m/k;return x == 1 || (x == 2 && m%k == 0);}void put(int x, int y, int k) {for (int i = 0; i < k; i++) {for (int j = 0; j < x; j++) printf("1");if (i < y) printf("1");printf("0");}}void solve (int k) {int x = m/k, y = m%k;if (k < n) {printf("0");put(x, y, k);} else if (k == n) {put(x, y, k);} else {put(x, y, k-1);for (int i = 0; i < x; i++) printf("1");}printf("\n");}int main () {bool flag = true;scanf("%d%d", &n, &m);for (int i = n-1; i <= n+1; i++) if (judge(i)) {solve (i);flag = false;break;}if (flag) printf("-1\n");return 0;}
0 0
- Codeforces 401C Team(贪心+暴力)
- Codeforces 401C Team 贪心法
- codeforces 401C - Team
- CodeForces 401C Team
- Codeforces-401C-Team
- Codeforces Team Olympiad(暴力)
- Codeforces 526C - Om Nom and Candies(贪心,暴力)
- !codeforces 399C Cards-数论&贪心-(暴力枚举)
- Codeforces 665C Simple Strings【暴力,贪心】
- 暴力 + 贪心 --- Codeforces 558C : Amr and Chemistry
- CodeForces 723C Polycarp at the Radio (贪心+暴力)
- Codeforces Round #279 (Div. 2)---A. Team Olympiad (贪心)
- codeforces C. Team
- Educational Codeforces Round 27 A B 暴力+贪心 C 贪心+排序
- codeforces 519C A and B and Team Training 解题报告 贪心
- CodeForces 508C (贪心)
- Codeforces 805C (贪心)
- CodeForces 478C (贪心)
- NYOJ 116 士兵杀敌 二
- 二进制中1的个数
- dwr与weblogic报错问题
- dundas chart
- [Linux]如何在vim保存时获得sudo权限
- Codeforces 401C Team(贪心+暴力)
- 2013级C++第17周项目【项目2-用指针玩字符串】之字符串比较大小
- ASP.NET中读取Excel内容,并显示在界面上
- eclipse中安装tomcat插件
- jdk和tomcat7的配置方法
- 10055 - Hashmat the Brave Warrior
- hadoop-0.20.2开发环境搭建
- Android Layout各种布局
- 移植tinyproxy http代理服务器