【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

迭代加深搜索。
枚举最大层数。(也即改变的数字个数
然后枚举第一个改哪个数字,第二个改哪个数字。。
一定要注意字典序问题。
每次优先改成较小的字典序(也即顺序枚举
然后注意这个字符不改的情况。
不要算改变数。
最后改完之后。
只需要枚举a和b的情况。
看看a*b是不是等于c就好
->查看这样的a*b数量是不是1
如果是1的话.就说明是正确的。直接输出那个ans就好(我们已经是从小到大枚举了,找到的一定是答案

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
using namespace std; string x,y,z,s,ans;
int belong[10];
int maxdep,lenx,leny,lenz,tot; string inttostring(int x){
string s = "";
while (x > 0){
s = (char)(x%10+'0')+ s;
x/=10;
}
return s;
} int stringtoint(string s){
int x = 0;
int len = s.size();
for (int i = 0;i < len;i++){
x = x *10 + s[i]-'0';
}
return x;
} void ok(int dep){
if (tot>1) return;
if (dep==lenx+leny){
string v[3];
for (int i = 0;i < 3;i++) v[i]="";
for (int i = 0;i < lenx+leny+lenz;i++) v[belong[i]]+=s[i];
int tx = stringtoint(v[0]),ty = stringtoint(v[1]);
tx = tx*ty;
string tz = inttostring(tx);
if ((int)tz.size()!=(int)v[2].size()) return;
for (int i = 0;i < (int) v[2].size();i++)
if (tz[i]!=v[2][i] && v[2][i]!='*') return;
tot++;
return;
}
if (s[dep]=='*'){
int qidian = 0;
if (dep==0 || dep == lenx || dep==lenx+leny) qidian = 1;
for (int i = qidian;i <= 9;i++){
s[dep] = i+'0';
ok(dep+1);
s[dep] = '*';
}
}else ok(dep+1);
} bool dfs1(int dep,int nex){
if (dep==maxdep){
tot = 0;
string tans = s;
ok(0);
if(tot==1) {
ans = s;
return true;
}
return false;
}
if (nex>=lenx+leny+lenz) return false;
char temp; temp = s[nex];
s[nex] = '*';
int cnt = 1;
if (s[nex]==temp) cnt = 0;
if (dfs1(dep+cnt,nex+1)) return true;
s[nex] = temp; int qidian = 0;
if (nex==0 || nex == lenx || nex == lenx+leny) qidian = 1;
for (int i = qidian;i <= 9;i++){
temp = s[nex];
s[nex] = i+'0';
int cnt = 1;
if (s[nex]==temp) cnt = 0;
if (dfs1(dep+cnt,nex+1)) return true;
s[nex] = temp;
} return false;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int kase = 0;
while (cin >> x && x[0]!='0'){
ans.clear();
cin >> y >> z;
lenx = x.size(),leny = y.size(),lenz = z.size();
s = x + y + z;
for (int i = 0;i < lenx;i++) belong[i] = 0;
for (int i = lenx;i < lenx+leny;i++) belong[i] = 1;
for (int i = lenx+leny;i < lenx+leny+lenz;i++) belong[i] = 2; for (maxdep = 0;;maxdep++)
if (dfs1(0,0)) break; cout <<"Case "<<++kase<<": ";
for (int i = 0;i < lenx;i++) cout << ans[i];cout <<' ';
for (int i = lenx;i < lenx+leny;i++) cout << ans[i];cout <<' ';
for (int i = lenx+leny;i < lenx+leny+lenz;i++) cout << ans[i];
cout << endl;
}
return 0;
}

【习题 7-8 UVA-12107】Digit Puzzle的更多相关文章

  1. UVA - 12107 Digit Puzzle(数字谜)(IDA*)

    题意:给出一个数字谜,要求修改尽量少的数,使修改后的数字谜只有唯一解.空格和数字可以随意替换,但不能增删,数字谜中所有涉及的数必须是没有前导零的正数.输入数字谜一定形如a*b=c,其中a.b.c分别最 ...

  2. UVA_Digit Puzzle UVA 12107

    If you hide some digits in an integer equation, you create a digit puzzle. The figure below shows tw ...

  3. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

  4. UVa 1583 Digit Generator --- 水题+打表

    UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...

  5. 紫书 习题7-8 UVa 12107 (IDA*)

    参考了这哥们的博客 https://blog.csdn.net/hyqsblog/article/details/46980287  (1)atoi可以char数组转int, 头文件 cstdlib ...

  6. UVa 1225 Digit Counting

    题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...

  7. UVa 1583 Digit Generator(数学)

     题意 假设a加上a全部数位上的数等于b时 a称为b的generator  求给定数的最小generator 给的数n是小于100,000的  考虑到全部数位和最大的数99,999的数位和也才45 ...

  8. UVa 1583 - Digit Generator

    A+A的每一位的数字的和=B 问你每一个B对应 的最小的A 是多少 不然输出0: #include <cstdio> #include <iostream> #include ...

  9. UVa 10533 - Digit Primes

    题目:输出给定区间中,本身是素数,而且这个数的各位之和也是素数的数(称为位素数)的个数. 分析:数论.首先利用筛法,求出1000000内的全部的素数:然后在利用生成的素数表, 推断每一个数是不是各位之 ...

随机推荐

  1. Dubbo源代码分析(三):Dubbo之服务端(Service)

    如上图所看到的的Dubbo的暴露服务的过程,不难看出它也和消费者端非常像,也须要一个像reference的对象来维护service关联的全部对象及其属性.这里的reference就是provider. ...

  2. rman数据库恢复;关键/非重要文件、影像副本、控制文件、还原点、非归档、增量、新数据库、灾难性回复

    运行全然恢复:在 ARCHIVELOG 模式下 丢失了系统重要数据文件: 假设某个数据文件丢失或损坏.且该文件属于 SYSTEM 或 UNDO 表空间,请运行下面步骤: 1. 实例可能会也可能不会自己 ...

  3. 2.最详细的WSDD配置文件注释

    https://blog.csdn.net/u011063151/article/details/52590282

  4. 22.dll调用技术

    1.dll文件: #include <Windows.h> _declspec(dllexport) void message_hello() { MessageBoxA(, ); } _ ...

  5. Django transaction 误用之后遇到的一个问题与解决方法

    今天在调试项目开发好的一个模块的时候,发现了一个很诡异的现象,最后追踪发现是因为在项目中事务处理有误所致.这个问题坑了我好一会,所以记录一下,以免再踩坑.下面开始详述. 我们都知道 Django 框架 ...

  6. blkid---对系统块设备信息查询

    在Linux下可以使用blkid命令对查询设备上所采用文件系统类型进行查询.blkid主要用来对系统的块设备(包括交换分区)所使用的文件系统类型.LABEL.UUID等信息进行查询.要使用这个命令必须 ...

  7. mysql省市区数据库表源码

     下载  一:创建表 1省: create table CREATE TABLE `provinces` ( `id` ) NOT NULL AUTO_INCREMENT, `provinceid` ...

  8. 使用Linux遇到的一些问题和解决方案

    1.如何在重装系统或换机器以后继续使用以前用过的thunderbird邮件 执行命令thunderbird -ProfileManager以后会打开一个配置用户界面. 在里面添加一个新的配置,然后选择 ...

  9. Android捕获View焦点事件,LinearLayout结合HorizontalScrollView实现ViewPgaer和选项卡Tabs联动

     <Android捕获View焦点事件,LinearLayout结合HorizontalScrollView实现ViewPgaer和选项卡Tabs联动.> 如图: package zh ...

  10. [Python] Wikipedia Crawler

    import time import urllib import bs4 import requests start_url = "https://en.wikipedia.org/wiki ...