10.15每日总结

//双端队列,两边可以同时弹出,适合环形字符串 https://ac.nowcoder.com/acm/contest/65821/A
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int sum=0;
    deque<char> c;
    for(int i=0;i<n;i++)
    {
        if(!c.empty()&&s[i]==c.back())
        {
            c.pop_back();
            sum+=2;
        }
        else
		{
            c.push_back(s[i]);
        }
    }
    while(c.back()==c.front()&&c.size()>=2)
    {
        c.pop_back();
        c.pop_front();
        sum+=2;
    }
    cout<<sum<<endl;
    return 0;
}

/* 将x变成y ,*2或+1,逆向用y找x,看哪个改变量大就优先哪个 https://ac.nowcoder.com/acm/contest/65821/B
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int x,y;
   cin>>x>>y;
   	int cnt=0;
   	while(y>x)//y<=x时就会自动退出 
   	{
   		if(y%2==0)
   		{
   			y=y/2;
   			cnt++;
		}
		else
		{
		   	y=y-1;
		   	cnt++;
		}
	}
   if(y<x)//上次y/2后,y<x了 
   {
   	cnt--;//撤销上面的y/2步骤 
   	cnt+=y*2-x;//看还需要减几个1 
   }
   cout<<cnt<<endl;	
	return 0;
}
/*x变成y,*5或/6,找因数,看经过操作能不能相等,看因数满足题目要求不 
https://blog.csdn.net/qq_61903556/article/details/124493701?ops_request_misc=&request_id=&biz_id=102&utm_term=%E6%8A%8A%E4%B8%80%E4%B8%AA%E6%95%B0%E5%8F%98%E6%88%90%E5%8F%A6%E4%B8%80%E4%B8%AA%E6%95%B0%E6%80%8E%E4%B9%88%E6%83%B3&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-124493701.142^v96^pc_search_result_base6&spm=1018.2226.3001.4187
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        int x5=0,x6=0,y5=0,y6=0;
        while(x%5==0)//看x有多少个5因数
        {
            x=x/5;//因为5的改变量更大,所以操作优先
            x5++;
        }
        while(x%6==0)
        {
            x=x/6;
            x6++;
        }
        while(y%5==0)
        {
            y=y/5;
            y5++;
        }
        while(y%6==0)
        {
            y=y/6;
            y6++;
        }
        if(x!=y)
        {
            cout<<-1<<endl;
            continue;
        }
        if(x5>y5||x6<y6)//根据题目说的x变5规则
        {
            cout<<-1<<endl;
            continue;
        }
        cout<<y5-x5+x6-y6<<endl;
    }
    return 0;
}

小白周赛那个题

题目数据10的100000次方,我用longlong我真的傻叉,这么大直接用string呀,就不该想复杂,然后第二题是那个绝对值加减,一定要注意会不会改变值,多找几个试试

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值