zoukankan      html  css  js  c++  java
  • [题解]Print a 1337-string...-数学(codeforces 1202D)

    题目链接:https://codeforces.com/problemset/problem/1202/D


    题意:

    构造一串只由 ‘1’,‘3’,‘7’ 组成的字符串,使其 ‘1337’ 子序列数量为n

    思路:

     构造 ‘13377733337’ 类型的字符串,使 C(m,2)+k=n

    k为中间 ‘7’ 的数量,C(m,2)为中间 ‘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 }
    正因为是最弱,所以才理解智慧之强
  • 相关阅读:
    python基础 2
    python基础 1
    进程
    进程作业
    上海python14期第二次阶段性考试
    面向对向之元类
    面向对向
    笔试题
    模块(2)
    模块作业
  • 原文地址:https://www.cnblogs.com/Yanick/p/11330923.html
Copyright © 2011-2022 走看看