你最愿意做的哪件事,才是你的天赋所在

0%

2019年安徽大学ACM/ICPC实验室新生赛(公开赛)

题目链接

2019年安徽大学ACM/ICPC实验室新生赛(公开赛)

A,B,C

D

思路

判断gcd(a,b)是否为1,为1输出a*b,否则则无解。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll a,b;
scanf("%lld %lld",&a,&b);
ll g=gcd(a,b);
if(g!=1)
{
printf("-1\n");
continue;
}
printf("%lld %lld %lld\n",b,a,1ll*a*b);
}
}

E

思路

考虑3,如果这类数有一个能够整除3,那么这类数都能整除,反之若有一个不能整除,则都不能。所以3肯定是一个答案,我们就考虑2是不是答案即可,暴力判断

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int getnum(int x)
{
int num = 0;
while(x)
{
num+=x%10;
x/=10;
}
return num;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
string s;
cin>>s;
int num = 0;
bool no = false;
bool ok = false;
for(int i=0;i<s.size();i++)
{
num+=s[i]-'0';
}
if((s[s.size()-1]-'0')%2==0)ok=true;
else no=true;
if(num%2==0)ok=true;
else no=true;
int num1,num2,num3;
num1=num2=num3=-1;
if(num>=10)
{
num1=getnum(num);
if(num1%2==0)ok=true;
else no=true;
}
if(num1>=10)
{
num2=getnum(num1);
if(num2%2==0)ok=true;
else no=true;
}
if(num2>=10){
num3=getnum(num2);
if(num3%2==0)ok=true;
else no=true;
}
if(ok&&no)printf("3\n");
else printf("2\n");
}
}

F

思路

答案为(a/(a+b)+b/(a+b))

代码实现

1
2
3
4
5
6
7
8
#include<bits/stdc++.h>
using namespace std;
int main()
{
float a,b;
scanf("%f %f",&a,&b);
printf("%.2f\n",a*(a/(a+b))+b*(b/(a+b)));
}

G

思路

因为n只有1e9,我们考虑先减去某个平方数,这样我们可以用前两个字母来凑,例如n=16=4*4那么可以让AAAAHHHHUICPC。然后考虑平方剩余,即减去平方数后多出来的个数,我们可在H中间插入A,显然,只需要在中间插入一个即可,否则可以直接在前面插入。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n;
scanf("%lld",&n);
if(n<1e4)
{
string ans(n,'A');
ans+="HUICPC";
cout<<ans<<endl;
return 0;
}
int k;
while(1ll*k*k<n)k++;
k--;
string s(k,'A');
string s1(k,'H');
int need=n-1ll*k*k;
string ans = s;
while(need)
{
if(need>=k)
{
ans+="A";
need-=k;
}
else
{
ans+=string(k-need,'H');
k-=(k-need);
ans+="A";
break;
}
}
ans+=string(k,'H');
ans+="UICPC";
cout<<ans<<endl;
}

H

思路

考虑一个数从1->n的方法,如果这个数是一个质数,那么只能从1加倍变成2后不断的+1,如果有因子的话,不管多少个因子,总可以通过因子加倍到达,所以对n分解质因数,对指数相乘,质因数相加即可。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n;
scanf("%lld",&n);
int sq = sqrt(n);
if(n%sq!=0)sq++;
ll ans = 0;
for(int i=2;i<=sq;i++)
{
if(n%i!=0)continue;
while(n%i==0)
{
ans+=i;
n/=i;
}
}
if(n!=1)ans+=n;
cout<<ans<<endl;
}
-------------你最愿意做的哪件事才是你的天赋所在-------------