CSP2016-12

  CSP201612-1 中间数

 

 

 

 

 1 //
 2 //  main.cpp
 3 //  CSP201612-1 中间数
 4 //
 5 //  Created by sylvia on 2021/11/4.
 6 //  Copyright © 2021 apple. All rights reserved.
 7 //
 8 
 9 #include <iostream>
10 #include <algorithm>
11 using namespace std;
12 #define M 1000+2
13 int a[M];
14 void fun(int i,int j,int mid){
15     while (a[i]==a[j]){
16                i--;j++;
17            }
18            if((a[i]==a[mid]&&a[j]!=a[mid])||(a[j]==a[mid]&&a[i]!=a[mid])) cout<<-1<<endl;
19            else cout<<a[mid]<<endl;
20 }
21 int main(){
22     int n;
23     cin>>n;
24     for (int i=0;i<n;i++){
25         cin>>a[i];
26     }
27     sort(a,a+n);
28     int mid=n/2;
29     if (n%2){  //奇数
30         fun(mid-1,mid+1,mid);
31     }
32     else if(!(n%2)){
33         fun(mid-1,mid,mid);
34     }
35     return 0;
36 }
View Code

 

  CSP201612-2 工资计算

 

 

 

 以后遇到这种比较绕的数学题还是先在纸上写好式子和判断条件再敲。。。不然就会像我一样查不出错误,卡在70‘上,最后发现自己愚蠢得把税前和税后相关变量弄混了,然后一直WA

 1 //
 2 //  main.cpp
 3 //  CSP201612-2 工资计算
 4 //
 5 //  Created by sylvia on 2021/11/6.
 6 //  Copyright © 2021 apple. All rights reserved.
 7 //
 8 
 9 #include <iostream>
10 #include <stdio.h>
11 #include <math.h>
12 #include <algorithm>
13 #include <string.h>
14 using namespace std;
15 int T=0,S,sum;
16 int flag=0;
17 int a[10]={0,45,300,900,6500,6000,8750};
18 int b[10]={3500,1500,3000,4500,26000,20000,25000};
19 int c[10]={3500,1455,2700,3600,19500,14000,16250};
20 int main(){
21     cin>>T;
22     sum=S=3500;
23     if(T<=3500) {S=T;flag=1;}
24     for (int i=1;i<=6&&(!flag);i++){
25         if(sum+c[i]>=T){
26             flag=1;
27             S+=(T-sum)/(1-(double)a[i]/b[i]);
28         }
29         else {
30             S+=b[i];
31             sum+=c[i];
32         }
33     }
34     if(!flag) {
35         S+=(T-sum)/0.55;
36     }
37     cout<<S<<endl;
38     return 0;
39     
40 }
View Code

 

posted @ 2021-11-04 12:28  Sylvia_lee  阅读(24)  评论(0编辑  收藏  举报