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. C09 指针

    目录 指针相关概念 指针变量 null指针 指针的算术运算 指针数组 指向指针的指针 传递指针给函数 从函数返回指针 指针相关概念 变量 如果在程序中定义了一个变量,在对程序进行编译时,系统就会为这个 ...

  2. StatementHandler-Mybatis源码系列

    内容更新github地址:我飞 StatementHandler接口 StatementHandler封装了Mybatis连接数据库操作最基础的部分.因为,无论怎么封装,最终我们都是要使用JDBC和数 ...

  3. vue入坑教程(三)vue父子组件之间互相调用方法以及互相传递数据

    1.父组件调用子组件的方法 父组件: <template> <div> <button v-on:click="clickParent">点击& ...

  4. DB2中创建表

    CONNECT TO TEST; CREATE TABLE DB2ADMIN.PERSON ( ID BIGINT NOT NULL , NAME BIGINT , FLAG BIGINT , ADD ...

  5. [bzoj]1003: [ZJOI2006]物流运输

    Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格 ...

  6. CF-1013 (2019/02/09 补)

    CF-1013 A. Piles With Stones 比较两个序列的和,因为只能拿走或者不拿,所以总数不能变大. B. And 答案只有 -1,0,1,2几种可能,所以对于每一种答案都暴力扫一次是 ...

  7. 如何使用 HTML5 的picture元素处理响应式图片

    来自: http://www.w3cplus.com/html5/quick-tip-how-to-use-html5-picture-for-responsive-images.html 图片在响应 ...

  8. 无需上传附件到服务器,Servlet读取Excel(二)

    package com.str; import java.io.File;import java.io.FileInputStream;import java.io.IOException; impo ...

  9. perl-basic-数组操作

    RT...直接看代码 my @stack = ("Fred", "Eileen", "Denise", "Charlie" ...

  10. 3224: Tyvj 1728 普通平衡树(新板子)

    3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 17048  Solved: 7429[Submit][St ...