Codeforces April Fools Contest 2017

来自FallDream的博客,未经允许,请勿转载,谢谢。

-----------------------------------------------------------

听学长说了这场比赛十分有意思,所以来玩玩。   学长真的强,啥都会,全程听正解然后码代码.....

A.Numbers Joke

只有一个样例,输入3输出27  机智的学长瞬间就在OEIS上找到了

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<queue>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int s[]={4,22,27,58,85,94,121,166,202,265,274,319,346,355,378,382,391,438,454,483,517,526,535,562,576,588,627,634,636,645,648,654,663,666,690,706,728,729,762,778};

int main()
{
    int n=read();
    cout<<s[n-1];
    return 0;
}

B.Kids' Riddle

只给输入输出  input 11 output  2   input14output0    input61441output2    input571576output10    input2128506output3

我也不知道学长是怎么发现的,正解是转换成16进制,然后数圈圈(对,你没看错)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<queue>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int n,ans=0;
const int s[16]={1,0,0,0,1,0,1,0,2,1,1,2,0,1,0,0};
int main()
{
    int x=read();if(!x)return 0*puts("1");
    while(x)
    {
        int a=x%16;
        ans+=s[a];
        x/=16;
    }
    cout<<ans;
    return 0;
}

C.INTERCALC

当场就念了一首诗

DO YOU EXPECT ME TO FIND THIS OUT?

WHAT BASE AND/XOR LANGUAGE INCLUDES string?

DON'T BYTE OF MORE THAN YOU CAN CHEW

YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR

SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD

THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!

I HAVE NO ARRAY AND I MUST SCREAM

ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE

我们发现它是藏头的,其实表达的是

FIND/FIGURE OR/XOR OF/OFF LARGEST/LAWS AND/WAND LAST/NEXT ARRAY/FILE ELEMENTS/VARIABLES

find xor of largest and last array elements

所以找出最大的和最后一个异或一下输出

#include<cstdio>
#include<iostream>
using namespace std;
int n,x,mx=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>x,mx=max(mx,x);
    cout<<(x^mx);
    return 0;
}

D.Touchy-feely Plaindromes

根据样例和题目判断,最后的结论是根据盲文判断是否对称...

 

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;

int s[]={8,-1,-1,-1,6,9,4,-1,0,5};
char st[12313];

int main()
{
    scanf("%s",st+1);int n=strlen(st+1);
    for(int i=1,j=n;i<j;i++,j--)
        if(st[i]!=st[j]&&s[st[i]-'0']!=st[j]-'0') return 0*puts("No");
    if(n&1){if(st[n/2+1]!='3'&&st[n/2+1]!='7')return 0*puts("No");}
    puts("YES");
    return 0;
}

E.Twisted Circuit

第二列从上到下表示异或、或、与和异或,然后直接算

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<queue>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int s[15];

int main()
{
    int a=read(),b=read(),c=read(),d=read();
    cout<<(((a^b)&(c|d))^((b&c)|(a^d)));
    return 0;
}

F.Crunching Numbers Just for You

题意:有n个顾客有n个数,你要把给定的n<=10个数排序好。

但是排序完出现rejected的情况,这时候看最后一句话

Remember, this is a very important feature, and you have to make sure the customers appreciate it!

所以顾客不想那么快结束,你要卡卡时间就行了。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<queue>
#include<algorithm>
#include<ctime>
#include<map>
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int a[132123];


int main()
{
    int n=read();time_t start = clock();
    for(int i=1;i<=n;i++)a[i]=read();
    sort(a+1,a+n+1);
    while((double)(clock()-start)/CLOCKS_PER_SEC<1.9);
    for(int i=1;i<=n;i++) cout<<a[i]<<" ";
    return 0;
}

F.给定一个表达式求值,输出一份BrainFuck语言写的可以算出答案的代码。

先算出答案,然后按照BrainFuck语言的一套理论,+表示计数器+1,-表示计数器-1,.(点)表示输出计数器的asc码对应的字符。所以+48之后随便输出呗。

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;

char st[1231000];
int op[1231231],num[12313],cnt=0;

int calc(int l,int r)
{
    int x=0;
    for(int i=l;i<=r;i++)
        x=x*10+st[i]-'0';
    return x;
}

void work(int&th,int x)
{
    int to=x+48;
    while(th>to)th--,printf("-");
    while(th<to)th++,printf("+");
    printf(".\n");
}

int main()
{
    scanf("%s",st+1);int pre=0;
    for(int i=1;st[i];i++)
    {
        if(st[i]=='+'||st[i]=='-')
        {
            op[++cnt]=(st[i]=='+')?1:2;
            num[cnt]=calc(pre+1,i-1);
            pre=i;
        }
    }
    num[++cnt]=calc(pre+1,strlen(st+1));
    int x=num[1];
    for(int i=1;i<cnt;i++)
    {
        if(op[i]==1)x=x+num[i+1];
        else x=x-num[i+1];
    }
    int th=0;cnt=0;
    if(!x) {work(th,0);return 0;}
    while(x)
    {
        num[++cnt]=x%10;x/=10;
    }
    for(int i=cnt;i;i--)
        work(th,num[i]);
    return 0;
}

 

posted @ 2017-04-01 12:19  FallDream  阅读(525)  评论(0编辑  收藏  举报