【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各自有一个数字, ...
随机推荐
- 洛谷 P2309 loidc,卖卖萌
P2309 loidc,卖卖萌 题目背景 Loidc萌萌哒. 他最近一直在靠卖萌追求他的真爱——vivym,经过几轮攻势后vivym酱眼看就要被他所攻略.擅长数据结构的vivym决定利用强大的数据结构 ...
- CHROME开发者工具的小技巧
我猜不能转载,但是必须分享. http://coolshell.cn/articles/17634.html
- Sparse Autoencoder(二)
Gradient checking and advanced optimization In this section, we describe a method for numerically ch ...
- 解决Not allowed to load local resource
在做视频上传的时候,发现Not allowed to load local resource,也弄了很久,怕自己忘记了所以记下来 bind: function() { SelectVideo.on(& ...
- kali之Nmap (Network Mapper(网络映射器)
Nmap是主机扫描工具,他的图形化界面是Zenmap,分布式框架为Dnamp. Nmap可以完成以下任务: 主机探测 端口扫描 版本检测 系统检测 支持探测脚本的编写 Nmap在实际中应用场合如下: ...
- javascript 获取HTML DOM父,子,临近节点
在Web应用程序特别是Web2.0程序开发中.常常要获取页面中某个元素,然后更新该元素的样式.内容等.怎样获取要更新的元素,是首先要解决的问题.令人欣慰的是,使用JavaScript获取节点的方法有非 ...
- 源代码编译安装CloudStack 4.2
基于CentOS 6.4安装CloudStack 环境配置 # yum -y update # yum -y upgrade 安装NTP,jdk 1.7, tomcat 6, mysql,git等服务 ...
- javafx image button
public class EffectTest extends Application { public static void main(String[] args) { launch(args); ...
- Codeforces Round #194 (Div. 2) 部分题解
http://codeforces.com/contest/334 A题意:1-n^2 平均分成 n 份,每份n个数,且和相同 解法 : 构造矩阵1-n^2的矩阵即可 ][]; int main() ...
- Codeforces 451 E. Devu and Flowers(组合数学,数论,容斥原理)
传送门 解题思路: 假如只有 s 束花束并且不考虑 f ,那么根据隔板法的可重复的情况时,这里的答案就是 假如说只有一个 f 受到限制,其不合法时一定是取了超过 f 的花束 那么根据组合数,我们仍然可 ...