sgu 116 Index of super-prime
题意:用最少的super-prime组成n;
找出所有的super-prime数,只有202个。用完全背包记录能取到n值的最少数量。再找出7要哪些元素。
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <iomanip>
- #include <cstring>
- #include <map>
- #include <queue>
- #include <set>
- #include <cassert>
- using namespace std;
- const double EPS=1e-;
- const int SZ=,INF=0x7FFFFFFF;
- typedef long long lon;
- bool p[SZ];
- int sz,pri[SZ],spr[SZ],ssz;
- set<int> st;
- int dp[][SZ];
- void init()
- {
- memset(p,,sizeof(p));
- for(int i=;i<SZ;++i)
- {
- if(p[i])
- {
- for(int j=i*i;j<SZ;j+=i)p[j]=;
- pri[++sz]=i;
- st.insert(i);
- }
- }
- for(int i=;i<=sz;++i)
- {
- if(st.find(i)!=st.end())spr[++ssz]=pri[i];
- }
- }
- void show(int r,int c)
- {
- for(int i=;i<=r;++i)
- {
- for(int j=;j<=c;++j)
- {
- cout<<dp[i][j]<<" ";
- }cout<<endl;
- }
- }
- void work(int x)
- {
- memset(dp,-,sizeof(dp));
- int pos=;
- dp[][]=;
- for(int i=;i<=ssz;++i)
- {
- if(spr[i]<=x)pos=i;
- else break;
- for(int j=;j<=x;++j)
- {
- dp[i][j]=dp[i-][j];
- if(j>=spr[i]&&dp[i][j-spr[i]]!=-)
- {
- //if(i==1)cout<<j<<" "<<dp[i][j-spr[i]]<<endl;
- if(dp[i-][j]==-)dp[i][j]=dp[i][j-spr[i]]+;
- else dp[i][j]=min(dp[i][j],dp[i][j-spr[i]]+);
- }
- }
- }
- //show(pos,x);
- //if(x!=6)for(;;);
- if(dp[pos][x]==-)
- {//if(x!=6)for(;;);
- cout<<""<<endl;
- return;
- }
- //if(x!=6)for(;;);
- vector<int> res;
- for(int i=pos,j=x;i>=&&j>;)
- {
- if(j>=spr[i]&&dp[i][j-spr[i]]+==dp[i][j])
- {
- res.push_back(spr[i]);
- j-=spr[i];
- }
- else --i;
- }
- {
- cout<<dp[pos][x]<<endl;
- for(int i=;i<res.size();++i)
- {
- if(i)cout<<' ';
- cout<<res[i];
- }
- }
- }
- int main()
- {
- std::ios::sync_with_stdio();
- //freopen("d:\\1.txt","r",stdin);
- init();
- //cout<<ssz<<endl;
- int n;
- cin>>n;
- work(n);
- return ;
- }
sgu 116 Index of super-prime的更多相关文章
- 素数 + 背包 - SGU 116. Index of super-prime
Index of super-prime Problem's Link Mean: 如果一个素数所在的位置还是素数,那么这个素数就是超级素数,比如3在第2位置,那么3就是超级素数. 现在给你一个数,求 ...
- Index of super-prime - SGU 116(素数+背包)
题目大意:素数表2,3,5,7,11.....如果一个素数所在的位置还是素数,那么这个素数就是超级素数,比如3在第2位置,那么3就是超级素数.....现在给你一个数,求出来这个数由最少的超级素数的和组 ...
- SGU 106.Index of super-prime
时间限制:0.25s 空间限制:4M 题目大意: 在从下标1开始素数表里,下标为素数的素数,称为超级素数(Super-prime),给出一个n(n<=10000) ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 快速切题 sgu116. Index of super-prime bfs+树思想
116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...
- Python 之 super & MRO (没有遇到过适用场景)
WOW!!! 这里wow的是真尼玛绕且没看完, 好困呐,贴上网址,等自己英文好一点再看(https://rhettinger.wordpress.com/2011/05/26/super-consid ...
- UESTC 1272 Final Pan's prime numbers(乱搞)
题目链接 Description Final Pan likes prime numbers very much. One day, he want to find the super prime n ...
- poj 1595 Prime Cuts
Prime Cuts Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10610 Accepted: 4046 Descr ...
- Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
问题描述: PhoneGap+Sencha Touch开发的应用,打包后的APP或者调试期间,在启动的时候提示如下信息: Application Error - The connection to t ...
随机推荐
- 无法在web服务器下启动调试
VS2013 编译时异常 无法在web服务器下启动调试.该Web服务器未及时响应 VS2013 编译时错误 无法在web服务器上启动调试.该Web服务器未及时响应.无法在web服务器上启动调试.该 ...
- 论文笔记:2018 PRCV 顶会顶刊墙展
Global Gated Mixture of Second-order Pooling for Imporving Deep Convolutional Neural Network(2018 NI ...
- web前端----jQuery扩展(很重要!!)
1.jQuery扩展语法 把扩展的内容就可以写到xxxx.js文件了,在主文件中直接导入就行了. 用法1.$.xxx() $.extend({ "GDP": function () ...
- 推荐:Java性能优化系列集锦
Java性能问题一直困扰着广大程序员,由于平台复杂性,要定位问题,找出其根源确实很难.随着10多年Java平台的改进以及新出现的多核多处理器,Java软件的性能和扩展性已经今非昔比了.现代JVM持续演 ...
- Python3 爬取微信好友基本信息,并进行数据清洗
Python3 爬取微信好友基本信息,并进行数据清洗 1,登录获取好友基础信息: 好友的获取方法为get_friends,将会返回完整的好友列表. 其中每个好友为一个字典 列表的第一项为本人的账号信息 ...
- Java并发之FairSync和NonfairSync
Java并发中的fairSync和NonfairSync主要区别为: 如果当前线程不是锁的占有者,则NonfairSync并不判断是否有等待队列,直接使用compareAndSwap去进行锁的占用; ...
- 解决国内 NPM 安装依赖速度慢问题
不知道各位是否遇到这种情况,使用NPM(Node.js包管理工具)安装依赖时速度特别慢,为了安装Express,执行命令后两个多小时都没安装成功,最后只能取消安装,笔者20M带宽,应该不是我网络的原因 ...
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...
- VC++ 利用CreateFile、ReadFile和WriteFile实现CopyFile
1. CreateFile:这是一个多功能的函数,可打开或创建以下对象,并返回可访问的句柄:控制台,通信资源,目录(只读打开),磁盘驱动器,文件,邮槽,管道. 参照:http://www.cppblo ...
- Python3基础 str translate 将指定字符转换成另一种特定字符
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...