A. Make a triangle!
水题,只需满足三角形较小两边相加大于第三边即可
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[3];
while(~scanf("%d%d%d",&a[0],&a[1],&a[2]))
{
sort(a,a+3);
if(a[0]+a[1]>a[2])
printf("0\n");
else
printf("%d\n",a[2]-a[0]-a[1]+1);
}
return 0;
}
B. Equations of Mathematical Magic
转化一下变为 a=x+x xor a,用集合的思想即可知x xor a=x并a-x交a,推得x为a的子集,所以只需讨论a在二进制形式下1的个数即可
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long a;
scanf("%lld",&a);
long long ans=0;
while(a>0)
{
if(a%2==1) ans++;
a/=2;
}
//cout<<ans<<endl;
long long cnt=1;
for(int i=1;i<=ans;i++)
{
cnt*=2;
}
printf("%lld\n",cnt);
}
return 0;
}
2^n==1<<n(向左移一位代表乘以2)
C. Oh Those Palindromes
只需将相同字母排在一起,这样他们能做出最大贡献,所以只需排个序即可
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
char a[100100];
cin>>a;
sort(a,a+n);
cout<<a<<endl;
}
return 0;
}
D. Labyrinth
01BFS学到新东西了,单开一篇文章讲
E. Dwarves, Hats and Extrasensory Abilities
交互题,二分思想
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
string st;
int p=0;
int l=0,r=1e9;
cout<<0<<" "<<1<<endl;
cin>>st;
for(int i=1;i<n;i++)
{
int mid=(l+r)/2;
cout<<mid<<" "<<1<<endl;
cin>>s;
if(s==st)
{
l=mid;
}
else
{
r=mid;
}
}
cout<<l<<" "<<0<<" "<<r<<" "<<2<<endl;
}
F. Candies for Children
推推推