Codeforces Round 739 (Div. 3)

Codeforces Round 739 (Div. 3)

Problem - A - Codeforces

#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
const int INF = 1e6+10;
vector<int>v;
void get_x()
{
	for(int i = 1;i <= 2000;i ++)
	{
		if(i % 3 != 0 && i % 10 != 3)
		{
			v.push_back(i);
		}
	}
	return ;
}
int main()
{
	get_x();
	int _;
	cin>>_;
	while(_--)
	{
		int k;
		cin>>k;
		cout<<v[k-1]<<endl;
	}
	return 0;
	
}

Problem - B - Codeforces

在这里插入图片描述

#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
const int INF = 1e6+10;

int main()
{

	int _;
	cin>>_;
	while(_--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		int dis = abs(a-b);
		if(dis <= 1){
			cout<<-1<<endl;
//			continue;
		}
		else
		{
			int num = 2 * dis;
			if(a > num || b > num)
			{
				cout<<-1<<endl;
			}
			else if(c > num)
			{
				cout<<-1<<endl;
	//			continue;
			}
			else
			{
				if(c <= num / 2)
				{
					cout<<c + dis<<endl;
				}
				else
				{
					cout<<c - dis<<endl;
				}
			}
		}
		
		
	}
	return 0;
	
}

Problem - C - Codeforces

#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
const int INF = 1e6+10;

int main()
{

	int _;
	cin>>_;
	while(_--)
	{
		int k;
		cin>>k;
		int now = sqrt(k);
		if(now * now == k)
		{
			cout<<now<<" "<<1<<endl;
		}
		else
		{
			int dis = (LL)(now + 1)*(now + 1) - (now * now);
			int ans = k - (now * now);
			if(ans <= dis / 2 + 1)
			{
				cout<<ans<<" "<<now + 1<<endl;
			}
			else
			{
				LL all = (now + 1)*(now + 1);
				LL ans1 = all - k + 1;
				cout<<now + 1<<" "<<ans1<<endl;
			}
			
		}
		
		
	}
	return 0;
	
}

Problem - D - Codeforces

//通过数据,可以得出最大如果n=999999999则答案最大为9+1=10(删除所有9,再加上2就可以)
//然后将2在10的19次方内的幂都枚举,然后就将n和2的幂转化为字符串,分别比较,找出最小值即可
//(!注意,一定要在将2在10的19次方内的幂都枚举,因为他很可能给的数值9位就是2的幂的前9位,然后如果只有枚举2在10的9次方内的幂就找不出来)
#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
const int INF = 1e6+10;
vector<LL>v;
void get_n()//枚举所有2的幂 
{
	LL ans = 1;
	v.push_back(ans);
	for(int i=1;i<=59;i++)
	{
		ans *= 2;
		v.push_back(ans);
	}
	return ;
}

int minn_change(string s)
{
	int minn = 12;
	for(int i=0;i<v.size();i++) //枚举所有2的幂 
	{
		string num = to_string(v[i]);
		int j = 0;
		for(int i = 0;i < s.size() && j < num.size();i ++)
		{
			if(s[i] == num[j])
			{
				j++;
			}
		}
		int cnt;
		if(j == num.size())//直接包含了,删除剩下的就可以 
		{
			cnt = s.size() - num.size(); 
		}
		else  //没有包含先删除除了包含以外的 再加上没有包含的  
		{
			cnt =  s.size() - j + (num.size() - j);
			    //除了包含以外的     //没有包含的 
		}
		minn = min(minn , cnt);
	}
	return minn;
}

int main()
{

	int _;
	cin>>_;
	get_n();
//	for(int i=0;i<v.size();i++)
//	{
//		cout<<v[i]<<endl;
//	}
	while(_--)
	{
		int n;
		cin>>n;
		string s = to_string(n);
		int ans = minn_change(s);
		int ans2 = s.size()+1; 
		ans = min(ans,ans2);
		cout<<ans<<endl;
		
	}
	
	return 0;
	
}

Problem - E - Codeforces

在这里插入图片描述

#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
const int INF = 5e5+10;
int a[30],a1[30];
bool vis[30];
int main()
{

	int _;
	cin>>_;
	while(_--)
	{
		vector<char>v;
		string s,s1 = "";
		int n = 0;
		cin>>s;
		memset(a,0,sizeof(a));
	//	memset(a1,0,sizeof(a1));
		memset(vis,0,sizeof(vis));
		for(int i=s.size()-1;i>=0;i--)//从t的最后开始遍历
		{
			a[s[i]-'a']++;//每种字符的个数
			if(!vis[s[i]-'a'])
			{
				v.push_back(s[i]);
				vis[s[i]-'a'] = 1;
				n++;//字符的种类数,也是需要删除的次数
			}
		}
		int len = 0;
		for(int i = 0;i < v.size();i ++)
		{
			int now = v[i] - 'a';
			a[now] = a[now] / (n-i);//计算出原始s中每种字符的个数
			len += a[now];//计算出原始s的长度
		}
		string ans = "";
		for(int i = 0;i < len;i ++)
		{
			ans += s[i];//根据给出的t得出原始的s
	//		a1[s[i] - 'a']++;
		}
		s1 = ans;
		int flag = 0;
		bool c[30]={0};
		for(int i= v.size() - 1;i >= 0;i--)//根据得出的s再遍历一遍得出t
		{
			c[v[i] - 'a'] = 1;
			for(int j = 0;j < ans.size();j++)
			{
				if(!c[ans[j] - 'a'])
				{
					s1 += ans[j];
				}
			}
		}
//		cout<<s1<<endl;
		if(s1 != s)//判断是否相同
		{
			ans = "-1";
			flag = 1;
		}
		cout<<ans<<" ";
		if(!flag)
		for(int i = v.size()-1;i >= 0;i --)
		{
			cout<<v[i];
		}
		cout<<endl;
	}
	
	return 0;
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值