Aizu - 0033(深搜)
2016-03-17 15:34
423 查看
题目链接:点击打开链接
解析:
深搜。用vis数组做标记,1的代表第一个数组,0的代表第二个数组。通过dfs生成第一个递增的数组,然后检查余下数字组成的第二个数组。
完整代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int maxn = 10001;
int a[maxn];
int vis[maxn];
void dfs(int pre , int cur)
{
if(cur < 10 && a[pre] < a[cur])
{
vis[cur] = 1;
dfs(cur , cur + 1);
}
else if(cur < 10 && a[pre] > a[cur]){
dfs(pre , cur + 1);
}
}
int main()
{
#ifdef DoubleQ
freopen("in.txt" , "r" , stdin);
#endif // DoubleQ
int n;
cin >> n;
while(n --){
for(int i = 0 ; i < 10 ; i ++){
cin >> a[i];
}
bool flag = false;
for(int i = 0 ; i < 10 ; i ++){
memset(vis , 0 , sizeof(vis));
vis[i] = 1;
dfs(i , i + 1);
int pre = 0;
for(int j = 0 ; j < 10 ; j ++){
if(vis[j] == 0){
if(pre > a[j]){
flag = true;
break;
}
else pre = a[j];
}
}
if(!flag){
cout << "YES" << endl;
break;
}
}
if(flag) cout << "NO" << endl;
}
}
解析:
深搜。用vis数组做标记,1的代表第一个数组,0的代表第二个数组。通过dfs生成第一个递增的数组,然后检查余下数字组成的第二个数组。
完整代码:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int maxn = 10001;
int a[maxn];
int vis[maxn];
void dfs(int pre , int cur)
{
if(cur < 10 && a[pre] < a[cur])
{
vis[cur] = 1;
dfs(cur , cur + 1);
}
else if(cur < 10 && a[pre] > a[cur]){
dfs(pre , cur + 1);
}
}
int main()
{
#ifdef DoubleQ
freopen("in.txt" , "r" , stdin);
#endif // DoubleQ
int n;
cin >> n;
while(n --){
for(int i = 0 ; i < 10 ; i ++){
cin >> a[i];
}
bool flag = false;
for(int i = 0 ; i < 10 ; i ++){
memset(vis , 0 , sizeof(vis));
vis[i] = 1;
dfs(i , i + 1);
int pre = 0;
for(int j = 0 ; j < 10 ; j ++){
if(vis[j] == 0){
if(pre > a[j]){
flag = true;
break;
}
else pre = a[j];
}
}
if(!flag){
cout << "YES" << endl;
break;
}
}
if(flag) cout << "NO" << endl;
}
}
相关文章推荐
- 【案例】RAID卡写策略改变引发的问题
- Pairs Forming LCM(素因子分解+lcm)
- larbin 的main函数
- IBM serverx服务器RAID阵列磁盘配置JBOD模式(直通模式)
- 使用azure send grid发送email
- genymotion问题:Failed to deploy virtual device : Server returned HTTP status code 0
- 【数字图像处理】带AI的井字棋游戏
- Mybaits学习笔记(一)
- WinMain函数
- 出现 (linker command failed with exit code 1) 错误总结
- RAID阵列与LVM逻辑卷组原理
- MapReduce任务分析与讨论MapReduce job explained
- USACO Barn Repair 解题日志
- HDU 4630 No Pain No Game(线段树离线处理)
- Rails中使用geometry格式的数据
- contains与compareDocumentPosition方法详解
- SDWebImage : NSURLErrorDomain - Code = 406
- contains和compareDocumentPosition 方法来确定是否HTML节点间的关系
- How to Repair, Restore, or Reinstall Grub 2 with a Ubuntu Live CD or USB
- 简单描述RAID级别: