hdu4403暴力搜索
题意:
给你一个数字串,让你在里面添加一个=和若干个+,使等式成立.
思路:
lmax最大是15,直接暴搜,无压力,关键是判重,要在答案的时候判重,一开始在进队列之前判的,各种wa,哎!后来才发现如果在之前判断就不能得到当前什么符号都不加,而下一个有符号了,判重我用的是map,随意什么只要别爆内存就行,水搜索竟然调了2个小时,丢脸啊...
#include<stdio.h>
#include<string.h>
#include<queue>
#include<map>
using namespace std; typedef struct
{
int mk[16];
char str[16];
int nowid ,deng;
}NODE; NODE xin ,tou;
int nn;
map<__int64 ,__int64>mark; bool MK(NODE aa)
{
__int64 sum = 0;
for(int i = 0 ;i <= nn ;i ++)
sum = sum * 10 + aa.mk[i];
if(mark[sum]) return 1;
mark[sum] = 1;
return 0;
} bool ok(NODE tou)
{
if(tou.deng)
{
int l ,r;
l = r = 0;
int sum = 0;
int mki;
for(int i = 0 ;tou.mk[i] != 2 ;i ++)
{
if(tou.mk[i] == 1)
{
l += sum;
sum = tou.str[i] - 48;
}
else
{
sum = sum * 10 + tou.str[i] - 48;
}
mki = i;
}
l += sum;
sum = 0;
for(int i = mki + 1;i <= nn ;i ++)
{
if(tou.mk[i] == 1)
{
r += sum;
sum = tou.str[i] - 48;
}
else
{
sum = sum * 10 + tou.str[i] - 48;
}
}
r += sum;
return l == r && !MK(tou);
}
return 0;
} int BFS()
{
memset(xin.mk ,0 ,sizeof(xin.mk));
nn = strlen(xin.str) - 1;
xin.nowid = 0;
xin.deng = 0;
queue<NODE>q;
q.push(xin);
int ans = 0;
mark.clear();
while(!q.empty())
{
tou = q.front();
q.pop();
if(ok(tou))
ans ++;
if(tou.nowid == nn) continue;
if(!tou.deng)// =
{
xin = tou;
xin.deng = 1;
xin.nowid = tou.nowid + 1;
xin.mk[xin.nowid] = 2;
q.push(xin);
} //+
xin = tou;
xin.deng = tou.deng;
xin.nowid = tou.nowid + 1;
xin.mk[xin.nowid] = 1;
q.push(xin); //
xin = tou;
xin.deng = tou.deng;
xin.nowid = tou.nowid + 1;
xin.mk[xin.nowid] = 0;
q.push(xin);
}
return ans;
} int main ()
{
while(~scanf("%s" ,xin.str) && strcmp("END" ,xin.str))
{
printf("%d\n" ,BFS());
}
return 0;
}
hdu4403暴力搜索的更多相关文章
- ACM 暴力搜索题 题目整理
UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...
- hdu 4740 The Donkey of Gui Zhou(暴力搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...
- hdu 1427 速算24点 dfs暴力搜索
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem De ...
- 随手练——洛谷-P1151(枚举与暴力搜索)
枚举 #include <iostream> using namespace std; int main() { ; cin >> k; ; i < ; i++) { ) ...
- 枚举进程——暴力搜索内存(Ring0)
上面说过了隐藏进程,这篇博客我们就简单描述一下暴力搜索进程. 一个进程要运行,必然会加载到内存中,断链隐藏进程只是把EPROCESS从链表上摘除了,但它还是驻留在内存中的.这样我们就有了找到它的方法. ...
- [luogu 1092] 虫食算 (暴力搜索剪枝)
传送门 Description Input 包含四行. 第一行有一个正整数 (N≤26). 后面的三行,每行有一个由大写字母组成的字符串,分别代表两个加数以及和.这3个字符串左右两端都没有空格,从高位 ...
- HDU 3131 One…Two…Five! (暴力搜索)
题目链接:pid=3131">HDU 3131 One-Two-Five! (暴力搜索) 题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6= ...
- 吴裕雄 python 机器学习——模型选择参数优化暴力搜索寻优GridSearchCV模型
import scipy from sklearn.datasets import load_digits from sklearn.metrics import classification_rep ...
- POJ 1129:Channel Allocation 四色定理+暴力搜索
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13357 Accepted: 68 ...
随机推荐
- FutureTask源码分析(JDK7)
总览 A cancellable asynchronous computation. This class provides a base implementation of {@link Futur ...
- node.js详解1
1.运行node脚本 新建app.js 写入代码console.log('hello') cmd终端执行 node app.js 2.node读取环境变量 浏览器地址:ht ...
- fastjson<=1.2.47反序列化漏洞复现
0x00:前言 这个漏洞爆出来之后本来一直打算挑时间去复现,后来一个朋友突然发来他们站点存在fastjson这个漏洞被白帽子发了报告.既然漏洞环境送上门来,我便打算直接下手试一试.在我的想象中当然是一 ...
- 【odoo14】odoo 14 Development Cookbook【目录篇】
网上已经有大佬翻译过odoo12并且在翻译odoo14了.各位着急的可以自行搜索下... 这本书是为了让自己从odoo12转odoo14学习.也是为了锻炼下自己... odoo 14 Developm ...
- 2019 GDUT Rating Contest III : Problem A. Out of Sorts
题面: 传送门 A. Out of Sorts Input file: standard input Output file: standard output Time limit: 1 second M ...
- Django的路由控制
一.Django中路由到作用 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表:你就是以这种方式告诉Django,对于客户端发来 ...
- python tempfile 创建临时目录
一.tempfile介绍 该模块创建临时文件和目录.它适用于所有支持的平台.TemporaryFile,NamedTemporaryFile,TemporaryDirectory,和SpooledTe ...
- Visual Studio添加引用的方式
- 5行代码!完成bat病毒制作!!!
这个病毒的功能是删除当前目录下.cpp类型的代码. copy %0 "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\P ...
- DAOS 分布式异步对象存储|事务模型
DAOS API 支持分布式事务,允许将针对属于同一 Container 的对象的任何更新操作组合到单个 ACID 事务中.分布式一致性是通过基于多版本时间戳排序的无锁乐观并发控制机制提供的.DAOS ...