p1218 Superprime Rib
深搜,添加数字后如果仍为质数,继续递归。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF;
vector<int> pri,res;
bool isp[SZ]; bool isprime(int x)
{
for(int i=;i<pri.size();++i)
{
if(x!=pri[i]&&x%pri[i]==)return ;
}
return ;
} void dfs(int x,int n,int val)
{
if(x==n)
{
res.push_back(val);
return;
}
val*=;
for(int i=;i<;i+=)
{
val+=i;
if(isprime(val))
{
dfs(x+,n,val);
}
val-=i;
}
} void init()
{
memset(isp,,sizeof(isp));
isp[]=;
for(int i=;i*i<SZ;++i)
{
if(isp[i])
for(int j=i*i;j<SZ;j+=i)
{
isp[j]=;
}
}
for(int i=;i<SZ;++i)
{
if(isp[i])
{
pri.push_back(i);
}
}
} void work(int n)
{
init();
for(int i=;i<;++i)
{
dfs(,n,pri[i]);
}
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
int n;
cin>>n;
work(n);
for(int i=;i<res.size();++i)
{
cout<<res[i]<<endl;
}
}
return ;
}
p1218 Superprime Rib的更多相关文章
- 洛谷P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib
P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 284通过 425提交 题目提供者该用户不存在 标签USACO 难度普及- 提交 讨论 题解 最新讨论 超时怎么办? ...
- 洛谷 P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib
P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们.农民约翰确定他卖给 ...
- 洛谷P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 使用四种算法
洛谷P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 水题一道…… 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. ...
- USACO Superprime Rib
洛谷 P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 洛谷传送门 JDOJ 1673: Superprime Rib JDOJ传送门 题目描述 农民约翰的母牛总是产生最好 ...
- USACO 1.5 Superprime Rib
Superprime Rib Butchering Farmer John's cows always yields the best prime rib. You can tell prime ri ...
- P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib (数论—素数 + DFS)
这大概是我写的第一个DFS 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们.农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋骨, ...
- P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib
题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们.农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋骨,每次还剩下的肋骨上的数字都组 ...
- [Swust OJ 799]--Superprime Rib(DFS)
题目链接:http://acm.swust.edu.cn/problem/799/ Time limit(ms): 1000 Memory limit(kb): 10000 Description ...
- 【USACO 1.5】SuperPrime Rib
/* TASK: sprime LANG: C++ SOLVE: dfs,后面每增加一位,判断当前是否为素数. 第一位不能为0 */ #include<cstdio> int n; voi ...
随机推荐
- Python3 tkinter基础 Button command 单击按钮 在console中打印文本
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- java Swing小知识点
private JTextArea jta=new JTextArea(1,2); private ScrollPane sp=new ScrollPane(); private JPasswordF ...
- CentOS 源码编译安装 Python3
准备 yum -y install wget gcc make libffi-devel zlib-devel readline-devel bzip2-devel ncurses-devel sql ...
- linux下如何使make只输出执行过程中的命令序列
答: make -n (-n.--just-print.--dry-run.--recon等价)
- linux内核中侧async_tx是什么?
答: 异步内存传输api(asynchronous memory transfer/transform API),这是一种api,用来为应用提供操作DMA的API. 下图是async_tx在架构中所处 ...
- selinux 设置的彻底理解 并要 熟练经常的使用
只需要参考这篇文章就好了: http://www.jishux.com/plus/view-631994-1.html 注意 在linux中 两个术语 的严格区分和使用: 改变: change; 改变 ...
- js字符串方法、数组方法整理
push 向数组末尾添加一项 返回值为数组的长度: pop 删除数组最后一项: unshift 向数组开头增加一项: shift 删除数组第一项: splice 删除数组中的值:1 splice(n, ...
- 【C#】神奇的yeild
直接出栗子: class Program { static void Main(string[] args) { foreach (var item in FilterWithoutYield) { ...
- facebook ads api
api测试 https://developers.facebook.com/tools/explorer/517735271920003?method=GET&path=act_1107316 ...
- JqGrid 列时间格式化
{name:'createTime',index:'createTime',label:"创建时间", editable:false,formatter:"date&qu ...