Fill the blanks

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 283    Accepted Submission(s): 115

Problem Description
There is a matrix of 4*4, you should fill it with digits 0 – 9, and you should follow the rules in the following picture:

 
Input
No input.
 
Output
Print all the matrixs that fits the rules in the picture. 
And there is a blank line between the every two matrixs.
 
Sample Output
1193
1009
9221
3191
 
1193
1021
9029
3911
……
9173
1559
3821
3391
 
 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; bool flag[],mark;
int map[][]; void get_primes()
{
memset(flag,,sizeof(flag));
int i,j;flag[]=flag[]=;
for(i=;i<;i++)
{
for(j=i+i;j<;j+=i)
flag[j]=;
}
}
bool cjudge(int x)
{
int i,a=,b=;
for(i=;i<;i++) a=a*+map[x][i];
for(i=;i>=;i--) b=b*+map[x][i];
if(flag[a]&&flag[b]) return true;
return false;
}
bool rjudge(int x)
{
int i,a=,b=;
for(i=;i<;i++) a=a*+map[i][x];
for(i=;i>=;i--) b=b*+map[i][x];
if(flag[a]&&flag[b]) return true;
return false;
}
bool ljudge()
{
int i,a=,b=;
for(i=;i<=;i++) a=a*+map[i][-i];
for(i=;i>=;i--) b=b*+map[i][-i];
if(flag[a]&&flag[b]) return true;
return false;
}
bool rjudge()
{
int i,a=,b=;
for(i=;i<=;i++) a=a*+map[i][i];
for(i=;i>=;i--) b=b*+map[i][i];
if(flag[a]&&flag[b]) return true;
return false;
}
void Printf()
{
for(int i=;i<;i++)
{
for(int j=;j<;j++)
printf("%d",map[i][j]);
printf("\n");
}
} void dfs(int i,int j)
{
if(i==)
{
if(mark++) puts("");
Printf();
return ;
}
for(int k=;k<;k++)
{
if(k%== && (i==||i==||j==||j==)) continue;
map[i][j]=k;
if(j== && !cjudge(i)) continue;
if(i== && !rjudge(j)) continue;
if(i== && j== && !ljudge()) continue;
if(i== && j== && !rjudge()) continue;
dfs(i+(j+)/,(j+)%);
}
} int main()
{
get_primes();
mark=;
dfs(,);
return ;
}

hdu 1979 剪枝暴搜的更多相关文章

  1. 长沙理工大学第十二届ACM大赛L 选择困难症 (剪枝暴搜)

    链接:https://ac.nowcoder.com/acm/contest/1/L 来源:牛客网 选择困难症 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 131072K,其他语言 ...

  2. hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

    Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  3. HDU 4620 Fruit Ninja Extreme 暴搜

    题目大意:题目就是描述的水果忍者. N表示以下共有 N种切水果的方式. M表示有M个水果需要你切. W表示两次连续连击之间最大的间隔时间. 然后下N行描述的是 N种切发 第一个数字C表示这种切法可以切 ...

  4. HDU 4284 Travel (Folyd预处理+dfs暴搜)

    题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...

  5. 紫书 习题7-14 UVa 307(暴搜+剪枝)

    这道题一开始我想的是在排序之后只在头和尾往中间靠近来找木块, 然后就WA, 事实证明这种方法是错误的. 然后参考了别人的博客.发现别人是直接暴搜, 但是加了很多剪枝, 所以不会超时. 我也想过这个做法 ...

  6. hdu4982 暴搜+剪枝(k个数和是n,k-1个数的和是平方数)

    题意:       给你两个数n,k问你是否怎在这样一个序列:      (1)这个序列有k个正整数,且不重复.      (2)这k个数的和是n.      (3)其中有k-1个数的和是一个平方数. ...

  7. hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜

    题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...

  8. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

  9. hdu4848 DFS 暴搜+ 强剪枝

    题意:       给你一个图,然后问你从1出发遍历所有的点的距离和是多少,这里的距离和是每一个点到1的距离的总和,不是选择一条遍历所有点的路径的总长度,时间限制是 8000ms. 思路:       ...

随机推荐

  1. PAT (Basic Level) Practise (中文)-1019. 数字黑洞 (20)

    http://www.patest.cn/contests/pat-b-practise/1019 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第 ...

  2. Bootstrap 缩略图

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  3. runtime实践之Method Swizzling

    利用 Objective-C 的 Runtime 特性,我们可以给语言做扩展,帮助解决项目开发中的一些设计和技术问题.这一篇,我们来探索一些利用 Objective-C Runtime 的黑色技巧.这 ...

  4. 【思维题 状压dp】APC001F - XOR Tree

    可能算是道中规中矩的套路题吧…… Time limit : 2sec / Memory limit : 256MB Problem Statement You are given a tree wit ...

  5. python2和python3中filter函数

    在python2和python3中filter是不同的,其中在python2中filter返回的是一个list,可以直接使用 >>> a = [1,2,3,4,5,6,7] > ...

  6. 【android】安卓开发apk列表

    - 谷歌的Zxing框架的扫码软件 (目前国内的应用商店很少此种类型的扫码app) - 解析IP地址功能,从IP地址(子网掩码)自动解析出网段,广播地址

  7. python 列表加法"+"和"extend"的区别

    相同点 : "+"和"extend"都能将两个列表成员拼接到到一起 不同点 :   + : 生成的是一个新列表(id改变) extend : 是将一个列表的成员 ...

  8. poj-3278 catch that cow(搜索题)

    题目描述: Farmer John has been informed of the location of a fugitive cow and wants to catch her immedia ...

  9. light oj 1104 Birthday Paradox (概率题)

    Sometimes some mathematical results are hard to believe. One of the common problems is the birthday ...

  10. MySQL配置允许远程登录

    MySQL默认只允许用户本地登录,需要远程连接可进行如下操作: 允许root用户在任何地方进行远程登录,并具有所有库任何操作权限: 使用root用户登录mysql: mysql -u root -p& ...