首页 > 其他 > 详细

Codeforces Round #624 (Div. 3)

时间:2020-02-25 15:39:01      阅读:68      评论:0      收藏:0      [点我收藏+]

Codeforces Round #624 (Div. 3)

A.Add Odd or Subtract Even:

对于一个数,你可以执行操作:加一个奇数,或者减一个偶数,给出两个数a,b,判断最少执行几次操作可以由a得到b。分情况讨论即可。

/**********************************************************
* @Author:             Maple
* @Date:               2020-02-24 22:37:36
* @Last Modified by:   Maple
* @Last Modified time: 2020-02-24 22:39:42
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn=1000;


int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.in","r",stdin);
    #endif
    FAST
    int t;
    cin>>t;
    while(t--){
        int a,b;
        cin>>a>>b;
        if(a<b){
            int x=b-a;
            if(x&1)
                cout<<"1"<<endl;
            else
                cout<<"2"<<endl;
        }
        else if(a==b)
            cout<<"0"<<endl;
        else{
            int x=a-b;
            if(x&1)
                cout<<"2"<<endl;
            else
                cout<<"1"<<endl;
        }
    }
    return 0;
}

B.WeirdSort

题意:给出一个数组a有n个数,再给出一个长度为m的数组p,对于p中每一个数,pi=x,则a数组中ax和a(x+1)可以交换。判断给出的p数组能否实现将a数组从小到大排序。冒泡排序题,排序过程加入判断即可。

/**********************************************************
* @Author:             Maple
* @Date:               2020-02-24 22:44:28
* @Last Modified by:   Maple
* @Last Modified time: 2020-02-24 22:53:24
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn=111;
int n,m,a[maxn],p[maxn];

void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
    return;
}

bool bubleok(){
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-1-i;j++){
            if(a[j]>a[j+1]){
                if(p[j]){
                    swap(a[j],a[j+1]);
                }
                else
                    return false;
            }
        }
    }
    return true;
}

void piaint(){
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.in","r",stdin);
    #endif
    FAST
    int t;
    cin>>t;
    while(t--){
        memset(p,0,sizeof(p));
        cin>>n>>m;
        for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=0;i<m;i++){
            int x;
            cin>>x;
            p[x-1]=1;
        }
        bubleok()?cout<<"YES"<<endl:cout<<"NO"<<endl;
        // /piaint();
    }   
    return 0;
}

C.Perform the Combo

题意,有一个长度为n的字符串和一个长度为m的数组p,对于p数组中的数,如果pi=x意味着,当顺次使用到字符串m位置时,会出现错误,所以,要从头开始,要求计算出26个小写字母各被用到多少次。用前缀和维护字符串中i位置之前各个字母各出现了多少次,然后遍历数组p累计p中描述位置的字母出现次数计科,最后加上完整使用一整个字符串会用多少字符。

/**********************************************************
* @Author:             Maple
* @Date:               2020-02-24 23:03:43
* @Last Modified by:   Maple
* @Last Modified time: 2020-02-24 23:22:50
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn=2e5+100;
int n,m,lsum[30][maxn],ans[maxn];
char str[maxn];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.in","r",stdin);
    #endif
    int t;
    scanf("%d",&t);
    while(t--){
        for(int i=0;i<26;i++)
            lsum[i][0]=0;
        scanf("%d%d",&n,&m);
        scanf("%s",str+1);
        for(int i=1;i<=n;i++){
            for(int j=0;j<26;j++)
                lsum[j][i]=lsum[j][i-1];
            lsum[int(str[i]-'a')][i]++;
        }
        for(int i=0;i<m;i++){
            int p;
            scanf("%d",&p);
            for(int j=0;j<26;j++){
                ans[j]+=lsum[j][p];
            }
        }
        for(int i=0;i<26;i++){
            ans[i]+=lsum[i][n];
        }
        for(int i=0;i<26;i++){
            printf("%d ",ans[i]);
            ans[i]=0;
        }
        printf("\n");
    }
    return 0;
}

注意数据量较大采用高效输入模式

D.Three Integers:

题意,给出三个数,a,b,c,每个数可以执行加或减1操作无数次,但是不能出现非正数,求最少执行多少次可以实现b%a==0&&c%b==0 ,直接在范围内搜索a的可能值,b的可能值和c的可能值,注意开大上限,防止漏掉情况。

/**********************************************************
* @Author:             Maple
* @Date:               2020-02-25 11:22:43
* @Last Modified by:   Maple
* @Last Modified time: 2020-02-25 11:26:47
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-(x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn=1000;
int a,b,c;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.in","r",stdin);
    #endif
    FAST
    int t;
    cin>>t;
    while(t--){
        int ans=INF,wa,wb,wc;
        cin>>a>>b>>c;
        for(int i=1;i<=20000;i++){
            for(int j=i;j<=20000;j+=i){
                for(int k=j;k<=20000;k+=j){
                    int mid=abs(a-i)+abs(b-j)+abs(c-k);
                    if(mid<ans){
                        ans=mid;
                        wa=i;
                        wb=j;
                        wc=k;
                    }
                }
            }
        }
        cout<<ans<<endl;
        cout<<wa<<" "<<wb<<" "<<wc<<endl;
    }
    return 0;
}

Codeforces Round #624 (Div. 3)

原文:https://www.cnblogs.com/LeafLove/p/12361984.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!