HDU 5334(Virtual Participation-(A+C+1)(B+C+1)=K+(1+C)^2-C)
来源:互联网 发布:js 日期转时间戳 编辑:程序博客网 时间:2024/04/30 10:00
Virtual Participation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 886 Accepted Submission(s): 257
Special Judge
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he asks rikka to have some practice on codeforces. Then she opens the problem B:
Given an integerK , she needs to come up with an sequence of integers A satisfying that the number of different continuous subsequence of A is equal to k .
Two continuous subsequencesa, b are different if and only if one of the following conditions is satisfied:
1. The length ofa is not equal to the length of b .
2. There is at least onet that at≠bt , where at means the t -th element of a and bt means the t -th element of b .
Unfortunately, it is too difficult for Rikka. Can you help her?
Given an integer
Two continuous subsequences
1. The length of
2. There is at least one
Unfortunately, it is too difficult for Rikka. Can you help her?
Input
There are at most 20 testcases,each testcase only contains a single integerK (1≤K≤109)
Output
For each testcase print two lines.
The first line contains one integersn (n≤min(K,105)) .
The second line containsn space-separated integer Ai (1≤Ai≤n) - the sequence you find.
The first line contains one integers
The second line contains
Sample Input
10
Sample Output
41 2 3 4
Author
XJZX
Source
2015 Multi-University Training Contest 4
Recommend
wange2014 | We have carefully selected several similar problems for you: 5416 5415 5414 5413 5412
假设答案只有A个1,B个2,C个3
则原题要找A+B+C<=Min(K,10^5) 且 A+B+C+AB+BC+AC=K 的解
右边方程移项得,(A+C+1)(B+C+1)=K+(1+C)^2-C
#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (1000000+10)typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}void work(ll k,ll &A,ll &B,ll &C){A=B=C=1;while (1){int K2=k+(1+C)*(1+C)-C;for(ll x=(ll)(sqrt(K2));x>=C+1;x--) {if (K2%x==0) {A=x-C-1,B=K2/x-C-1; if (A+B+C>100000) continue;return; }}C++;}} int main(){//freopen("H.in","r",stdin);ll k;while (cin>>k) {if (k==1) {puts("1");puts("1");continue;} else if (k==2) {puts("2");puts("1 1");} else if (k<=100000){printf("%d\n",k);For(i,k-1) printf("1 ");printf("1\n");} else {ll A,B,C=0;work(k,A,B,C);printf("%d\n",A+B+C);bool flag=0;For(i,A) {if (!flag) flag=1;else printf(" ");printf("1");}For(i,B) {if (!flag) flag=1;else printf(" ");printf("2");}For(i,C) {if (!flag) flag=1;else printf(" ");printf("3");}printf("\n");}}return 0;}
0 0
- HDU 5334(Virtual Participation-(A+C+1)(B+C+1)=K+(1+C)^2-C)
- 关于 T(n) = a*T(n/b)+c*n^k;T(1) = c
- Virtual Judge Contest 1-B-C
- 当a=1,b=2,c=3时,if(a>c)b=a;a=c;c=b;的执行结果详解
- hdu--2504 a,b,c (a,c)=b,已知a,b求c
- hdu-4704 (a^b)%c
- HDU 5334 Virtual Participation
- a的b次方对c取模(1=<a,b,c<=1000000000)
- c = ( (++a) + (b++) );
- A=B+C
- max = (a>b) ? (c>d ? 1 : 2) : 3
- Codeforces Beta Round #1 A B C
- Codeforces Beta Round #1 A B C
- 第1题:A+B+C问题
- Codeforces Beta Round #1 A,B,C
- Codeforces Beta Round #1 A,B,C
- Codeforces Beta Round #1 A,B,C
- Codeforces Beta Round #1 A,B,C
- HDOJ 1272 小希迷宫 (并查集)
- C++基础---string类的capacity/max_size/size/length/empty/reserve/resize
- hdu 5411 CRB and Puzzle 矩阵快速幂
- 图数据库之neo4j-jdbc的使用
- HDU 4705 Y (树形DP)
- HDU 5334(Virtual Participation-(A+C+1)(B+C+1)=K+(1+C)^2-C)
- ACdream 1073
- 115个Java面试题和答案——终极列表(上)
- 黑马程序员——String类和基本数据类型包装类
- 微信记录恢复软件MMRecovery下载与使用方法
- 115个Java面试题和答案——终极列表(下)
- 黑马程序员-[C语言]第三篇:指针总结
- 在VirtualBox中安装Ubuntu 的增强工具包
- 杭电1557