AtCoder Beginner Contest 247 ABCDE

很久没打abc了,还是临时创的号。😂

A - Move Right

题目大意:给定一个长度为4的字符串,右移一位前面补个0,原个数输出。 

#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    string s;
    cin>>s;
    cout<<"0";
    for(int i=0;i<s.size()-1;i++)
        cout<<s[i];
    return 0;
}

B - Unique Nicknames

题目大意:一个人有两个名儿,我要在他的两个名儿里面选出来一个当作绰号,不能出现喊这个绰号出现多个人应答的情况。

有wa点 :一个人两名儿都叫一样的

#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
struct node
{
    string a,b;
}s[200200];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int t;
    cin>>t;
    map<string,int> mp;
    for(int i=1;i<=t;i++)
    {
        cin>>s[i].a>>s[i].b;
        mp[s[i].a]++;
        mp[s[i].b]++;
    }
    bool flag=true;
    for(int i=1;i<=t;i++)
    {
        if(mp[s[i].a]>=2&&mp[s[i].b]>=2)
        {
            if(s[i].a==s[i].b)
            {
                if(mp[s[i].a]==2) continue;
                else
                {
                    flag=false;
                    break;
                }
            }
            else
            {
                flag=false;
                break;
            }
        }
    }
    if(flag==true) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

C - 1 2 1 3 1 2 1

题目大意:(叠奥利奥??)

#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n==1) cout<<"1"<<endl;
    else if(n==2) cout<<"1 2 1"<<endl;
    else if(n==3) cout<<"1 2 1 3 1 2 1"<<endl;
    else if(n==4) cout<<"1 2 1 3 1 2 1 4 1 2 1 3 1 2 1"<<endl;
    else if(n==5) cout<<"1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1"<<endl;
    else
    {
        string s="1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1";
        int a=6;
        while(1)
        {
            string c=s;
            s+=" ";
            s+=to_string(a);
            s+=" ";
            s+=c;
            if(a==n) break;
            else a++;
        }
        cout<<s<<endl;
    }
    return 0;
}

D - Cylinder

题目大意:队列,1表示每次从队尾插入c个x,2表示每次从队头取c个数字加起来然后输出。

开long long

要仔细昂! 

#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long LL;
struct node
{
    LL idx;
    LL sum;
}a[500200];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL n;
	cin>>n;
	LL k=1;
	LL flag=1;
	for(int i=1;i<=n;i++)
    {
        int num;
        cin>>num;
		if(num==1)
        {
            LL x,c;
            cin>>x>>c;
            a[k].idx=x;
            a[k].sum=c;
            k++;
		}
		else
		{
		    LL res=0;
		    LL c;
			cin>>c;
			while(c)
			{
				if(c<a[flag].sum)
				{
					res+=c*a[flag].idx;
					a[flag].sum-=c;
					c=0;
					break;
				}
				else
				{
				    c-=a[flag].sum;
					res+=a[flag].sum*a[flag].idx;
					flag++;
				}
			}
			cout<<res<<endl;
		}
	}
	return 0;
}

flag是全局变量,放局部变量不wa才怪嘞!

E - Max Min

题目大意:给定一个长度为n的数组a,再给出最大值x最小值y,问我们随便截取一个长度[l , r ],这个区间内的最大值就是x,最小值就是y。这样的区间个数有多少?

acwing有一道类似的,记得好像是暴力写法,搬到这儿来结果就tle了(妥妥的)

tle写法:

#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long LL;
LL a[200200];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL n,maxn,minn;
    cin>>n>>maxn>>minn;
    for(LL i=1;i<=n;i++)
        cin>>a[i];
    LL sum=0;
    for(LL i=1;i<=n;i++)
    {
        LL maxx=a[i],minx=a[i];
        for(LL j=i;j<=n;j++)
        {
            maxx=max(a[j],maxx);
            minx=min(a[j],minx);
            if(maxx==maxn&&minx==minn) sum++;
        }
    }
    cout<<sum<<endl;
	return 0;
}

 学习一下佬的写法

思路:从前往后标记一下最大值和最小值的位置,要不断地更新,因为标到谁就可以和前面无误处(初始时为第一个数)参与个数计算,而最大值位置和最小值位置所产生的个数就是受到了最小值位置的约束。

当出现会干扰最值情况的时候就代表不能一直往前数了,数到error就该停止。

#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long LL;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL n,maxn,minn;
	cin>>n>>maxn>>minn;
	LL sum=0,error=0;
	LL daidx=0,xiaoidx=0;
	for(LL i=1;i<=n;i++)
    {
        LL x;
		cin>>x;
		if(x==maxn) daidx=i;
		if(x==minn) xiaoidx=i;
		if(x>maxn||x<minn)//有超过比最大的都还大的或者说比最小都还小的
        {
            //那就妥妥的寄了
			xiaoidx=0;
			daidx=0;//把他们的位置还原
			error=i;//error表示出错了的坐标,在这里就意味着不可以超出这个界限
		}
		if(daidx!=0&&xiaoidx!=0)
        {
            //cout<<error<<endl;
            sum+=min(daidx,xiaoidx)-error;//没有出错的话那就直接是找min(最大坐标,最小坐标);
            //如果有误的话那么就不能越过error的坐标;
        }
	}
	cout<<sum<<endl;
	return 0;
}

要多做难题,再摆烂下去就退役了。。。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Vijurria

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

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

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

打赏作者

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

抵扣说明:

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

余额充值