2020 Multi-University Training Contest 6

1002 Little Rabbit’s Equation

有两个注意点:题目中说有前导0得注意,其次就是最小的进制为2,注意判别;

#include
using namespace std;
typedef unsigned long long LL;
const int mod = 998244353;
const int N = 6e6+7;

LL fun(string s,LL ans){
	LL x=0,i=0;
	while(s[i]=='0'&&i<s.size()) i++;
	for(;i<s.size();i++){
		if(s[i]>='0'&&s[i]<='9') x = x*ans + (s[i]-'0');
		else x = x*ans + (s[i] - 'A')+ 10;
	}
	return x;
}

int main()
{	
	string s;
	map<char,int> mp;
	mp['+'] =1, mp['-'] = 1,mp['*'] = 1,mp['/'] = 1;
	while(cin>>s){
		int i=0,j=0,n=s.size();
		while(i<n&&!mp[s[i]]) i++;
		while(j<n&&s[j]!='=') j++;
		string a,b,c;
		a = s.substr(0,i);
		b = s.substr(i+1,j-i-1);
		c = s.substr(j+1);
		int ans=0;
		for(int k=0;k<n;k++){
			if(mp[s[k]]||s[k]=='=') continue;
			if(s[k]>='A'&&s[k]<='F') ans = max(ans,s[k]-'A'+10);
			else ans = max(ans,s[k]-'0');
		}
		for(ans++;ans<=16;ans++){
			LL x=0,y=0,z=0;
			x = fun(a,ans);
			y = fun(b,ans);
			z = fun(c,ans);
			if(s[i]=='+'&&x+y==z) break;
			if(s[i]=='-'&&x-y==z) break;
			if(s[i]=='*'&&x*y==z) break;
			if(s[i]=='/'&&y!=0&&x/y==z&&x%y==0) break;
		}
		if(ans>=2&&ans<=16) cout<<ans<<"\n";
		else if(ans==1) cout<<"2\n";
		else cout<<"-1\n";
	}
	return 0;
}

1009 Divisibility

这题怕是来充数的吧

#include
using namespace std;
typedef long long LL;
const int mod = 998244353;
const int N = 6e6+7;

int main()
{    
    int T;
    scanf("%d",&T);
    while(T--){
        LL b,x;
        scanf("%lld%lld",&b,&x);
        if(b%x==1) printf("T\n");
        else printf("F\n");
    }
    return 0;
}

1001 Road To The 3rd Building

你可能感兴趣的:(HDU)