usaco Checker Challenge
来源:互联网 发布:知乎 支链氨基酸 肌酸 编辑:程序博客网 时间:2024/05/17 08:21
很朴实的DFS没有加任何剪枝和优化,0.7sec ~~
code:
/*ID: yueqiqLANG: C++TASK: checker*/#include <set>#include <map>#include <ctime>#include <queue>#include <cmath>#include <stack>#include <limits>#include <vector>#include <bitset>#include <string>#include <cstdio>#include <cstring>#include <fstream>#include <string.h>#include <iostream>#include <algorithm>#define ls rt<<1#define rs rt<<1|1#define Si set<int>#define LL long long#define pb push_back#define PS printf(" ")#define Vi vector<int>#define LN printf("\n")#define SD(a) scanf("%d",&a)#define PD(a) printf("%d",a)#define SET(a,b) memset(a,b,sizeof(a))#define FF(i,a) for(int i(0);i<(a);i++)#define FD(i,a) for(int i(a);i>=(1);i--)#define FOR(i,a,b) for(int i(a);i<=(b);i++)#define FOD(i,a,b) for(int i(a);i>=(b);i--)#define readf freopen("checker.in","r",stdin)#define writef freopen("checker.out","w",stdout)const double pi = acos(-1.0);const int maxn = 50;const int BigP = 99999999;const int INF = 99999999;const int dx[]={0,1,0,-1};const int dy[]={1,0,-1,0};using namespace std;int N,ans;bool visx[maxn],visy[maxn],vis1[maxn],vis2[maxn];//vis1 2-2N vis2 1-(2N-1);//p is 列int path[21];int count=0;bool can(int x,int y){ if(visx[x]) return false; if(visy[y]) return false; if(vis1[x+y]) return false; if(vis2[N-y+x]) return false; return true;}void dfs(int p){ if(p>N){ ans++; if(ans<=3){ FOR(i,1,N-1) printf("%d ",path[i]); printf("%d\n",path[N]); } return ; } FOR(i,1,N){ if(can(i,p)){ visx[i]=true; visy[p]=true; vis1[i+p]=true; vis2[N-p+i]=true; path[p]=i; dfs(p+1); visx[i]=false; visy[p]=false; vis1[i+p]=false; vis2[N-p+i]=false; } }}int main(){ readf; writef; SD(N); dfs(1); PD(ans);LN; return 0;}
- USACO 1.5 Checker Challenge (checker)
- 【搜索】【USACO】Checker Challenge
- [usaco]1.5 Checker Challenge
- usaco Checker Challenge
- USACO:Checker Challenge
- USACO-Checker Challenge
- USACO Checker Challenge
- USACO Checker Challenge
- USACO 1.5.4 Checker Challenge
- [USACO 1.5.4] Checker Challenge
- usaco 1.5.4 Checker Challenge
- USACO Checker Challenge 位运算
- USACO Section 1.5 Checker Challenge
- USACO Section 1.5 Checker Challenge
- USACO 1.5 Checker Challenge (DFS)
- USACO section 1.5.4 Checker Challenge
- USACO section 1.5 Checker Challenge(dfs深搜)
- USACO-cha1-sec1.5 Checker Challenge
- C++与C#之容器Map的比较
- myweb的nodejs框架通过npm安装方式
- hibernate错误java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss
- [Linux]链接,静态库和动态库
- SqlServer中查看,修改Identity的值
- usaco Checker Challenge
- ibatis-数据类型超最大值
- java 代码上传
- ffmpeg采集编码的测试文档
- 帮助你生成纯CSS3动画开关效果的在线工具 - On/Off FlipSwitch
- Code::Blocks安装过程
- 分离当前正在使用的数据库
- 如何修改ubuntu 的Grub来修改启动项
- 游戏引擎——Box2d(v2.1a, for flash)单位转换