2020.04.11补提
H - To begin or not to begin
题意:箱子里有1个红球和k个黑球
Alice和Bob轮流不放回地从箱子里随机取出一个球
当某人取到红球时获得胜利,游戏结束
问先手是否获胜几率更大,几率更大,输出"1";几率更小,输出"2";几率相等,输出"0"
思路:概率
先手赢得概率大于等于后手,因为后手概率总为1/2;
AC代码:
#include<iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#define ll long long
using namespace std;
double pi=3.14159265358979323;
int main() {
int n;
while(cin>>n){
int num=n+1;
if(num%2==0) cout<<0<<endl;
else cout<<1<<endl;
}
return 0;
}
I - Convex
题意:计算N的三角形的面积
思路:公式 S = 1/2a*b*sin(ab边夹角)
AC代码:
#include<iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#define ll long long
using namespace std;
double pi=3.14159265358979323;
int main() {
int n,d;
while(cin>>n>>d) {
int num;
double ans=0;
for(int i=0; i<n; i++) {
cin>>num;
ans=ans+sin(pi*num/180)*d*d*0.5;
}
printf("%.3lf\n",ans);
}
return 0;
}
J - Find Small A
思路:给定一堆32位整数,对于每个数字,每8位算一个数,统计有多少个97,也就是字符A
AC代码:
#include <iostream>
using namespace std;
int main() {
int N, n, cnt = 0;
int x = 255;
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> n;
do {
if ((n & x) == 'a') {
cnt += 1;
}
n >>= 8;
} while (n);
}
cout << cnt << endl;
// cout << (256>>8 & 255) << endl;
return 0;
}