竹園論壇

標題: a828 - 間隔數 ( number ) [打印本頁]

作者: Sylveon    時間: 2014-6-24 08:12
標題: a828 - 間隔數 ( number )
原題:http://zerojudge.tw/ShowProblem?problemid=a828
AC:http://zerojudge.tw/Submissions?problemid=a828&account=lfs92002

可以發現一個二位數反覆的長度能決定一個間隔數列,可以推出長度為N的間隔數恰有81個,就可以移此類推求出第N個間隔數


ACCODE
@code
  • /**********************************************************************************/
  • /*  Problem: a828 "間隔數 ( number )" from 102北市賽                        */
  • /*  Language: CPP (502 Bytes)                                                     */
  • /*  Result: AC(24ms, 236KB) judge by this@ZeroJudge                               */
  • /*  Author: lfs92002 at 2014-06-23 21:11:00                                       */
  • /**********************************************************************************/


  • #include<cstdio>
  • using namespace std;
  • inline void put_min_int(int i)
  • {
  •     int e=i/10;
  •     if(e!=0){
  •         putchar('0'+e);
  •         i-=e*10;
  •     }
  •     putchar('0'+i);
  • }
  • int main()
  • {
  •     int n,p,q,i,j,k,o;
  •     int tab[81];
  •     int *tmp=tab;
  •     for(i=1;i<=9;++i){
  •         k=10*i;
  •         for(j=0;j<=9;++j)
  •             if(i!=j)
  •                 *(tmp++)=k+j;
  •     }
  •     while(~scanf("%d",&n)){
  •         --n;
  •         q=n/81;
  •         p=n-q*81;
  •         q+=3;
  •         k=q>>1;
  •         o=tab[p];
  •         for(i=0;i<k;++i)
  •             put_min_int(o);
  •         if(q&1)
  •             put_min_int(o/10);
  •         putchar('\n');
  •     }
  • }


  • RANK版
    @code
  • /**********************************************************************************/
  • /*  Problem: a828 "間隔數 ( number )" from 102北市賽                        */
  • /*  Language: CPP (640 Bytes)                                                     */
  • /*  Result: AC(8ms, 1.4MB) judge by this@ZeroJudge                                */
  • /*  Author: lfs92002 at 2014-06-23 21:33:44                                       */
  • /**********************************************************************************/


  • #include<cstdio>
  • using namespace std;
  • char buf[10000000],*ptr;
  • int main()
  • {
  •     register int i,j,k,o;
  •     int n,p,q;
  •     int tab[81]={10,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31,32,34,35,36,37,38,39,40,41,42,43,45,46,47,48,49,50,51,52,53,54,56,57,58,59,60,61,62,63,64,65,67,68,69,70,71,72,73,74,75,76,78,79,80,81,82,83,84,85,86,87,89,90,91,92,93,94,95,96,97,98};
  •     while(~scanf("%d",&n)){
  •         --n;
  •         q=n/81;
  •         p=n-q*81;
  •         q+=3;
  •         k=q>>1;
  •         o=tab[p];
  •         j=o/10;
  •         o=o-j*10+'0';
  •         j+='0';
  •         ptr=buf;
  •         for(i=0;i<k;++i){
  •             *(ptr++)=j;
  •             *(ptr++)=o;
  •         }
  •         if(q&1)
  •             *(ptr++)=j;
  •         *(ptr++)=0;
  •         puts(buf);
  •     }
  • }









  • 歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2