Codeforces Round #815 (Div. 2) ABC

A - Burenka Plays with Fractions
https://codeforces.com/contest/1720/problem/A

题目大意:给出a,b,c,d,每次可以×任意数,问我们a/b,c/d要几次操作才可以相等?
input
8
2 1 1 1
6 3 2 1
1 2 2 3
0 1 0 100
0 1 228 179
100 3 25 6
999999999 300000000 666666666 100000000
33 15 0 84
output
1
0
2
0
1
1
1
1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        LL a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a==0&&c==0) cout<<"0"<<endl;
        else if(a==0) cout<<"1"<<endl;
        else if(c==0) cout<<"1"<<endl;
        else if(a*d==b*c) cout<<"0"<<endl;
        else if((a*d)>(b*c)&&((a*d)%(b*c)==0)) cout<<"1"<<endl;
        else if((a*d)<(b*c)&&((b*c)%(a*d)==0)) cout<<"1"<<endl;
        else cout<<"2"<<endl;
    }
    return 0;
}

B - Interesting Sum
https://codeforces.com/contest/1720/problem/B

题目大意:给定长度为n的数组a,让我们求a[1]到a[l-1],以及a[r+1]到a[n]的最大值-最小值
再加上被挖掉的那一部分的最大值以及最小值
input
4
8
1 2 2 3 1 5 6 1
5
1 2 3 100 200
4
3 3 3 3
6
7 8 3 1 1 8
output
9
297
0
14
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        sort(a+1,a+1+n);
        LL sum=a[n]+a[n-1]-a[1]-a[2];
        cout<<sum<<endl;
    }
    return 0;
}

C - Corners
https://codeforces.com/contest/1720/problem/C

题目大意:给定n*m的01矩阵,L操作是每次只要L三个位置上有1就可以进行全换0操作(注意:L 可以360°随意翻转)
input
4
4 3
101
111
011
110
3 4
1110
0111
0111
2 2
00
00
2 2
11
11
output
8
9
0
2
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
char a[M][M];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        int sum1=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            {
                cin>>a[i][j];
                if(a[i][j]=='1') sum1++;
            }
        //cout<<sum1<<endl;
        if(sum1==n*m) cout<<sum1-2<<endl;
        else
        {
            bool flag=false;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    if(a[i][j]=='0')
                    {
                        if(i-1>=1&&a[i-1][j]=='0') flag=true;
                        else if(i+1<=n&&a[i+1][j]=='0') flag=true;
                        else if(j+1<=m&&a[i][j+1]=='0') flag=true;
                        else if(j-1>=1&&a[i][j-1]=='0') flag=true;

                        else if(i-1>=1&&j-1>=1&&a[i-1][j-1]=='0') flag=true;
                        else if(i-1>=1&&j+1<=m&&a[i-1][j+1]=='0') flag=true;
                        else if(i+1<=n&&j-1>=1&&a[i+1][j-1]=='0') flag=true;
                        else if(i+1<=n&&j+1<=m&&a[i+1][j+1]=='0') flag=true;
                    }
                    if(flag==true) break;
                }
                if(flag==true) break;
            }
            if(flag==true) cout<<sum1<<endl;
            else cout<<sum1-1<<endl;
        }
    }
    return 0;
}
posted @ 2022-08-26 17:56  Vijurria  阅读(15)  评论(0编辑  收藏  举报