URAL 2047 Maths 打表 递推
Maths
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87157#problem/B
Description
Input
Output
If there is no such sequence output “Impossible”. Otherwise output space-separated integers a1, …, an (1 ≤ ai ≤ 300).
Sample Input
3
Sample Output
1 3 4
HINT
题意
让你构造n个数,要求a1+……+ak的和的因子数恰好为ak
题解:
假设我们已经构造出了ak,且前缀和sum已知,那么ak-1=sum-ak,这个是显然的结论
于是我们直接打表打出来100000位就好了,然后把sum求出来,然后前面直接递推就好了
代码:
打表程序:
#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 2000001 #define mod 1000000007 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() {ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } //**************************************************************************************int cnt[300*200010]; vector<int> Q; int flag=0; int n; void dfs(int N,int sum,int z) {if(flag)return;if(sum+z>300*100000)return;if(N>1&&cnt[sum]!=z)return;if(N==n){printf("%d",Q[0]);for(int i=1;i<Q.size();i++)printf(" %d",Q[i]);printf("\n");cout<<sum<<endl;flag=1;return;}for(int i=1;i<=300;i++){Q.push_back(i);dfs(N+1,sum+i,i);Q.erase(Q.end()-1);}} int main() {freopen("1.out","w",stdout);for(int i=1;i<=300*100010;i++){for(int j=i;j<300*100010;j+=i){cnt[j]++;}}n=read();Q.clear();flag=0;for(int i=1;i<=300;i++){Q.push_back(i);dfs(1,i,i);Q.erase(Q.end()-1);}if(flag==0)printf("Impossible\n"); }
AC程序:
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 20001 #define mod 1000000007 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() {ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } //************************************************************************************** const int N=2000000; int cnt[N]; int a[N],sum=0; vector<int> Q; int flag=0; int n; int tot; int main() {for(int i=1;i<N;i++){for(int j=i;j<N;j+=i)cnt[j]++;}for(int p=1586335,i=100000;i>0;p-=cnt[p],i--){a[i]=cnt[p];sum+=a[i];}n=read();for(int i=1;i<n;i++) printf("%d ",a[i]);printf("%d\n",a[n]); }
转载于:https://www.cnblogs.com/qscqesze/p/4718887.html
URAL 2047 Maths 打表 递推相关推荐
- 【牛客 - 318L】彪神666(水题,半高精度,递推,trick)
题干: 在国外,666代表魔鬼,777代表上帝. 所以牛逼的彪神就非常不喜欢6这个数字. 有一天彪神突发奇想,,他想求一些书与6无关的数. 如果一个数能被6整除,或者它的十进制表示法中某位上的数字为6 ...
- 【THUSC 2017】如果奇迹有颜色【polya引理】【矩阵】【计数dp】【BM打表+线性递推】
题意:长度为 nnn 的环染 mmm 种颜色,要求任意相邻 mmm 个元素不能包含全部的颜色.求方案数 模 109+710^9+7109+7,循环同构. n≤109,m≤7n\leq 10^9,m\l ...
- luogu P2216 [HAOI2007]理想的正方形 递推+ST表
题意:有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 数据规模: (1)矩阵中的所有数都不超过1,000,000,000 (2)20% ...
- 组合数学 —— 组合数取模 —— 逆元与递推打表
[逆元求法] 1.要求:p 是质数 2.时间复杂度:O(n) 3.求解 的步骤: 1)通过循环,预先算好所有小于 N 的阶乘(%p)的结果,存到数组 fac[] 中 (fac[i] = i!%p) ...
- 递推DP URAL 1119 Metro
题目传送门 1 /* 2 题意:已知起点(1,1),终点(n,m):从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0): 3 递推DP:仿照JayYe,处理的很巧妙, ...
- UVA10943 How do you add【递推打表】
Larry is very bad at math - he usually uses a calculator, which worked well throughout college. Unfo ...
- Bailian3258 兔子产子【递推+打表】
3258:兔子产子 总时间限制: 1000ms 内存限制: 65536kB 描述 从前有一对长寿兔子,它们每一个月生一对兔子,新生的小兔子两个月就长大了,在第二个月的月底开始生它们的下一代小兔子,这样 ...
- Bailian2942 吃糖果【递推+打表】
2942:吃糖果 总时间限制: 1000ms 内存限制: 65536kB 描述 名名的妈妈从外地出差回来,带了一盒好吃又精美的巧克力给名名(盒内共有 N 块巧克力,20 > N >0).妈 ...
- HDU1290 重建希望小学【递推+打表】
重建希望小学 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
最新文章
- 9月21日科技联播:报告显示网约车案发率低于传统出租车;刘强东性侵案已移交美国检方...
- 使用jquery实现的计算器功能
- java的AutoCloseable接口
- 二分检索用途及复杂性_二分查找和三分查找哪个快?算法复杂度与常数无关?复杂度分析的常见误区...
- memcache 获取key的方法,查询session存储
- sqlalchemy 事务
- 中国摊铺设备市场趋势报告、技术动态创新及市场预测
- jQuery中的gt和lt
- ES(Elasticsearch)更改字段索引
- textarea 在 Chrome Safari FireFox 浏览器中禁用拖动和固定大小
- 【阿卡乐谱】【日常分享】超级强大的简谱-《大海啊,故乡》
- m4a录音文件损坏修复_m4a音频文件损坏修复!
- 市场调研报告-全球与中国船用下水推车市场现状及未来发展趋势
- 如何像打王者荣耀一样励志学习
- L1和L2简单易懂的理解
- Mac安装ffmpeg时 Failed to download resource quot;texi2htmlquot; 的解决办法
- 相约3.8!罗.姆EEPROM在线研讨会
- 团队项目-初步分工与计划安排
- 在Linux系统下载与安装Nginx
- 2020年第十一届蓝桥杯决赛Python组(真题+解析+代码):阶乘约数