Codeforces Round #664 (Div. 2) 补题记录

B. Boboniu Plays Chess

思路:
因为题目要求我们必须像车一样,只能跑同一行同一列
所以我们可以先跑自己当前行,然后从第一行开始,走S行路线,
即从第一行开始跑,然后再再绕到下一行,那么就不重不漏了

For循环模拟:

#include <bits/stdc++.h>
using namespace std;
int n,m,x,y;
int main()
{
    cin>>n>>m>>x>>y;
    cout<<x<<" "<<y<<endl;
    for(int i=1; i<=m; i++)
        if(i!=y)
        先输出这一行
            cout<<x<<" "<<i<<endl;
    int step = m;
    for(int i=1; i<=n; i++)
    枚举每一行 从第一行开始
    {
        if(i == x)
            continue;
        if(step ==m)
        {
            for(int j=m; j>=1; j--)
            蛇皮走位
                cout<<i<<" "<<j<<endl;
            step = 1;
        }
        else if(step == 1)
        {
            for(int j=1; j<=m; j++)
                cout<<i<<" "<<j<<endl;
            step = 1;
            step = m;
        }
    }

    return 0;
}

dfs处理:

#include <bits/stdc++.h>
using namespace std;
const int N = 210;
int n,m,sx,sy;
int ok[N][N],p[N*N],q[N*N];

void dfs(int x,int y,int c)
{
    int i;
    if(c>n*m)
    {
        for(int i=1;i<=n*m;i++)
            cout<<p[i]<<" "<<q[i]<<endl;
        exit(0);
    }
    for(int i=1;i<=n;i++)
    每行开始dfs
    if(!ok[i][y])
    {
        ok[i][y] = 1;
        p[c] = i ;
        q[c] = y;
        dfs(i,y,c+1);
        ok[i][y] = 0;
    }
    for(int i=1;i<=m;i++)
    if(!ok[x][i])
    {
        ok[x][i] = 1;
        p[c] = x;
        q[c] = i;
        dfs(x,i,c+1);
        ok[x][i] = 0;
    }
}
int main()
{
    cin>>n>>m>>sx>>sy;
    p[1]  = sx;
    q[1] =  sy;
    ok[sx][sy] = 1;
    dfs(sx,sy,2);
}

C.Boboniu and Bit Operations

第一次做这种题:
才知道2^10范围是如此的小 才1024

思路:
因为最后需要求的是C,而且范围还挺小所以我们可以直接枚举模拟

枚举代码:

#include <bits/stdc++.h>
using namespace std;
const int N  = 210;
int n,m;
int a[N],b[N];
int main()
{
    cin>>n>>m;
    ///emm 数据范围真的挺小的
    for(int i=1; i<=n; i++)
        cin>>a[i];
    for(int i=1; i<=m; i++)
        cin>>b[i];
    int flag1  = 0;
    int flag2 = 0;
    int ans = 0x3f3f3f3f;
    这里算是枚举了所有的C
    for(int i=0; i<(1<<10); i++)
    {
        flag1 = 1;
        枚举所有的a[j]
        for(int j=1; j<=n; j++)
        {
            flag2 = 0;
            枚举所有的b[k]
            for(int k=1; k<=m; k++)
                一个c[i] | c == c 也就是c[i] = 0
                if(((a[j]&b[k])|(i)) == i)
                {
                    flag2= 1;
                    break;
                }

                if(!flag2)
                {
                    flag1 = 0;
                    break;
                }

        }
        if(flag1) ans = min(ans,i);
    }
    cout<<ans<<endl;

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值