https://scut.online/p/31

还是不知道为什么RE了。的确非常玄学。

重构之后就没问题了。果然写的越复杂,分的情况越乱就越容易找不到bug。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int cnt[15];
int cnt2[15]; bool dfs(int x, int rest, bool dui) {
if(rest == 0)
return true;
if(cnt2[x] == 0)
return dfs(x + 1, rest, dui);
if(cnt2[x] == 1) {
if(x <= 7 && cnt2[x + 1] >= 1 && cnt2[x + 2] >= 1) {
cnt2[x]--, cnt2[x + 1]--, cnt2[x + 2]--;
if(dfs(x + 1, rest - 3, dui))
return true;
cnt2[x + 2]++, cnt2[x + 1]++, cnt2[x]++;
}
return false;
}
if(cnt2[x] == 2) {
if(!dui) {
cnt2[x] -= 2;
if(dfs(x + 1, rest - 2, true))
return true;
cnt2[x] += 2;
}
if(x <= 7 && cnt2[x + 1] >= 2 && cnt2[x + 2] >= 2) {
cnt2[x] -= 2, cnt2[x + 1] -= 2, cnt2[x + 2] -= 2;
if(dfs(x + 1, rest - 6, dui))
return true;
cnt2[x + 2] += 2, cnt2[x + 1] += 2, cnt2[x] += 2;
}
return false;
}
if(cnt2[x] >= 3) {
if(!dui) {
cnt2[x] -= 2;
if(dfs(x, rest - 2, true))
return true;
cnt2[x] += 2;
}
cnt2[x] -= 3;
if(dfs(x, rest - 3, dui))
return true;
cnt2[x] += 3;
if(x <= 7 && cnt2[x + 1] >= 1 && cnt2[x + 2] >= 1) {
cnt2[x] --, cnt2[x + 1] --, cnt2[x + 2] --;
if(dfs(x, rest - 3, dui))
return true;
cnt2[x + 2] ++, cnt2[x + 1] ++, cnt2[x] ++;
}
return false;
}
} vector<int> ans; void check(int x) {
memcpy(cnt2, cnt, sizeof(cnt2));
cnt2[x]++;
if(cnt2[x] > 4)
return;
int cnttwo = 7;
for(int i = 1; i <= 9; ++i)
cnttwo -= (cnt2[i] == 2);
if(cnttwo == 0 || dfs(1, 14, false))
ans.push_back(x);
} int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
#endif // Yinku
int T;
char s[20];
scanf("%d", &T);
while(T--) {
scanf("%s", s + 1);
memset(cnt, 0, sizeof(cnt));
for(int i = 1; i <= 13; ++i)
cnt[s[i] - '0']++;
ans.clear();
for(int i = 1; i <= 9; ++i)
check(i);
if(ans.empty())
ans.push_back(-1);
for(auto i : ans)
printf("%d", i);
puts("");
}
}

最新文章

  1. Database Replay和Consolidated Database replay
  2. 一个简单oop的changeTab
  3. net面试题
  4. cell 内部 设置width 总不对
  5. .net c# 视频剪切抓取缩略图
  6. cygwin-使用介绍
  7. NS2中trace文件分析
  8. HDU 3089 (快速约瑟夫环)
  9. javascript 判断浏览器的ie版本,替换html标签
  10. Android RecyclerView添加Header头部
  11. iOS开发——实战总结OC篇&amp;网易彩票开发知识点总结
  12. 基于单个 div 的 CSS 画图
  13. linux c: core dump
  14. c++设计模式-----抽象工厂模式
  15. HDU 5543 Pick The Sticks
  16. Android应用性能测试之CPU和内存占用
  17. 学习java的感受
  18. ubuntu修改grub,修改开机顺序,配置grub启动顺序
  19. Samba原理和配置
  20. Oracle 12c CDB PDB 安装/配置/管理

热门文章

  1. re模块下的的常用方法
  2. webkit内核的浏览器常见7种分别是..
  3. js自执行函数前加个分号是什么意思?
  4. asp.net (web)选择文件夹 上传文件
  5. 【PowerOJ1744&amp;网络流24题】方格取数问题(最小割)
  6. Redis学习:Redis的安装与配置
  7. [CF1082G]Petya and Graph:最小割
  8. 重新理解了重定向,利用重定向可以防止用户重复提交表单(兼谈springmvc重定向操作)
  9. shell中的=~的简单用法
  10. jetty 启动时出现的问题