codeforces1392 E Omkar and Duck

这是一道交互题,给你一个数n,你要构造一个n*n的矩阵,然后电脑按照每次只能向下走或者向右走的规则从(1,1)走到(n,n)并计算经过的点值和。要你精确的给出唯一的路径。

看到唯一路径的确想到了2的幂,但是没把奇数行的数值全都化为零,导致这个唯一路径一直确定不了。

思路:把奇数行全赋值为0,偶数行则=2^(i+j-3);(从(2,1)为2^0开始)

如果现在k的某一位的值为1,并且x在奇数行,那么只能是x++。否则就是y++。

k的某一位为0也是这样判断。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#define ll long long
#define PI acos(-1.0)
#define F first
#define S second
#define pb push_back
#define debug(x); printf("debug%d
",x);
#define des(x); printf("des:%s
",x+1);
const ll INF=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
using namespace std;
const int N=1e6+5;
int n;
ll a[30][30];
int x,y,q;
ll k;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i&1)
            {
                printf("0%c",j==n?'
':' ');
            }
            else
            {
                printf("%lld%c",1LL<<(i+j-3),j==n?'
':' ');
            }
            fflush(stdout);
        }
    }
    scanf("%d",&q);
    while(q--)
    {
        scanf("%lld",&k);
        printf("%d %d
",1,1);
        x=1;
        y=1;
        fflush(stdout);
        for(int i=0;i<=2*n-3;i++)
        {
            if(k&1LL<<(i))
            {
                if(x&1)
                    x++;
                else
                    y++;
            }
            else
            {
                if(x&1)
                    y++;
                else
                    x++;
            }
            printf("%d %d
",x,y);
            fflush(stdout);
        }
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/switch-waht/p/13517118.html