Codeforces Round #739 (Div. 3)

A. Dislike of Threes

签到:求出满足不为3的倍数并且我为不是3的第k个数

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    vector<int> v; 
    int t;
    for(int i=1; i<=100000; i++)
    {
        if(i%3==0||i%10==3)
            continue;
        v.push_back(i);
    }
    cin>>t;
    while(t--)
    {
        int x;
        cin>>x;
        cout<<v[x-1]<<endl;
    }
}

B. Who’s Opposite?

签到题:t组数据,给出abc,编号顺时针排列,ab对称轴,cd对称轴,求d,不存在输出-1.
思路:求出圆桌上共有多少人,超出就是不存在
然后如果C是大数,就减半圈,否则就加半圈

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int t;
    int a,b,c;
    cin>>t;
    while(t--)
    {
        cin>>a>>b>>c;
        int all=abs(a-b)*2;
        if(a>all||b>all||c>all)
            cout<<"-1"<<endl;
        else
        {
            if(c>all/2)
                cout<<c-all/2<<endl;
            else
                cout<<c+all/2<<endl;
        }
    }
}

C. Infinity Table

签到:按照题目给的阵列求出该数字是哪一行哪一列的

//Author:Happy Dog
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int i;
		for(i=1;i<=sqrt(n);i++)
		{
		  if(i*i>=n&&(i-1)*(i-1)<n)
		  break;
		}
	//	cout<<i<<endl;
		if(n>=(i*i+(i-1)*(i-1)+1)/2)
		{
			cout<<i<<" "<<i*i-n+1<<endl;
		}
		else
		{
		     cout<<n-(i-1)*(i-1)<<" "<<i<<endl;	
		} 
	} 
}

D. Make a Power of Two

签到:给定一个数字,求能经过最少几次操作可以将其变为一个2的次幂,例如1,2,4,8,16.。。。。。。
操作有如下两种:1:删掉任意一位的一个数字;2:在最后一位加上另一个数字。
做法:暴力2^60以内的2的次幂,判断哪一个能操作最少次数即可

//Author:Happy Dog
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        ll trueans,n,add=1,minn=1000000;
        cin>>n;
        ll temp=1,tempans=0;
        ll ans=1;
        ll num[1009];
        while(n!=0)
        {
            num[ans]=n%10;
            n=n/10;
            // cout<<num[ans]<<" ";
            ans++;
        }
        ans--;
        tempans=ans;
        for(int i=1; i<=60; i++)
        {
            temp=add;
            add=add*2;
            int a[61];
            ans=1;
            while(temp!=0)
            {
                a[ans]=temp%10;
                temp=temp/10;
                //    cout<<a[ans]<<" ";
                ans++;
            }
            ans--;
            ll tempp=ans;
            //cout<<ans<<endl;
            //�Ƚϳ��ֹ�ϵ
            ll temp=ans;
            for(int j=tempans; j>=1; j--)
            {
                if(num[j]==a[ans])
                    ans--;
                if(ans==0)
                    break;
            }
            trueans=0;
         //   cout<<ans<<"+"<<tempans<<"-"<<tempp-ans<<endl;
            trueans=ans+tempans-(tempp-ans);
            minn=min(minn,trueans);
        }
        cout<<minn<<endl;
    }
}

E. Polycarp and String Transformation

题意:给定一个字符串s,每次删掉s中的一个字符,剩余的字符串加在t后面,直到s为空停止放入,现在给定字符串t,求字符串s以及删掉字符的顺序
若为不存在则输出-1;
思路:字符出现的位置越在后面,越后删除。
有了删掉字符的顺序,就可以把原来字符串s中,求出字符的数量,最后一个删除的字符是字符串t中所有的该字符
最后只需要对原字符串进行检验即可

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll c[26],d[26],k=1,e[26];
int main()
{
    ll T;
    cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        string t="";
        memset(c,0,sizeof(c));
        memset(d,0,sizeof(d));
        memset(e,0,sizeof(e));
        for(ll i=(ll)s.size()-1; i>=0; i--)
        {
            if(!c[s[i]-'a'])
            {
                t+=s[i];
                d[s[i]-'a']=k;
                k++;
            }
            c[s[i]-'a']++;
        }
        reverse(t.begin(),t.end());
        for(ll i=0; i<=25; i++)
        {
            if(!d[i]) continue;
            d[i]=k-d[i];
            e[i]=c[i]/d[i];
        }
        string r="",w="",z="";
        for(ll i=0; i<=(ll)s.size()-1; i++)
        {
            r+=s[i];
            e[s[i]-'a']--;
            ll f=1;
            for(ll j=0; j<=25; j++)
            {
                if(e[j]<0)
                {
                    cout<<"-1"<<endl;
                    goto end;
                }
                if(e[j]) f=0;
            }
            if(f) break;
        }
        z=r;
        for(ll i=0; i<=(ll)t.size()-1; i++)
        {
            w+=r;
            string r2="";
            for(ll j=0; j<=(ll)r.size()-1; j++)
            {
                if(r[j]==t[i])
                    continue;
                r2+=r[j];
            }
            swap(r,r2);
        }
        if(s==w)
            cout<<z<<" "<<t<<endl;
        else
            cout<<"-1"<<endl;
end:
        ;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值