2017多校-7

来源:互联网 发布:网络有什么好项目投资 编辑:程序博客网 时间:2024/05/16 06:28

Euler theorem
http://acm.hdu.edu.cn/showproblem.php?pid=6124
比赛时我用计算器算了前几个找到了规律,22334455…….

#include <iostream>#include <cstdio>using namespace std;int main(){    int t;    scanf("%d",&t);    while(t--)    {        int a;        scanf("%d",&a);        int s;        if(a%2==1)        {            s=(a+1)/2+1;        }        else        {            s=a/2+1;        }        printf("%d\n",s);    }    return 0;}

看了别人的题解,其实一个式子就可以了s=(a-1)/2+2

Kolakoski
http://acm.hdu.edu.cn/showproblem.php?pid=6130
时间给的比较多,打表就可以了

#include <iostream>#include <cstdio>#define LL long longusing namespace std;const int maxn=1e7+10;int a[maxn];int main(){    a[1]=1;a[2]=a[3]=2;    int k=4,num=1;    for(int i=3;k<=maxn;i++)    {        for(int j=1;j<=a[i];j++)        {            a[k]=num;            k++;        }        num=(num==1)?2:1;    }    int t,n;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        printf("%d\n",a[n]);    }    return 0;}
原创粉丝点击