Live2d Test Env

ZOJ2185 简单分块 找规律

初步找大概位置,然后找精确位置,算是简单化的分块吧!


#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
int c[5000];
int num=0;
void _get()
{
      int  k=1,m;
      while(true){
        m=(k+1)*k/2;
        if(m>10000000) break;
        c[++num]=m;
        k++;
    }
}
void _work(int v)
{
     int k=num,a,b,V=v;
     for(int i=2;i<=num;i++)
      if(c[i-1]<=v&&c[i]>v) {k=i-1;break;}
     if(k%2==1)
     {
        a=1;b=k;
        if(c[k]==v) { printf("TERM %d IS %d/%d\n",V,a,b); return ;}
        b++;v--;
        if(c[k]==v) { printf("TERM %d IS %d/%d\n",V,a,b); return ;}
        while(b>1)
        {
                a++;b--;v--;
               if(c[k]==v) {printf("TERM %d IS %d/%d\n",V,a,b); return;}
        }     
        }
        else {
        a=k;b=1;
        if(c[k]==v) { printf("TERM %d IS %d/%d\n",V,a,b); return ;}
         a++;v--;
        if(c[k]==v) { printf("TERM %d IS %d/%d\n",V,a,b); return ;}
        while(a>1)
        {
                a--;b++;v--;
               if(c[k]==v) {printf("TERM %d IS %d/%d\n",V,a,b); return;}
        }     
    }
}
int main()
{
    int n;
    _get();
     while(~scanf("%d",&n))
      _work(n);
    return 0;
}

 


posted @ 2017-09-27 21:06  nimphy  阅读(120)  评论(0编辑  收藏  举报