【CS Round #48 (Div. 2 only)】8 Divisible
【链接】h在这里写链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std; string s;
int len, cnt[10], cnt1[10];
vector <string> v;
vector <int> v1; void back() {
for (int i = 0; i <= 9; i++) cnt[i] = cnt1[i];
} void sp() {
int start = 3 - len;
if (v1[start] == 0) return;//开头不能为0 for (int i = start; i <= 2; i++) {//只有后start位才有效.
cnt[v1[i]]--;//数字递减。
} for (int i = 0; i <= 9; i++)
if (cnt[i] != 0) {
back();
return;
} string ts = "";
for (int i = start; i <= 2; i++)
ts += (char)('0' + v1[i]); v.push_back(ts);
back();
} int main() {
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
cin >> s;
len = s.size();
for (int i = 0; i <= len - 1; i++) cnt[s[i] - '0']++;
v1.resize(3);
for (int i = 0; i <= 999; i += 8) {//枚举末3位是什么。肯定是8的倍数
for (int j = 0; j <= 9; j++) cnt1[j] = cnt[j];//每一位的数字有多少个。 int temp = i;
for (int j = 2; j >= 0; j--, temp /= 10) v1[j] = temp % 10;//把这3位全都获取出来。 if (len <= 3) {
sp();
continue;
} bool ok = true; for (int j = 0; j <= 2; j++) {
cnt[v1[j]]--;
if (cnt[v1[j]] < 0) ok = false;
} if (!ok) {
back();
continue;
} string ts = "";
ok = false;
for (int j = 1; j <= 9; j++)
if (cnt[j]) {
ts += (char)('0' + j);
cnt[j]--;
ok = true;
break;
}
if (!ok) {
back(); continue;
}
for (int j = 0; j <= 9; j++)
while (cnt[j] > 0) {
cnt[j]--;
ts += (char)('0' + j);
}
for (int j = 0; j <= 2; j++)
ts += (char)('0' + v1[j]);
v.push_back(ts);
back();
}
sort(v.begin(), v.end());
if (v.empty())
cout << -1 << endl;
else
cout << v[0] << endl;
return 0;
}
【CS Round #48 (Div. 2 only)】8 Divisible的更多相关文章
- 【CS Round #48 (Div. 2 only)】Dominant Free Sets
[链接]h在这里写链接 [题意] 让你在n个点组成的集合里面选取不为空的集合s. 使得这里面的点没有出现某个点a和b,ax>=bx且ay>=by; 问你s的个数. [题解] 我们把这些点按 ...
- 【CS Round #48 (Div. 2 only)】Water Volume
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举0在哪个位置就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> us ...
- 【CS Round #48 (Div. 2 only)】Game of Chance
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【CS Round #36 (Div. 2 only) A】Bicycle Rental
[题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...
- 【CS Round #37 (Div. 2 only) D】Reconstruct Graph
[Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...
- 【CS Round #37 (Div. 2 only) B】Group Split
[Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...
- 【CS Round #37 (Div. 2 only) A】Boring Number
[Link]:https://csacademy.com/contest/round-37/task/boring-number/ [Description] 让你找离平均数最近的一个数的下标; [S ...
- 【CS Round #39 (Div. 2 only) D】Seven-segment Display
[Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...
随机推荐
- (七十一)关于UITableView退出崩溃的问题和滚动究竟部的方法
[TableView退出崩溃的问题] 近期在使用TableView时偶然发如今TableView中数据较多时,假设在滚动过程中退出TableView到上一界面.会引起程序的崩溃.经过网上查阅和思考我发 ...
- cmake 常见问题及解决
1. undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5 未定义对某符号的引用,该错误为链接时(linking)发生的错误.有 ...
- Elasticsearch之marvel(集群管理、监控)插件安装之后的浏览详解
前提 Elasticsearch之插件介绍及安装 https://i.cnblogs.com/posts?categoryid=950999&page=2 (强烈建议,从头开始看) 比如,我 ...
- 几个不错的开源的.net界面控件
转自原文 几个不错的开源的.net界面控件 (转) 几个不错的开源的.net界面控件 - zt 介绍几个自己觉得不错的几个开源的.net界面控件,不知道是否有人介绍过. DockPanel Suite ...
- 怎样使用 OneAPM 监控微软 Azure Cloud Service ?
不知不觉微软 Azure 已经进入中国市场近两年的时间.那么 Azure 平台的性能到底怎样?资源载入的延迟.虚拟机的稳定性等问题是否切实满足客户期许.这些都是大家对微软 Azure 这个国外的云服务 ...
- GridView-属性大全
这是个网格控件 他的实现也是通过adapter来实现的,感觉跟listview在使用上并没有多大的区别 常见属性如下 1.android:numColumns=”auto_fit” //GridVie ...
- 31.Node.js 常用工具 util
转自:http://www.runoob.com/nodejs/nodejs-module-system.html util 是一个Node.js 核心模块,提供常用函数的集合,用于弥补核心JavaS ...
- HTML5手机应用的最大优势就是可以在网页上直接调试和修改
HTML5手机应用的最大优势就是可以在网页上直接调试和修改
- Navicat for MySQL 新建查询时,报can't create file ...系统找不到指定的文件夹出现问题
如图点击新建查询报错 解决办法 将这个路径修改一下就ok了
- 记Bootstrap Table两种渲染方式
这里主要区别两种Bootstrap Table的数据渲染方式,一.属性渲染方式,二.JS渲染方式 工作直接接手前人的,之前都直接在table标签上渲染属性,后面因为项目需要,同一页面的表格,需要申请不 ...