1.
对于第一种套餐,优惠比例为 0.5a / (2a + 0.5a) = 0.2; 对于第二种套餐,优惠比例为 0.9a / (3a + 0.9a) = 9 / 39;
题目给了这么计算的了
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int test,n;
double b,c,best;
cin >> test;
for(int i=0;i<test;i++){
cin >> n;
best=0;
for(int j=0;j<n;j++){
cin >> b >> c;
c=1-c;
c*=100;
b*=100;
best=max(best,c/(b+c));
}
printf("%.5f\n",best);
}
return 0;
}
2.第二题 当x大于1的时候一定不他一定是最大了。若x小于等于1 换的的期望为 (0.5x + 2x)/2 = 1.25x > x 一定交换
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int n ;
cin >> n;
double x;
for(int i=0;i<n;i++){
cin >> x;
if(x<=1) {
cout<< "Yes" << endl;
}else{
cout<< "No" << endl;
}
}
return 0;
}
3.大家手动计算一下发现结果就是 n-1 到 n-1-2*k的和 ,注意要用前n和公式以及k需要是 ll
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int t,n,m ;
cin >> t;
while(t--){
cin >> n >> m;
if( n == 1 || m == 0){
cout << 0 << endl;
}else{
// n 个数 m 次交换机会
long long k; //只需要这么多次
k = min(n/2,m);
cout<<k*(n-1+n-2*k) << endl;
}
}
return 0;
}
4.小车跑的距离 只有他们距离相差1的时候才会出现堵车的情况,其他都是根据距离比较远的那个小车运行情况所决定的,因此特判距离为1的时候即可
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int t,n,m ;
cin >> t;
while(t--){
int n,x,y,m1=-1,m2=-1;
cin >> n;
for(int i=0;i<n;i++){
cin >> x >> y;
if(x==1 && y>m1) m1 = y;
if(x==2 && y>m2) m2 = y;
}
//分为三种情况 1. x y相同
if(m1 == m2)
cout << m1+2 << endl;
else if(m1 > m2){
if(m1-m2==1)
cout << m2+3 << endl;
else
cout << m1+1 << endl;
} else{
if(m2-m1 ==1){
cout << m2+3 << endl;
}else{
cout << m2+2<< endl;
}
}
}
return 0;
}
7、模拟出所有的情况即可
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,x,y,z,ans;
cin >> n;
while(n--){
cin >> x >> y >> z;
int xx = 1000/x + (1000%x != 0);
int yy = 1000/y + (1000%y != 0);
int zz = 1000/z + (1000%z != 0);
for(int i = 0; i <= zz; ++i) {
for(int j = 0; j <= zz; ++j) {
int xxx = i*y+j*z;
for(int k = 0;k<=zz;k++){
int yyy = i*x+k*z;
int zzz = j*x+k*y;
int cnt = 0;
if(xxx >= 1000) cnt++;
if(yyy >= 1000) cnt++;
if(zzz >= 1000) cnt++;
if(cnt > 1) {
ans = min(ans, i+j+k);
break;
}
}
if(xxx >= 1000) break;
}
if(x*i >= 1000) break;
}
cout << ans << endl;
}
}
还有三题不会 淦
还有写题的时候是真的脑瘫 我要好好训练