HDU 5847 构造
来源:互联网 发布:xbox无法连接网络 编辑:程序博客网 时间:2024/05/28 18:43
Different Sums
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Special Judge
Problem Description
A subsum of the sequence is sum of one or more consecutive integers of it. You are given an integer N (1≤N≤2000 ). Your task is to make a sequence of integers which are less than 3(N+6) , such that its all subsums (N(N+1)/2 in total) are different from each other.
Input
There are several test cases.
The first line of the input contains an integerT(1≤T≤200) , the number of test cases.
Each of the nextT lines contains an integer ,N the length of the sequence.
The first line of the input contains an integer
Each of the next
Output
For each test case, print one line with N space separated integers representing your sequence.
If multiple solutions exist, any of them will be accepted.
If multiple solutions exist, any of them will be accepted.
Sample Input
225
Sample Output
1 21 2 4 8 16题意:给你一个n,找出一个长度为n的序列,数都为正整数且不超过3*n+18,使得他们的子序列和各不相同。题解:我是个翻译员23333,具体为什么这样做我也不会QAQ。翻译:寻找一个素数p刚好大于n,定义s[i]为前i个数的和,再找出一个x,0<=x<pS[i] = 2 * i * p + (i * (i+1) / 2 * x) % p
定义r[i] = (i * (i+1) / 2 * x) % p.
如果s[i]-s[j]=s[k]-s[l] 那么i-j=k-l 因为|r[i]-r[j]|<p且|r[k]-r[l]|<p
而且(r[i]-r[j]-r[k]+r[l])能被p整除,所以i+j=k+l。
也就是说i=k且j=l
对于所有的6<=n<=2000,我们只要for一下寻找满足每个数都小于3*n+18的x就可以了
然后我们从1for到p-1就行了,不用去管0
ps:朝鲜ACM best ACM 强无敌 这题全场744发没一个队过
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int s[2005];int main(){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);int i,j,p;for(p=n+1;;p++){int flag=1;for(j=2;j*j<=p;j++){if(p%j==0){flag=0;break;}}if(flag)break;}int x;for(x=1;x<p;x++){for(i=1;i<=n;i++){s[i]=2*i*p+(i*(i+1)/2*x)%p;if(s[i]-s[i-1]>=3*n+18)break;}if(i==n+1)break;} for(i=1;i<n;i++){printf("%d ",s[i]-s[i-1]);}printf("%d\n",s[i]-s[i-1]);}return 0;}
0 0
- HDU 5847 构造
- [构造 数学推导] HDU 5847 Different Sums
- hdu 3306 矩阵构造
- HDU 3306 矩阵构造
- hdu 3483 矩阵构造
- hdu 4731 构造
- hdu 1588 构造矩阵
- HDU 4781 构造
- HDU - 5301(构造)
- HDU 1757 矩阵构造
- HDU 4850 (构造 dfs)
- HDU 5386 构造
- hdu 5740(构造,KM)
- hdu 5874 构造
- HDU 6030(构造矩阵)
- hdu 5573贪心构造
- hdu 6150 思维构造
- HDU 5847 Different Sums (构造+数学+打表)
- firefox历史版本下载路径
- KMP代码实现
- 第二周《C语言及程序设计》实践项目33 三种循环语句
- 设计模式C++版:第二式抽象工厂
- 图数据库Neo4j使用
- HDU 5847 构造
- xftp 登录远程服务器
- Effective Modern C++ 条款9 用别名声明(alias declaration)代替typedef
- 推理集 —— 物质与成分及性质的研究
- SDUT2107图的深度遍历
- POJ 3256 Cow Picnic SPFA
- eclipse在线安装FatJar插件失败解决方案
- 使用 Python 创建你自己的 Shell (上)
- FP-Growth 算法MapReduce 关联规则算法