zoukankan      html  css  js  c++  java
  • n=C(2,n)+k(构造)( Print a 1337-string)Educational Codeforces Round 70 (Rated for Div. 2)

    题目链接:https://codeforc.es/contest/1202/problem/D

    题意:

    给你一个数 n ( <=1e9 ),让你构造137713713.....(只含有1,3,7)的字符串使不同1337的子序列个数为n,而构造出来的字符串不能很长( <= 1e5)

    思路:

    这类构造题肯定是要先固定一种方式,我尝试了以 C(2,a)+C(2,b)+C(2,c)+... = n 的形式,发现不行。后来还是看了别人的代码,

    是以 C(2,m)+k 的形式组成 n,因为任意两个 n*(n-1)(n-1)*(n-2) 之间相差的数量不会大于( 2*31622 ),因为根号下1e931622

    所以总长度不会大于 2*31622 (这是k的最大长度)+31622 (这是m的最大长度) 刚好是 94868<1e5。

    所以答案就是  133+7(k个)+3333(m-2个)...7

      1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
      2 #include <cstdio>//sprintf islower isupper
      3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
      4 #include <iostream>//pair
      5 #include <fstream>
      6 #include <bitset>
      7 //#include <map>
      8 //#include<unordered_map>  https://codeforc.es/contest/1202/problem/D
      9 #include <vector>
     10 #include <stack>
     11 #include <set>
     12 #include <string.h>//strstr substr
     13 #include <string>
     14 #include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
     15 #include <cmath>
     16 #include <deque>
     17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
     18 #include <vector>//emplace_back
     19 //#include <math.h>
     20 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
     21 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
     22 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
     23 #define fo(a,b,c) for(register int a=b;a<=c;++a)
     24 #define fr(a,b,c) for(register int a=b;a>=c;--a)
     25 #define mem(a,b) memset(a,b,sizeof(a))
     26 #define pr printf
     27 #define sc scanf
     28 #define ls rt<<1
     29 #define rs rt<<1|1
     30 void swapp(int &a,int &b);
     31 double fabss(double a);
     32 int maxx(int a,int b);
     33 int minn(int a,int b);
     34 int Del_bit_1(int n);
     35 int lowbit(int n);
     36 int abss(int a);
     37 //const long long INF=(1LL<<60);
     38 const double E=2.718281828;
     39 const double PI=acos(-1.0);
     40 const int inf=(1<<29);
     41 const double ESP=1e-9;
     42 const int mod=(int)1e9+7;
     43 const int N=(int)1e6+10;
     44 
     45 int main()
     46 {
     47     int T;
     48     sc("%d",&T);
     49     while(T--)
     50     {
     51         int n;
     52         sc("%d",&n);//C(2,n)+k;
     53         int k=0,m=0;
     54         for(int i=n;i>=1;--i)
     55         {
     56             k=n-i;
     57             int j=(int)sqrt(2*i);
     58             long long temp=j*(j+1);
     59             if(2*i==temp)
     60             {
     61                 m=j+1;
     62                 break;
     63             }
     64         }
     65         pr("133");
     66         fo(i,1,k)
     67             pr("7");
     68         fo(i,1,m-2)
     69             pr("3");
     70         pr("7");
     71         cout<<endl;
     72     }
     73     return 0;
     74 }
     75 
     76 /**************************************************************************************/
     77 
     78 int maxx(int a,int b)
     79 {
     80     return a>b?a:b;
     81 }
     82 
     83 void swapp(int &a,int &b)
     84 {
     85     a^=b^=a^=b;
     86 }
     87 
     88 int lowbit(int n)
     89 {
     90     return n&(-n);
     91 }
     92 
     93 int Del_bit_1(int n)
     94 {
     95     return n&(n-1);
     96 }
     97 
     98 int abss(int a)
     99 {
    100     return a>0?a:-a;
    101 }
    102 
    103 double fabss(double a)
    104 {
    105     return a>0?a:-a;
    106 }
    107 
    108 int minn(int a,int b)
    109 {
    110     return a<b?a:b;
    111 }
  • 相关阅读:
    mysql排序对空值的处理
    Lambda表达式要点
    nginx Provisional headers are shown
    JAVA使用POI如何导出百万级别数据(转)
    idea 自定义注释模板
    idea使用配置
    Caused by: java.util.concurrent.RejectedExecutionException: Thread pool is EXHAUSTED! Thread Name:
    Java HotSpot(TM) 64-Bit Server VM warning
    dubbo-admin管理平台搭建
    zookeeper安装
  • 原文地址:https://www.cnblogs.com/--HPY-7m/p/11333199.html
Copyright © 2011-2022 走看看