综合训练(1)+字符串

 A - Prefixes

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAX = 1e5+5;
int n,re,a_num,b_num;
string s;
int main()
{
   cin>>n;getchar();
   for(int i=1;i<=n;++i)
   {
        char t=getchar();
        if(t=='a') a_num++;
        if(t=='b') b_num++;
        if(i%2==0)
        {
            if(a_num<b_num) { re++;t='a';}
            else if(b_num<a_num) { re++;t='b';}
            a_num=0;
            b_num=0;
        }
        s+=t;
   }
   cout<<re<<endl;
   cout<<s<<endl;
    return 0;
}

B - Shooting

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#define MAX 1003
using namespace std;
int n,x,sum;
struct node
{
    int num;
    int id;
}a[MAX];
int cmp(node a,node b)
{
   return a.num>b.num;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i].num);
        a[i].id=i;
    }
    sort(a+1,a+1+n,cmp);
    int mins=0x3f3f3f3f;
    sum=1;x=1;
    for(int i=2;i<=n;++i)
    {
        sum+=a[i].num*x+1;x++;
    }
    printf("%d\n",sum);
    for(int i=1;i<=n;++i)
    {
        printf("%d ",a[i].id);
    }
    return 0;
}

C - White Sheet

#include<iostream>
using namespace std;
struct node
{
    int x1,y1,x2,y2;
}s[3];
string Check_a()
{
    if(s[2].x1<=s[0].x1&&s[2].x2>=s[0].x2 &&s[2].y1<=s[0].y1&&s[2].y2>=s[0].y2 ) return "NO";
	else if(s[1].x1<=s[0].x1&&s[1].x2>=s[0].x2 &&s[1].y1<=s[0].y1&&s[1].y2>=s[0].y2 ) return "NO";
	else if(max(s[1].x1,s[2].x1)<=s[0].x1&&s[0].x2<=min(s[1].x2,s[2].x2))
	{
		if(s[1].y1<=s[0].y1&&s[2].y2>=s[0].y2&&s[1].y2>=s[2].y1) return "NO";
		else if(s[2].y1<=s[0].y1&&s[1].y2>=s[0].y2&&s[2].y2>=s[1].y1) return "NO";
	}
    else if(max(s[1].y1,s[2].y1)<=s[0].y1&&s[0].y2<=min(s[1].y2,s[2].y2))
	{
		if(s[1].x1<=s[0].x1&&s[2].x2>=s[0].x2&&s[1].x2>=s[2].x1) return "NO";
		else if(s[2].x1<=s[0].x1&&s[1].x2>=s[0].x2&&s[2].x2>=s[1].x1) return "NO";
	}
	return "YES";
}
int main()
{
    for(int i=0;i<3;++i)
    {
        cin>>s[i].x1>>s[i].y1>>s[i].x2>>s[i].y2;
    }
    cout<<Check_a();
    return 0;
}

D - Swords

#include<iostream>
#include<algorithm>
#include<stdio.h>
const int MAX=2e6+7;
using namespace std;
long long n,large,j,sum,a[MAX],b[MAX],gcd;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    large=0;
    for(long long i=0;i<n;++i)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n);
    large=a[n-1];
    for(long long i=0;i<n;++i)
    {
        if(large==a[i])continue;
        b[j++]=large-a[i];
    }
    gcd=b[0];
    for(long long i=0;i<j;++i)
    {
        gcd=__gcd(gcd,b[i+1]);
    }
    printf("%lld %lld",(n*large-sum)/gcd,gcd);
    return 0;
}

E - Numerical Sequence (easy version)[前缀码,二分]💦

G - Wi-Fi[单调dp]💦

H - Text Reverse

#include<iostream>
#include<stack>
#include<stdio.h>
using namespace std;
char c;
int n;
int main()
{
    stack<char> s;
    scanf("%d",&n);getchar();
    while(n--)
    {
        while(1)
        {
            c=getchar();
            if(c==' '||c=='\n')
            {
                while(!s.empty())
                {
                    printf("%c",s.top());
                    s.pop();
                }
                cout<<c;
            }
            else
            {
                s.push(c);
            }
            if(c=='\n') break;
        }
    }
}

  

posted @ 2020-04-11 21:26  东坡肉肉君  阅读(435)  评论(0编辑  收藏  举报