标签:ORC lan alt tps pre problems 数学 cout turn
题目链接:https://codeforces.com/problemset/problem/1202/D
题意:
构造一串只由 ‘1’,‘3’,‘7’ 组成的字符串,使其 ‘1337’ 子序列数量为n
思路:
构造 ‘13377733337’ 类型的字符串,使 C(2,m)+k=n
k为中间 ‘7’ 的数量,C(2,m)为中间 ‘3’ 的数量
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 #define rep(i,m,n) for(int i=m;i<n;i++) 5 const int N = 2e5+5; 6 ll a[100006],b[100006]; 7 8 int main(){ 9 ios::sync_with_stdio(false); 10 cin.tie(0); 11 cout.tie(0); 12 int t,n; 13 cin>>t; 14 while(t--){ 15 cin>>n; 16 int num=sqrt(n*2),x,y; 17 rep(i,num,2*n+1){ 18 if(i*(i-1)<=2*n) 19 x=i,y=n-i*(i-1)/2; 20 else 21 break; 22 } 23 cout<<"133"; 24 rep(i,0,y) 25 cout<<"7"; 26 rep(i,0,x-2) 27 cout<<"3"; 28 cout<<"7"<<endl; 29 } 30 return 0; 31 }
[题解]Print a 1337-string...-数学(codeforces 1202D)
标签:ORC lan alt tps pre problems 数学 cout turn
原文地址:https://www.cnblogs.com/Yanick/p/11330923.html