前三道数学题
1 0 0 1 题
本来应该付的钱:b * a + ( 1 - c ) * a 充的钱+折扣的钱
实际付的钱:b * a 充的钱
优惠比例:( 1 - c ) / ( b + ( 1 - c ) )
可能做题的时候还没睡醒吧。。反正是算了五六分钟。。。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int test; scanf("%d", &test);
while(test--){
int n, b[105]; double c[105], ans=0;
scanf("%d", &n);
for(int i=0; i<n; i++) scanf("%d%lf", &b[i], &c[i]);
for(int i=0; i<n; i++){
double t=(1-c[i])/(b[i]+1-c[i]);
ans=max(ans, t);
}
printf("%.5lf\n", ans);
}
// system("pause");
return 0;
}
1 0 0 2 题
一道数学期望的题。
因为 x ∈ (0, 1],当 p > 1 的时候,是拿到了 2x 那一堆,一定不换;
当 p <= 1 时,假设不交换期望得到的金币数目为 1,
交换以后有一半概率翻倍,一半概率减半。E(X) = 0.5 * 2 + 0.5 * 0.5 = 1.25,
一定换。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int test; scanf("%d", &test);
while(test--){
double p; scanf("%lf", &p);
if(p>1.00000) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
//system("pause");
return 0;
}
1 0 0 3 题
因为卡时间嘛,所以推公式就好了。
当 m == 0 时,输出为 0;
当 m >= n / 2 时,变成了完全的倒序,逆序对数最大,为 n * ( n - 1 ) / 2;
否则就依次交换 1和n,2和n-1,…,一共交换 m 对,推的过程如下(感觉推的挺麻烦的,这是第二遍的做法。第一遍忘记怎么做的了,不过我觉得注意了那个没AC掉的点也能过。。。嘤。哎算了)
做题的时候没考虑范围用 int 报错了,改成 long long 过的
int:-2147483648~2147483647 10^9
long long:-9223372036854775808 ~ 9223372036854775807(>10^18)
unsigned long long的最大值:18446744073709551615
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long test; scanf("%lld", &test);
while(test--){
long long n, m; scanf("%lld%lld", &n, &m);
if(m==0) cout<<"0"<<endl;
else if(m>=n/2) cout<<n*(n-1)/2<<endl;
else{
long long t = n*m-m*(m+1)/2 + m*(n-2*m) + m*(m-1)/2;
cout<<t<<endl;
}
}
//system("pause");
return 0;
}