UvaLive-4255-Guess
来源:互联网 发布:淘宝网购物女童鞋 编辑:程序博客网 时间:2024/06/03 02:07
算是个模拟题吧,先完成对字符串的处理和转换。我用的是DFS进行搜索~
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;char map[11][11];int n,ans[11],sum[11];bool DFS(int index){ if(index==n+1)return true; for(int i=-10;i<=10;i++) {int m,flag=0;if(i<=0) m=-(i+10);else m=i;for(int j=1;j<=index;j++){ if(map[index][j]=='+') {if(m+sum[index-1]-sum[j-1]<=0){ flag=1; break;} } else if(map[index][j]=='-') {if(m+sum[index-1]-sum[j-1]>=0){ flag=1; break;} } else {if(m+sum[index-1]-sum[j-1]!=0){ flag=1; break;} }}if(!flag){ ans[index]=m; sum[index]=sum[index-1]+m; if(DFS(index+1))return true;} } return false;}int main(){ int T; scanf("%d",&T); while(T--) {char str[1001];scanf("%d",&n);scanf("%s",str);int cou=0;for(int i=1;i<=n;i++) for(int j=i;j<=n;j++)map[j][i]=str[cou++];memset(ans,0,sizeof(ans));memset(sum,0,sizeof(sum));DFS(1);for(int i=1;i<=n;i++) printf("%d%c",ans[i],i==n?'\n':' '); } return 0;}
- UvaLive-4255-Guess
- UVALive - 4255 Guess
- UVALive - 4255 Guess
- UVALive 4255 Guess
- UVALive 4255 Guess
- UVALive 4255 Guess【拓扑排序 】
- UVALive 4255-Guess-拓扑排序
- UValive 4255 Guess(拓扑排序)
- UVALive - 4255 - Guess (拓扑排序)
- UvaLive 4255 Guess(拓扑排序)
- UVALive 4255 Guess(前缀和+拓扑排序)
- UVALive 3664 Guess(贪心+精度)
- LA 4255 Guess
- LA 4255 Guess
- LA 4255(p309)----Guess
- Guess
- guess
- LA 4255 Guess 拓扑排序
- 提高web性能之--使用内容发布网络
- [Go] --- map
- 简单词法分析器的实现原理(编译原理)
- stdin、stdout & printf、scanf & fprintf、fscanf
- 继承和接口
- UvaLive-4255-Guess
- Valgrind
- POJ1201--差分约束--Intervals
- 函数模板与类模板的区别
- ubuntu下获取一个程序在终端的运行命令的方法
- 国务院李佐军博士内部报告会全文:中国2013年爆发经济危机
- ORA-39050: parameter _log_private_parallelism is incompatible with parameter _redo_read_from_memory
- 形态学图像处理
- 切换到 oracle的 hr用户下面练习