Codeforces Round #648 (Div. 2) A、B、C

题目链接:https://codeforces.ml/contest/1365
A、Matrix Game在这里插入图片描述
思路

很简单一个博弈问题,用数组记录每一行每一列是否被占用,找出能放置棋子的点,看两个人谁最后一个放即可,具体看代码。

代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f3f
#define ll long long
const int N = 2e5 + 10;
int a[55][55];
int x[100],y[100];
int main()
{
    int n,m,t;
    cin>>t;
    while(t--)
    {
        memset(x,0,sizeof x);
        memset(y,0,sizeof y);
        int sum=0;
        cin >> n >> m;
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++){
                cin >> a[i][j];
                if(a[i][j]==1)
                    x[i]=y[j]=1;
            }
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                if(x[i]==0&&y[j]==0)
                {
                    sum++;
                    x[i] = y[j] = 1;
                }
            }
        }
        if(sum%2)
            cout << "Ashish" <<endl;
        else
            cout << "Vivek" <<endl;
    }
    return 0;
}
B、Trouble Sort

在这里插入图片描述

思路

思维题,只要种类为0和种类为1的数都有,那么一定可以成功排序,如果全都是0或者全都是1的话,看是否为递增序列即可。

代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f3f
#define ll long long
int x[505],y[505];
int main()
{
    int n,m,t;
    cin>>t;
    while(t--)
    {
        cin >> n;
        bool flag = 0;
        int b0=0,b1=0;
        for(int i=0; i<n; i++)
        {
            cin >> x[i];
            if(i>0&&x[i]<x[i-1])
                flag = 1;
        }
        for(int i=0; i<n; i++)
        {
            cin >> y[i];
            if(y[i])
                b1++;
            else
                b0++;
        }
        if(flag&&(!b1||!b0))
        {
            cout << "No" <<endl;
            continue;
        }else{
            cout << "Yes" <<endl;
        }
    }
    return 0;
}
C、Rotation Matching

在这里插入图片描述

思路

这个题当时没AC出了,纯暴力超时,换了种算法也WA了,大题思路是对的。
a、b数组,记录b数组元素与a数组元素位置的差值,哪个差值出现的次数最大即出现的配对数目。

代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f3f
#define ll long long
const int N=2e5+5;
int a[N],b[N],pd[N];
map<int,int> ma;
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        pd[a[i]]=i;
    }
    for(int j=1; j<=n; j++)
        cin>>b[j];
    for(int i=1; i<=n; i++)
    {
        int dis=pd[b[i]]-i;
        if(dis<0)
            dis+=n;
        ma[dis]++;
    }
    int ans=0;
    for(auto it:ma)
    {
        ans=max(ans,it.second);
    }
    cout<<ans<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浅梦曾倾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值